aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAxel Forsman <axelsfor@gmail.com>2022-11-15 15:52:42 +0100
committerTom Dalziel <33435574+tomdl89@users.noreply.github.com>2022-12-29 17:38:43 +0000
commitbe6b09bcecf3bfdbaadecb21f31c57ce18abac05 (patch)
treea5a9ec3eeb07767922e035dbd9d96183f5717e4e
parent0c535d6dabb9f30ab16ab428c9a123dba9d6ef75 (diff)
Make visual block selection after j/k match Vim
Vim only extends the visual block selection to the temporary goal column if tracking EOL. Consider [a]bc a When entering Visual block mode with "C-v", going to the "c" in "abc" and then to the next line with "fcj", the selection should only include the two "a":s, and not "bc". Contrast this with when "$" is executed.
-rw-r--r--evil-common.el25
-rw-r--r--evil-states.el21
-rw-r--r--evil-tests.el9
3 files changed, 23 insertions, 32 deletions
diff --git a/evil-common.el b/evil-common.el
index 1ac543b..1ea0f87 100644
--- a/evil-common.el
+++ b/evil-common.el
@@ -2464,33 +2464,24 @@ take at least two arguments, the beginning and end of each
line. If PASS-COLUMNS is non-nil, these values are the columns,
otherwise they are buffer positions. Extra arguments to FUNC may
be passed via ARGS."
- (let ((eol-col (and (memq last-command '(next-line previous-line))
- (numberp temporary-goal-column)
- temporary-goal-column))
- startcol startpt endcol endpt)
+ (let (startcol startpt endcol endpt)
(save-excursion
(goto-char beg)
- (setq startcol (current-column))
- (beginning-of-line)
- (setq startpt (point))
+ (setq startcol (current-column)
+ startpt (line-beginning-position))
(goto-char end)
(setq endcol (current-column))
(forward-line 1)
(setq endpt (point-marker))
;; ensure the start column is the left one.
(evil-sort startcol endcol)
- ;; maybe find maximal column
- (when eol-col
- (setq eol-col 0)
+ ;; maybe extend up to EOL
+ (when (and (memq last-command '(next-line previous-line))
+ (eq temporary-goal-column most-positive-fixnum))
(goto-char startpt)
(while (< (point) endpt)
- (setq eol-col (max eol-col
- (evil-column (line-end-position))))
- (forward-line 1))
- (setq endcol (max endcol
- (min eol-col
- (1+ (min (1- most-positive-fixnum)
- (truncate temporary-goal-column)))))))
+ (setq endcol (max endcol (evil-column (line-end-position))))
+ (forward-line 1)))
;; start looping over lines
(goto-char startpt)
(while (< (point) endpt)
diff --git a/evil-states.el b/evil-states.el
index 4d87323..a7242c2 100644
--- a/evil-states.el
+++ b/evil-states.el
@@ -646,10 +646,6 @@ Reuse overlays where possible to prevent flicker."
(let* ((point (point))
(overlays (or overlays 'evil-visual-block-overlays))
(old (symbol-value overlays))
- (eol-col (and (memq this-command '(next-line previous-line))
- (numberp temporary-goal-column)
- (1+ (min (round temporary-goal-column)
- (1- most-positive-fixnum)))))
beg-col end-col new nlines overlay window-beg window-end)
(save-excursion
;; calculate the rectangular region represented by BEG and END,
@@ -660,16 +656,13 @@ Reuse overlays where possible to prevent flicker."
(when (>= beg-col end-col)
(if (= beg-col end-col)
(setq end-col (1+ end-col))
- (evil-sort beg-col end-col))
- (setq beg (save-excursion
- (goto-char beg)
- (evil-move-to-column beg-col))
- end (save-excursion
- (goto-char end)
- (evil-move-to-column end-col 1))))
- ;; update end column with eol-col (extension to eol).
- (when (and eol-col (> eol-col end-col))
- (setq end-col eol-col))
+ (evil-swap beg-col end-col))
+ (setq beg (progn (goto-char beg) (evil-move-to-column beg-col))
+ end (progn (goto-char end) (evil-move-to-column end-col 1))))
+ ;; maybe extend end column to EOL
+ (and (memq this-command '(next-line previous-line))
+ (eq temporary-goal-column most-positive-fixnum)
+ (setq end-col most-positive-fixnum))
;; force a redisplay so we can do reliable window
;; BEG/END calculations
(sit-for 0)
diff --git a/evil-tests.el b/evil-tests.el
index 6358087..f84d0db 100644
--- a/evil-tests.el
+++ b/evil-tests.el
@@ -7274,7 +7274,14 @@ Tiny ln"
"Short
A much
A me[d]
-Tiny ")))
+Tiny "))
+ (ert-info ("Visual block does not extend up to curswant unless tracking EOL")
+ (evil-test-buffer
+ "[a]bc
+"
+ ("\C-vfcjd")
+ "[b]c
+")))
(ert-deftest evil-test-visual-restore ()
"Test restoring a previous selection"