From 1c32e5c7b2966b1304b8fd4b9287239fac7379a0 Mon Sep 17 00:00:00 2001 From: Eitaro Fukamachi Date: Thu, 31 Aug 2023 16:57:41 +0000 Subject: [PATCH] Add tests for vi-replace-char (r). --- extensions/vi-mode/tests/operator.lisp | 33 ++++++++++++++++++++++++++ extensions/vi-mode/text-objects.lisp | 4 ++-- extensions/vi-mode/visual.lisp | 2 +- 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/extensions/vi-mode/tests/operator.lisp b/extensions/vi-mode/tests/operator.lisp index 1b708059f..8ad6fb70f 100644 --- a/extensions/vi-mode/tests/operator.lisp +++ b/extensions/vi-mode/tests/operator.lisp @@ -101,6 +101,39 @@ (cmd "J") (ok (buf= #?"abcdefgh[ ]ijklmn\n"))))) +(deftest vi-replace-char + (with-fake-interface () + (with-vi-buffer ("a[n]t") + (cmd "rr") + (ok (buf= "a[r]t"))) + (with-vi-buffer ("sh[o]ut") + (cmd "2re") + (ok (buf= "she[e]t"))) + (with-vi-buffer ("<[m]>eat") + (cmd "rb") + (ok (buf= "[b]eat"))) + (with-vi-buffer ("pk") + (cmd "re") + (ok (buf= "p[e]ek"))) + (with-vi-buffer ("p<[i]c>k") + (cmd "re") + (ok (buf= "p[e]ek"))) + (with-vi-buffer (#?"em[a]cs\n") + (cmd "VrX") + (ok (buf= #?"[X]XXXX\n"))) + (with-vi-buffer (#?"a[b]cd\nefgh\n") + (cmd "jlrx") + (ok (buf= #?"a[x]xd\nexxh\n"))) + (with-vi-buffer (#?"ab[c]d\nefgh\n") + (cmd "jhrx") + (ok (buf= #?"a[x]xd\nexxh\n"))) + (with-vi-buffer (#?"abcd\nef[g]h\n") + (cmd "khrx") + (ok (buf= #?"a[x]xd\nexxh\n"))) + (with-vi-buffer (#?"abcd\ne[f]gh\n") + (cmd "klrx") + (ok (buf= #?"a[x]xd\nexxh\n"))))) + (deftest vi-repeat (with-fake-interface () (with-vi-buffer (#?"[1]:abc\n2:def\n3:ghi\n4:jkl\n5:mno\n6:opq\n7:rst\n8:uvw") diff --git a/extensions/vi-mode/text-objects.lisp b/extensions/vi-mode/text-objects.lisp index 5970723a5..dc13c18b7 100644 --- a/extensions/vi-mode/text-objects.lisp +++ b/extensions/vi-mode/text-objects.lisp @@ -73,7 +73,7 @@ (defmethod a-range-of (object (state visual) count) (destructuring-bind (beg end) (visual-range) - (when (point= beg end) + (when (point= beg (current-point)) (return-from a-range-of (call-next-method))) (let ((direction (cond @@ -132,7 +132,7 @@ (defmethod inner-range-of (object (state visual) count) (destructuring-bind (beg end) (visual-range) - (when (point= beg end) + (when (point= beg (current-point)) (return-from inner-range-of (call-next-method))) (let ((direction (cond diff --git a/extensions/vi-mode/visual.lisp b/extensions/vi-mode/visual.lisp index 833c532e9..d5156a473 100644 --- a/extensions/vi-mode/visual.lisp +++ b/extensions/vi-mode/visual.lisp @@ -160,7 +160,7 @@ ((visual-char-p) (with-point ((start *start-point*) (end (current-point))) - (cond ((point< start end) + (cond ((point<= start end) (character-offset end 1)) ((point< end start) (character-offset start 1)))