Skip to content

Commit

Permalink
editor: fix current address when moving a single line
Browse files Browse the repository at this point in the history
When moving a single line, we only want to return the destination line.
  • Loading branch information
nmeum committed Aug 17, 2023
1 parent 3784b5c commit 7f85285
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/ed/editor.scm
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,11 @@
(buffer-move! buffer sline eline dest-line)
(min
(editor-lines editor)
(+ dest-line (inc (- eline sline))))))
(let ((diff (- eline sline)))
(+ dest-line
;; If we moved multiple lines, we need to increment
;; the destination lines by the amount of lines moved.
(if (zero? diff) diff (inc diff)))))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Expand Down
3 changes: 3 additions & 0 deletions tests/integration/move-update-current-on-single-line/cmds
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
2m3
.=
Q
1 change: 1 addition & 0 deletions tests/integration/move-update-current-on-single-line/opts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
testdata/input-file
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
foo
bar
baz
bla
blubb

0 comments on commit 7f85285

Please sign in to comment.