From 6ca32ca05eef41c3bc3d9cc66fc052741250bc3a Mon Sep 17 00:00:00 2001 From: Tom Dalziel Date: Thu, 4 Jan 2024 11:59:38 +0100 Subject: [PATCH] Fix pasting charwise text onto linewise selection --- evil-commands.el | 5 +++++ evil-tests.el | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/evil-commands.el b/evil-commands.el index 21a2527c..286cf946 100644 --- a/evil-commands.el +++ b/evil-commands.el @@ -2356,6 +2356,11 @@ leave the cursor just after the new text." (setq beg evil-visual-beginning end evil-visual-end type (evil-visual-type)) + ;; When pasting charwise text into linewise selection, keep trailing NL + (when (and text end + (eq 'line type) + (not (eq ?\n (aref text (1- (length text)))))) + (cl-decf end)) (evil-visual-rotate 'upper-left) (evil-delete beg end type (unless evil-kill-on-visual-paste ?_)) (when (and (eq yank-handler #'evil-yank-line-handler) diff --git a/evil-tests.el b/evil-tests.el index 84a779e2..09569f15 100644 --- a/evil-tests.el +++ b/evil-tests.el @@ -3081,7 +3081,7 @@ word3[]")) ("yiwyywyiw^j") "word1a word1b word1c\n[w]ord2a word2b\nword3a word3b word3c word3d\n" ("Vp") - "word1a word1b word1c\nword1[b]word3a word3b word3c word3d\n")) + "word1a word1b word1c\nword1[b]\nword3a word3b word3c word3d\n")) (ert-info ("Visual-line paste, char paste, line pop") (evil-test-buffer "[w]ord1a word1b word1c\nword2a word2b\nword3a word3b word3c word3d\n" @@ -3095,7 +3095,7 @@ word3[]")) ("yiwyywyiw^j") "word1a word1b word1c\n[w]ord2a word2b\nword3a word3b word3c word3d\n" ("Vp\C-p\C-p") - "word1a word1b word1c\nword1[a]word3a word3b word3c word3d\n"))) + "word1a word1b word1c\nword1[a]\nword3a word3b word3c word3d\n"))) (ert-deftest evil-test-register () "Test yanking and pasting to and from register."