aports/testing/edward/0001-editor-fix-current-address-when-moving-a-single-line.patch
2023-12-18 15:16:41 +00:00

61 lines
2.4 KiB
Diff

From 7f85285e784002921f22db29f6724f10bbea1182 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=B6ren=20Tempel?= <soeren+git@soeren-tempel.net>
Date: Thu, 17 Aug 2023 07:16:14 +0200
Subject: [PATCH] editor: fix current address when moving a single line
When moving a single line, we only want to return the destination line.
---
lib/ed/editor.scm | 6 +++++-
tests/integration/move-update-current-on-single-line/cmds | 3 +++
tests/integration/move-update-current-on-single-line/opts | 1 +
.../move-update-current-on-single-line/testdata/input-file | 5 +++++
4 files changed, 14 insertions(+), 1 deletion(-)
create mode 100644 tests/integration/move-update-current-on-single-line/cmds
create mode 100644 tests/integration/move-update-current-on-single-line/opts
create mode 100644 tests/integration/move-update-current-on-single-line/testdata/input-file
diff --git a/lib/ed/editor.scm b/lib/ed/editor.scm
index ccadd0b..9790407 100644
--- a/lib/ed/editor.scm
+++ b/lib/ed/editor.scm
@@ -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)))))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
diff --git a/tests/integration/move-update-current-on-single-line/cmds b/tests/integration/move-update-current-on-single-line/cmds
new file mode 100644
index 0000000..34eb4a1
--- /dev/null
+++ b/tests/integration/move-update-current-on-single-line/cmds
@@ -0,0 +1,3 @@
+2m3
+.=
+Q
diff --git a/tests/integration/move-update-current-on-single-line/opts b/tests/integration/move-update-current-on-single-line/opts
new file mode 100644
index 0000000..778c17f
--- /dev/null
+++ b/tests/integration/move-update-current-on-single-line/opts
@@ -0,0 +1 @@
+testdata/input-file
diff --git a/tests/integration/move-update-current-on-single-line/testdata/input-file b/tests/integration/move-update-current-on-single-line/testdata/input-file
new file mode 100644
index 0000000..6392fd1
--- /dev/null
+++ b/tests/integration/move-update-current-on-single-line/testdata/input-file
@@ -0,0 +1,5 @@
+foo
+bar
+baz
+bla
+blubb