Skip to content

Commit

Permalink
fix jump back action not to crash when the buffer is edited
Browse files Browse the repository at this point in the history
  • Loading branch information
itchyny committed Nov 25, 2024
1 parent 9a884df commit 7cd1bb3
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions window/window.go
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,7 @@ func (w *window) jumpTo() {
if offset <= 0 || w.length <= offset {
return
}
w.stack = append(w.stack, position{w.cursor, w.offset})
w.stack = append(w.stack, position{cursor: w.cursor, offset: w.offset})
w.cursor = offset
w.offset = max(offset-offset%w.width-max(w.height/3, 0)*w.width, 0)
}
Expand All @@ -718,8 +718,9 @@ func (w *window) jumpBack() {
if len(w.stack) == 0 {
return
}
w.cursor = w.stack[len(w.stack)-1].cursor
w.offset = w.stack[len(w.stack)-1].offset
if pos := w.stack[len(w.stack)-1]; pos.cursor < w.length {
w.cursor, w.offset = pos.cursor, pos.offset
}
w.stack = w.stack[:len(w.stack)-1]
}

Expand Down

0 comments on commit 7cd1bb3

Please sign in to comment.