emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/evil be6b09bcec 2/6: Make visual block selection after j/k


From: ELPA Syncer
Subject: [nongnu] elpa/evil be6b09bcec 2/6: Make visual block selection after j/k match Vim
Date: Thu, 29 Dec 2022 12:58:48 -0500 (EST)

branch: elpa/evil
commit be6b09bcecf3bfdbaadecb21f31c57ce18abac05
Author: Axel Forsman <axelsfor@gmail.com>
Commit: Tom Dalziel <33435574+tomdl89@users.noreply.github.com>

    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.
---
 evil-common.el | 25 ++++++++-----------------
 evil-states.el | 21 +++++++--------------
 evil-tests.el  |  9 ++++++++-
 3 files changed, 23 insertions(+), 32 deletions(-)

diff --git a/evil-common.el b/evil-common.el
index 1ac543b231..1ea0f8732c 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 4d87323bff..a7242c226a 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 6358087e3f..f84d0db4a6 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"



reply via email to

[Prev in Thread] Current Thread [Next in Thread]