From 7cd1bb3105dcb027da727b138c4bcb7ff7a3d57d Mon Sep 17 00:00:00 2001 From: itchyny Date: Tue, 26 Nov 2024 08:56:02 +0900 Subject: [PATCH] fix jump back action not to crash when the buffer is edited --- window/window.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/window/window.go b/window/window.go index 101944a..0f09ad3 100644 --- a/window/window.go +++ b/window/window.go @@ -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) } @@ -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] }