diff options
| author | Tom Dalziel <33435574+tomdl89@users.noreply.github.com> | 2021-04-17 00:23:16 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-04-17 00:23:16 +0200 |
| commit | 1b3db6349d04adfc68f707b0edd800f5ab3cb374 (patch) | |
| tree | e6460af74c5b3da13f991f295ad9dbefff4ddc75 | |
| parent | d998a8195e404b01e2ea62a455c3dec74d0823c3 (diff) | |
Fixup visual change commands (#1456)
* Fix `S` `C` & `R` in visual mode
* Add tests for C S and R, especially in visual states
| -rw-r--r-- | evil-commands.el | 14 | ||||
| -rw-r--r-- | evil-maps.el | 2 | ||||
| -rw-r--r-- | evil-tests.el | 49 |
3 files changed, 59 insertions, 6 deletions
diff --git a/evil-commands.el b/evil-commands.el index 64fdc0a..233d50d 100644 --- a/evil-commands.el +++ b/evil-commands.el @@ -1682,17 +1682,21 @@ of the block." (evil-insert 1))))) (evil-define-operator evil-change-line (beg end type register yank-handler) - "Change to end of line." + "Change to end of line, or change whole line if characterwise visual mode." :motion evil-end-of-line-or-visual-line (interactive "<R><x><y>") - (evil-change beg end type register yank-handler #'evil-delete-line)) + (if (and (evil-visual-state-p) (eq 'inclusive type)) + (cl-destructuring-bind (beg* end* &rest) (evil-line-expand beg end) + (evil-change-whole-line beg* end* register yank-handler)) + (evil-change beg end type register yank-handler #'evil-delete-line))) (evil-define-operator evil-change-whole-line - (beg end type register yank-handler) + (beg end register yank-handler) "Change whole line." :motion evil-line-or-visual-line - (interactive "<R><x>") - (evil-change beg end type register yank-handler #'evil-delete-whole-line)) + :type line + (interactive "<r><x>") + (evil-change beg end 'line register yank-handler #'evil-delete-whole-line)) (evil-define-command evil-copy (beg end address) "Copy lines in BEG END below line given by ADDRESS." diff --git a/evil-maps.el b/evil-maps.el index d4486c4..7429acd 100644 --- a/evil-maps.el +++ b/evil-maps.el @@ -352,7 +352,7 @@ (define-key evil-visual-state-map "I" 'evil-insert) (define-key evil-visual-state-map "o" 'exchange-point-and-mark) (define-key evil-visual-state-map "O" 'evil-visual-exchange-corners) -(define-key evil-visual-state-map "R" 'evil-change) +(define-key evil-visual-state-map "R" 'evil-change-whole-line) (define-key evil-visual-state-map "u" 'evil-downcase) (define-key evil-visual-state-map "U" 'evil-upcase) (define-key evil-visual-state-map "z=" 'ispell-word) diff --git a/evil-tests.el b/evil-tests.el index d88b39a..3da01b0 100644 --- a/evil-tests.el +++ b/evil-tests.el @@ -2004,6 +2004,55 @@ DEFLINE ("2ccABC" [escape]) ";; This buffer is for notes you don't want to save. AB[C]")) + (ert-info ("C changes whole line in visual characterwise and linewise states") + (evil-test-buffer + "Two lines [s]hould suffice +for this test." + ("veC" "all gone!") + "all gone![] +for this test.") + (evil-test-buffer + "Two lines [w]ill be fine +for this test too." + ("VjC" "all gone!") + "all gone![]")) + (ert-info ("C clears the visual blockwise selection, and all text to the right") + (evil-test-buffer + "Two [l]ines will be fine for +the tests here as well." + ("\C-vjeC") + "Two [] +the ")) + (ert-info ("S clears the whole line in normal mode, and all lines touched by visual selection") + (evil-test-buffer + "Two lines [s]hould suffice +for this test." + ("S" "all gone!") + "all gone![] +for this test.") + (evil-test-buffer + "Two lines [s]hould suffice +for this test." + ("vS" "all gone!") + "all gone![] +for this test.") + (evil-test-buffer + "Two lines [s]hould suffice +for this test." + ("VjS" "all gone!") + "all gone![]") + (evil-test-buffer + "Two lines [s]hould suffice +for this test." + ("\C-VjS" "all gone!") + "all gone![]")) + (ert-info ("R behaves the same as S in visual modes") + (evil-test-buffer + "Two lines [s]hould suffice +for this test." + ("vR" "all gone!") + "all gone![] +for this test.")) (ert-info ("Change rectangle") (evil-test-buffer "[;]; This buffer is for notes you don't want to save. |
