mirror of
https://github.com/charmbracelet/glow
synced 2024-12-13 21:52:37 +00:00
Add stash states for searching through notes
- stashStateSearchNotes will be used while entering the search term - stashStateShowFiltered will only display the filtered notes in the stash view.
This commit is contained in:
parent
998cbf1cc4
commit
23fb61f752
2 changed files with 29 additions and 5 deletions
32
ui/stash.go
32
ui/stash.go
|
@ -60,6 +60,8 @@ const (
|
||||||
stashStateLoadingDocument
|
stashStateLoadingDocument
|
||||||
stashStateSettingNote
|
stashStateSettingNote
|
||||||
stashStateShowingError
|
stashStateShowingError
|
||||||
|
stashStateSearchNotes
|
||||||
|
stashStateShowFiltered
|
||||||
)
|
)
|
||||||
|
|
||||||
type stashModel struct {
|
type stashModel struct {
|
||||||
|
@ -329,7 +331,7 @@ func stashUpdate(msg tea.Msg, m stashModel) (stashModel, tea.Cmd) {
|
||||||
}
|
}
|
||||||
|
|
||||||
switch m.state {
|
switch m.state {
|
||||||
case stashStateReady:
|
case stashStateReady, stashStateShowFiltered:
|
||||||
switch msg := msg.(type) {
|
switch msg := msg.(type) {
|
||||||
// Handle keys
|
// Handle keys
|
||||||
case tea.KeyMsg:
|
case tea.KeyMsg:
|
||||||
|
@ -388,6 +390,15 @@ func stashUpdate(msg tea.Msg, m stashModel) (stashModel, tea.Cmd) {
|
||||||
|
|
||||||
cmds = append(cmds, spinner.Tick(m.spinner))
|
cmds = append(cmds, spinner.Tick(m.spinner))
|
||||||
|
|
||||||
|
// Search through your notes
|
||||||
|
case "/":
|
||||||
|
m.hideStatusMessage()
|
||||||
|
|
||||||
|
if pages == 0 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
m.state = stashStateSearchNotes
|
||||||
// Set note
|
// Set note
|
||||||
case "m":
|
case "m":
|
||||||
m.hideStatusMessage()
|
m.hideStatusMessage()
|
||||||
|
@ -526,6 +537,14 @@ func stashUpdate(msg tea.Msg, m stashModel) (stashModel, tea.Cmd) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case stashStateSearchNotes:
|
||||||
|
if msg, ok := msg.(tea.KeyMsg); ok {
|
||||||
|
switch msg.String() {
|
||||||
|
case "esc":
|
||||||
|
// Cancel search
|
||||||
|
m.state = stashStateReady
|
||||||
|
}
|
||||||
|
}
|
||||||
case stashStateSettingNote:
|
case stashStateSettingNote:
|
||||||
if msg, ok := msg.(tea.KeyMsg); ok {
|
if msg, ok := msg.(tea.KeyMsg); ok {
|
||||||
switch msg.String() {
|
switch msg.String() {
|
||||||
|
@ -559,7 +578,6 @@ func stashUpdate(msg tea.Msg, m stashModel) (stashModel, tea.Cmd) {
|
||||||
|
|
||||||
// If an item is being confirmed for delete, any key (other than the key
|
// If an item is being confirmed for delete, any key (other than the key
|
||||||
// used for confirmation above) cancels the deletion
|
// used for confirmation above) cancels the deletion
|
||||||
|
|
||||||
return m, tea.Batch(cmds...)
|
return m, tea.Batch(cmds...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -572,7 +590,7 @@ func stashView(m stashModel) string {
|
||||||
return errorView(m.err, false)
|
return errorView(m.err, false)
|
||||||
case stashStateLoadingDocument:
|
case stashStateLoadingDocument:
|
||||||
s += " " + spinner.View(m.spinner) + " Loading document..."
|
s += " " + spinner.View(m.spinner) + " Loading document..."
|
||||||
case stashStateReady, stashStateSettingNote, stashStatePromptDelete:
|
case stashStateReady, stashStateSettingNote, stashStatePromptDelete, stashStateSearchNotes, stashStateShowFiltered:
|
||||||
|
|
||||||
loadingIndicator := ""
|
loadingIndicator := ""
|
||||||
if !m.localOnly() && (!m.loadingDone() || m.loadingFromNetwork || m.spinner.Visible()) {
|
if !m.localOnly() && (!m.loadingDone() || m.loadingFromNetwork || m.spinner.Visible()) {
|
||||||
|
@ -742,10 +760,15 @@ func stashHelpView(m stashModel) string {
|
||||||
h = append(h, "enter: confirm", "esc: cancel")
|
h = append(h, "enter: confirm", "esc: cancel")
|
||||||
} else if m.state == stashStatePromptDelete {
|
} else if m.state == stashStatePromptDelete {
|
||||||
h = append(h, "y: delete", "n: cancel")
|
h = append(h, "y: delete", "n: cancel")
|
||||||
|
} else if m.state == stashStateSearchNotes {
|
||||||
|
h = append(h, "enter: confirm", "esc: cancel", "ctrl+j/ctrl+k, ↑/↓: choose")
|
||||||
} else {
|
} else {
|
||||||
if len(m.markdowns) > 0 {
|
if len(m.markdowns) > 0 {
|
||||||
h = append(h, "enter: open")
|
h = append(h, "enter: open")
|
||||||
}
|
}
|
||||||
|
if m.state == stashStateShowFiltered {
|
||||||
|
h = append(h, "esc: clear search")
|
||||||
|
}
|
||||||
if len(m.markdowns) > 1 {
|
if len(m.markdowns) > 1 {
|
||||||
h = append(h, "j/k, ↑/↓: choose")
|
h = append(h, "j/k, ↑/↓: choose")
|
||||||
}
|
}
|
||||||
|
@ -753,13 +776,14 @@ func stashHelpView(m stashModel) string {
|
||||||
h = append(h, "h/l, ←/→: page")
|
h = append(h, "h/l, ←/→: page")
|
||||||
}
|
}
|
||||||
if isStashed {
|
if isStashed {
|
||||||
h = append(h, []string{"x: delete", "m: set memo"}...)
|
h = append(h, "x: delete", "m: set memo")
|
||||||
} else if isLocal && m.authStatus == authOK {
|
} else if isLocal && m.authStatus == authOK {
|
||||||
h = append(h, "s: stash")
|
h = append(h, "s: stash")
|
||||||
}
|
}
|
||||||
if m.err != nil {
|
if m.err != nil {
|
||||||
h = append(h, "!: errors")
|
h = append(h, "!: errors")
|
||||||
}
|
}
|
||||||
|
h = append(h, "/: search")
|
||||||
h = append(h, "q: quit")
|
h = append(h, "q: quit")
|
||||||
}
|
}
|
||||||
return stashHelpViewBuilder(m.terminalWidth, h...)
|
return stashHelpViewBuilder(m.terminalWidth, h...)
|
||||||
|
|
2
ui/ui.go
2
ui/ui.go
|
@ -240,7 +240,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||||
case stateShowStash:
|
case stateShowStash:
|
||||||
|
|
||||||
switch m.stash.state {
|
switch m.stash.state {
|
||||||
case stashStateSettingNote, stashStatePromptDelete, stashStateShowingError:
|
case stashStateSettingNote, stashStatePromptDelete, stashStateShowingError, stashStateSearchNotes, stashStateShowFiltered:
|
||||||
m.stash, cmd = stashUpdate(msg, m.stash)
|
m.stash, cmd = stashUpdate(msg, m.stash)
|
||||||
return m, cmd
|
return m, cmd
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue