ed

[hare] The standard editor
Log | Files | Refs | README | LICENSE

commit 79a170f6ff4b1881d49041e6b3dc2ebcaeef5ac0
parent efdd117f3bb0557332357dc4faffa1a35dee7f0a
Author: Curtis Arthaud <uku82@gmx.fr>
Date:   Wed, 20 Mar 2024 13:09:08 +0100

history: keep cursor within bounds

Signed-off-by: Curtis Arthaud <uku82@gmx.fr>

Diffstat:
Mhistory.ha | 8+++++++-
1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/history.ha b/history.ha @@ -65,11 +65,14 @@ fn hist_undo(buf: *Buffer) (void | NoHistory) = { let lines = buf.trash[(lentrash - m)..]; insert(buf.lines[n], lines...); delete(buf.trash[(lentrash - m)..]); + buf.cursor = (n + m) - 1; case let addn: Addition => let (n, m) = addn; let lines = buf.lines[n..(n + m)]; insert(buf.trash[0], lines...); delete(buf.lines[n..(n + m)]); + let prev = addr_prevline(buf, n); + buf.cursor = prev; }; }; @@ -84,16 +87,19 @@ fn hist_redo(buf: *Buffer) (void | NoHistory) = { match (seq[i]) { case let addn: Addition => let (n, m) = addn; - let lentrash = len(buf.trash); + //let lentrash = len(buf.trash); //let lines = buf.trash[(lentrash - m)..]; let lines = buf.trash[..m]; insert(buf.lines[n], lines...); //delete(buf.trash[(lentrash - m)..]); delete(buf.trash[..m]); + buf.cursor = (n + m) - 1; case let deln: Deletion => let (n, m) = deln; let lines = buf.lines[n..(n + m)]; append(buf.trash, lines...); delete(buf.lines[n..(n + m)]); + let prev = addr_prevline(buf, n); + buf.cursor = prev; }; };