Skip to content

Commit 004ac4e

Browse files
committed
Don't miss a final empty line in visual block insertion
1 parent 476f5fb commit 004ac4e

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

evil-commands.el

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2676,17 +2676,22 @@ If SKIP-EMPTY-LINES is non-nil, the insertion will not be performed
26762676
on lines on which the insertion point would be after the end of the
26772677
lines. This is the default behaviour for Visual-state insertion."
26782678
(interactive
2679-
(list (prefix-numeric-value current-prefix-arg)
2680-
(and (evil-visual-state-p)
2681-
(memq (evil-visual-type) '(line block))
2682-
(save-excursion
2683-
(let ((m (mark)))
2684-
;; go to upper-left corner temporarily so
2685-
;; `count-lines' yields accurate results
2686-
(evil-visual-rotate 'upper-left)
2687-
(prog1 (count-lines evil-visual-beginning evil-visual-end)
2688-
(set-mark m)))))
2689-
(evil-visual-state-p)))
2679+
(let ((lines+ 0))
2680+
(list (prefix-numeric-value current-prefix-arg)
2681+
(and (evil-visual-state-p)
2682+
(memq (evil-visual-type) '(line block))
2683+
(save-excursion
2684+
(let ((m (mark)))
2685+
(evil-visual-rotate 'lower-right)
2686+
;; count-lines misses an empty final line, so correct that
2687+
(and (bolp) (eolp) (setq lines+ 1))
2688+
;; go to upper-left corner temporarily so
2689+
;; `count-lines' yields accurate results
2690+
(evil-visual-rotate 'upper-left)
2691+
(prog1 (+ (count-lines evil-visual-beginning evil-visual-end)
2692+
lines+)
2693+
(set-mark m)))))
2694+
(evil-visual-state-p))))
26902695
(if (and (called-interactively-p 'any)
26912696
(evil-visual-state-p))
26922697
(cond

evil-tests.el

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1315,7 +1315,7 @@ evil\nrulz\nevil\nrulz\nevil\nrulz\nevil\nrulz\nevil\nrul[z]
13151315
(evil-test-buffer
13161316
""
13171317
("i" [return] [return] [return] [return] [return] [return] [escape] "gg\C-vGIX" [escape])
1318-
"X\nX\nX\nX\nX\nX\n")))
1318+
"X\nX\nX\nX\nX\nX\nX")))
13191319

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

0 commit comments

Comments
 (0)