From 88d073c9d03ca223564e7e8589f44ecc87c98153 Mon Sep 17 00:00:00 2001 From: Tom Dalziel Date: Tue, 2 Apr 2024 19:38:37 +0200 Subject: [PATCH] Fix point placement after D and C in normal state Bug since 476f5fbcf1288c5a46a6ba35efe0b8dd1e4dd0ec Thanks to @axelf4 for spotting. --- evil-commands.el | 13 +++++++------ evil-tests.el | 32 +++++++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 7 deletions(-) diff --git a/evil-commands.el b/evil-commands.el index 150ac046..7938b93a 100644 --- a/evil-commands.el +++ b/evil-commands.el @@ -1530,12 +1530,13 @@ Save in REGISTER or in the kill-ring with YANK-HANDLER." (last-command 'next-line)) (evil-delete beg end 'block register yank-handler)) (evil-delete beg end type register yank-handler) - (evil-first-non-blank) - (when (and (not evil-start-of-line) evil-operator-start-col) - (move-to-column (if (and (eq most-positive-fixnum temporary-goal-column) - (memq last-command '(next-line previous-line))) - temporary-goal-column - evil-operator-start-col)))))) + (when (eq 'line type) + (evil-first-non-blank) + (when (and (not evil-start-of-line) evil-operator-start-col) + (move-to-column (if (and (eq most-positive-fixnum temporary-goal-column) + (memq last-command '(next-line previous-line))) + temporary-goal-column + evil-operator-start-col))))))) (evil-define-operator evil-delete-whole-line (beg end type register yank-handler) diff --git a/evil-tests.el b/evil-tests.el index 8ca961fc..259c6ff9 100644 --- a/evil-tests.el +++ b/evil-tests.el @@ -2166,7 +2166,37 @@ ine3 line3 line3 l\n")) ;; This is line three" ("v$D") ";; This is line one -;; This is line three"))) +;; This is line three")) + (ert-info ("Deletion in normal state leaves point in the right place") + (evil-test-buffer + "alpha b[r]avo charlie\ndelta echo foxtrot\ngolf hotel india" + (should (not evil-start-of-line)) + ("D") + "alpha [b]\ndelta echo foxtrot\ngolf hotel india" + ("/echo" [return] "C" "newtext" [escape]) + "alpha b\ndelta newtex[t]\ngolf hotel india") + (let ((evil-start-of-line t)) + (evil-test-buffer + "alpha b[r]avo charlie\ndelta echo foxtrot\ngolf hotel india" + ("D") + "alpha [b]\ndelta echo foxtrot\ngolf hotel india" + ("/echo" [return] "C" "newtext" [escape]) + "alpha b\ndelta newtex[t]\ngolf hotel india"))) + (ert-info ("Line deletion in visual state leaves point in the right place") + (evil-test-buffer + "alpha [b]ravo charlie\ndelta echo foxtrot\ngolf hotel india" + (should (not evil-start-of-line)) + ("vD") + "delta [e]cho foxtrot\ngolf hotel india" + ("vX") + "golf h[o]tel india") + (let ((evil-start-of-line t)) + (evil-test-buffer + "alpha [b]ravo charlie\ndelta echo foxtrot\ngolf hotel india" + ("vD") + "[d]elta echo foxtrot\ngolf hotel india" + ("vX") + "[g]olf hotel india")))) (ert-deftest evil-test-delete-folded () "Test `evil-delete' on folded lines."