mirror of
https://github.com/charmbracelet/glow
synced 2024-11-10 06:04:18 +00:00
Maintain positions when renaming documents in a filtered listing
This commit is contained in:
parent
de09997fdb
commit
ae4c85e97d
2 changed files with 28 additions and 12 deletions
|
@ -20,7 +20,16 @@ const (
|
|||
// markdown wraps charm.Markdown.
|
||||
type markdown struct {
|
||||
markdownType markdownType
|
||||
localPath string // only relevant to local files and converted files that are newly stashed
|
||||
|
||||
// Full path of a local markdown file. Only relevant to local documents and
|
||||
// those that have been stashed in this session.
|
||||
localPath string
|
||||
|
||||
// Value we filter against. This exists so that we can maintain positions
|
||||
// of filtered items if notes are edited while a filter is active. This
|
||||
// field is ephemeral, and should only be referenced during filtering.
|
||||
filterValue string
|
||||
|
||||
charm.Markdown
|
||||
}
|
||||
|
||||
|
|
29
ui/stash.go
29
ui/stash.go
|
@ -234,17 +234,7 @@ func (m *stashModel) getNotes() []*markdown {
|
|||
targets := []string{}
|
||||
|
||||
for _, t := range m.markdowns {
|
||||
note, err := normalize(t.Note)
|
||||
if err != nil && debug {
|
||||
log.Printf("error normalizing '%s': %v", t.Note, err)
|
||||
note = t.Note
|
||||
}
|
||||
|
||||
if t.markdownType == newsMarkdown {
|
||||
note = "News: " + note
|
||||
}
|
||||
|
||||
targets = append(targets, note)
|
||||
targets = append(targets, t.filterValue)
|
||||
}
|
||||
|
||||
ranks := fuzzy.Find(m.filterInput.Value(), targets)
|
||||
|
@ -494,6 +484,23 @@ func stashUpdate(msg tea.Msg, m stashModel) (stashModel, tea.Cmd) {
|
|||
case "/":
|
||||
m.hideStatusMessage()
|
||||
|
||||
// Build values we'll filter against
|
||||
for _, md := range m.markdowns {
|
||||
note, err := normalize(md.Note)
|
||||
if err != nil {
|
||||
if debug {
|
||||
log.Printf("error normalizing '%s': %v", md.Note, err)
|
||||
}
|
||||
md.filterValue = md.Note
|
||||
continue
|
||||
}
|
||||
if md.markdownType == newsMarkdown {
|
||||
md.filterValue = "News: " + note
|
||||
continue
|
||||
}
|
||||
md.filterValue = note
|
||||
}
|
||||
|
||||
m.paginator.Page = 0
|
||||
m.index = 0
|
||||
m.state = stashStateFilterNotes
|
||||
|
|
Loading…
Reference in a new issue