Skip to content

Commit fe44a56

Browse files
committed
Fix Visual Insert affecting one too many lines
This fixes a regression caused by commit 004ac4e, where Visual mode "I" repeated the insertion on one too many lines unless at EOB.
1 parent 95ee3ce commit fe44a56

File tree

2 files changed

+39
-71
lines changed

2 files changed

+39
-71
lines changed

evil-commands.el

Lines changed: 20 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2655,20 +2655,19 @@ corner and point in the lower left."
26552655
(evil-visual-refresh))))
26562656

26572657
(evil-define-command evil-visual-rotate (corner &optional beg end type)
2658-
"In Visual Block selection, put point in CORNER.
2659-
Corner may be one of `upper-left', `upper-right', `lower-left'
2660-
and `lower-right':
2658+
"Move point to CORNER of the Visual selection.
2659+
Corner may be one of `upper-left', `upper-right', `lower-left' and
2660+
`lower-right':
26612661

2662-
upper-left +---+ upper-right
2663-
| |
2664-
lower-left +---+ lower-right
2662+
upper-left +---+ upper-right
2663+
| |
2664+
lower-left +---+ lower-right
26652665

2666-
When called interactively, the selection is rotated blockwise."
2666+
When called interactively, the selection is rotated clockwise."
26672667
:keep-visual t
26682668
(interactive
2669-
(let ((corners '(upper-left upper-right lower-right lower-left)))
2670-
(list (or (cadr (memq (evil-visual-block-corner) corners))
2671-
'upper-left))))
2669+
(let ((corners '#1=(upper-left upper-right lower-right lower-left . #1#)))
2670+
(list (cadr (memq (evil-visual-block-corner) corners)))))
26722671
(let* ((beg (or beg (point)))
26732672
(end (or end (mark t) beg))
26742673
(type (or type evil-this-type))
@@ -2697,43 +2696,21 @@ When called interactively, the selection is rotated blockwise."
26972696

26982697
(defun evil-insert (count &optional vcount skip-empty-lines)
26992698
"Switch to Insert state just before point.
2700-
The insertion will be repeated COUNT times and repeated once for
2701-
the next VCOUNT - 1 lines starting at the same column.
2699+
The insertion will be repeated COUNT times on the next VCOUNT lines,
2700+
starting at the same column.
27022701
If SKIP-EMPTY-LINES is non-nil, the insertion will not be performed
27032702
on lines on which the insertion point would be after the end of the
27042703
lines. This is the default behaviour for Visual-state insertion."
27052704
(interactive
2706-
(let ((lines+ 0))
2705+
(if (not (evil-visual-state-p))
2706+
(list (prefix-numeric-value current-prefix-arg))
2707+
(evil-visual-rotate 'upper-left)
27072708
(list (prefix-numeric-value current-prefix-arg)
2708-
(and (evil-visual-state-p)
2709-
(memq (evil-visual-type) '(line block))
2710-
(save-excursion
2711-
(let ((m (mark)))
2712-
(evil-visual-rotate 'lower-right)
2713-
;; count-lines misses an empty final line, so correct that
2714-
(and (bolp) (eolp) (setq lines+ 1))
2715-
;; go to upper-left corner temporarily so
2716-
;; `count-lines' yields accurate results
2717-
(evil-visual-rotate 'upper-left)
2718-
(prog1 (+ (count-lines evil-visual-beginning evil-visual-end)
2719-
lines+)
2720-
(set-mark m)))))
2721-
(evil-visual-state-p))))
2722-
(if (and (called-interactively-p 'any)
2723-
(evil-visual-state-p))
2724-
(cond
2725-
((eq (evil-visual-type) 'line)
2726-
(evil-visual-rotate 'upper-left)
2727-
(evil-insert-line count vcount))
2728-
((eq (evil-visual-type) 'block)
2729-
(let ((column (min (evil-column evil-visual-beginning)
2730-
(evil-column evil-visual-end))))
2731-
(evil-visual-rotate 'upper-left)
2732-
(move-to-column column t)
2733-
(evil-insert count vcount skip-empty-lines)))
2734-
(t
2735-
(evil-visual-rotate 'upper-left)
2736-
(evil-insert count vcount skip-empty-lines)))
2709+
(when (memq (evil-visual-type) '(line block))
2710+
(1+ (evil-count-lines evil-visual-point evil-visual-mark)))
2711+
t)))
2712+
(if (and (evil-visual-state-p) (eq (evil-visual-type) 'line))
2713+
(evil-insert-line count vcount)
27372714
(setq evil-insert-count count
27382715
evil-insert-lines nil
27392716
evil-insert-vcount (and vcount
@@ -2755,13 +2732,7 @@ the lines."
27552732
(list (prefix-numeric-value current-prefix-arg)
27562733
(and (evil-visual-state-p)
27572734
(memq (evil-visual-type) '(line block))
2758-
(save-excursion
2759-
(let ((m (mark)))
2760-
;; go to upper-left corner temporarily so
2761-
;; `count-lines' yields accurate results
2762-
(evil-visual-rotate 'upper-left)
2763-
(prog1 (count-lines evil-visual-beginning evil-visual-end)
2764-
(set-mark m)))))))
2735+
(1+ (evil-count-lines evil-visual-point evil-visual-mark)))))
27652736
(if (and (called-interactively-p 'any)
27662737
(evil-visual-state-p))
27672738
(cond

evil-tests.el

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -679,13 +679,20 @@ Below some empty line"
679679
("aevil rulz " [escape])
680680
";; Tevil rulz[ ]his buffer is for notes you don't want to save"))
681681

682+
(ert-deftest evil-test-visual-insert ()
683+
"Test `evil-insert' in Visual state."
684+
:tags '(evil insert)
685+
(ert-info ("Repeat insert over empty lines")
686+
(evil-test-buffer :visual line "<\n\n[]>"
687+
("IX" [escape])
688+
"X\nX\nX")))
689+
682690
(ert-deftest evil-test-visual-append ()
683-
"Test `evil-append' from visual state"
691+
"Test `evil-append' in Visual state."
684692
:tags '(evil insert)
685-
(evil-test-buffer
686-
";; [T]his buffer is for notes you don't want to save"
687-
("veA_evil rulz " [escape])
688-
";; This_evil rulz[ ] buffer is for notes you don't want to save"))
693+
(evil-test-buffer "<fo[o]> bar"
694+
("A_evil rulz " [escape])
695+
"foo_evil rulz[ ] bar"))
689696

690697
(ert-deftest evil-test-open-above ()
691698
"Test `evil-open-above'"
@@ -755,10 +762,13 @@ de[f]
755762
(ert-deftest evil-test-insert-line ()
756763
"Test `evil-insert-line'"
757764
:tags '(evil insert)
758-
(evil-test-buffer
759-
";; [T]his buffer is for notes you don't want to save"
765+
(evil-test-buffer "foo [b]ar"
760766
("Ievil rulz " [escape])
761-
"evil rulz[ ];; This buffer is for notes you don't want to save"))
767+
"evil rulz[ ]foo bar")
768+
(ert-info ("With count")
769+
(evil-test-buffer "foo [b]ar"
770+
("2Ievil rulz " [escape])
771+
"evil rulz evil rulz[ ]foo bar")))
762772

763773
(ert-deftest evil-test-append-line ()
764774
"Test `evil-append-line'"
@@ -1272,14 +1282,6 @@ evil\nrulz\nevil\nrul[z]
12721282
evil\nrulz\nevil\nrulz\nevil\nrulz\nevil\nrulz\nevil\nrul[z]
12731283
;; and for Lisp evaluation.")))
12741284

1275-
(ert-deftest evil-test-insert-line-with-count ()
1276-
"Test `evil-insert-line' with repeat count"
1277-
:tags '(evil repeat)
1278-
(evil-test-buffer
1279-
";; [T]his buffer is for notes"
1280-
("2Ievil rulz " [escape])
1281-
"evil rulz evil rulz[ ];; This buffer is for notes"))
1282-
12831285
(ert-deftest evil-test-repeat-insert-line ()
12841286
"Test repeating of `evil-insert-line'"
12851287
:tags '(evil repeat)
@@ -1310,12 +1312,7 @@ evil\nrulz\nevil\nrulz\nevil\nrulz\nevil\nrulz\nevil\nrul[z]
13101312
("10IABC" [escape])
13111313
"ABCABCABCABCABCABCABCABCABCAB[C];; This buffer is for notes"
13121314
("11.")
1313-
"ABCABCABCABCABCABCABCABCABCABCAB[C]ABCABCABCABCABCABCABCABCABCABC;; This buffer is for notes"))
1314-
(ert-info ("Repeat insert over empty lines")
1315-
(evil-test-buffer
1316-
""
1317-
("i" [return] [return] [return] [return] [return] [return] [escape] "gg\C-vGIX" [escape])
1318-
"X\nX\nX\nX\nX\nX\nX")))
1315+
"ABCABCABCABCABCABCABCABCABCABCAB[C]ABCABCABCABCABCABCABCABCABCABC;; This buffer is for notes")))
13191316

13201317
(ert-deftest evil-test-insert-line-vcount ()
13211318
"Test `evil-insert-line' with vertical repeating"

0 commit comments

Comments
 (0)