mirror of
https://github.com/charmbracelet/glow.git
synced 2026-08-23 00:24:17 +02:00
Selection index in file shouldn't dip below 0
This commit is contained in:
parent
1bf2298536
commit
df95fa6ba9
1 changed files with 7 additions and 5 deletions
12
ui/stash.go
12
ui/stash.go
|
|
@ -146,16 +146,18 @@ func (m stashModel) selectedMarkdown() *markdown {
|
|||
|
||||
// addDocuments adds markdown documents to the model
|
||||
func (m *stashModel) addMarkdowns(mds ...*markdown) {
|
||||
m.markdowns = append(m.markdowns, mds...)
|
||||
sort.Sort(markdownsByLocalFirst(m.markdowns))
|
||||
m.paginator.SetTotalPages(len(m.markdowns))
|
||||
if len(mds) > 0 {
|
||||
m.markdowns = append(m.markdowns, mds...)
|
||||
sort.Sort(markdownsByLocalFirst(m.markdowns))
|
||||
m.paginator.SetTotalPages(len(m.markdowns))
|
||||
}
|
||||
}
|
||||
|
||||
// INIT
|
||||
|
||||
func newStashModel() stashModel {
|
||||
s := spinner.NewModel()
|
||||
s.Frames = spinner.Dot
|
||||
s.Frames = spinner.Line
|
||||
s.ForegroundColor = common.SpinnerColor
|
||||
|
||||
p := paginator.NewModel()
|
||||
|
|
@ -313,7 +315,7 @@ func stashUpdate(msg tea.Msg, m stashModel) (stashModel, tea.Cmd) {
|
|||
// Keep the index in bounds when paginating
|
||||
itemsOnPage := m.paginator.ItemsOnPage(len(m.markdowns))
|
||||
if m.index > itemsOnPage-1 {
|
||||
m.index = itemsOnPage - 1
|
||||
m.index = max(0, itemsOnPage-1)
|
||||
}
|
||||
|
||||
// If we're on the last page and we haven't loaded everything, get
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue