Skip to content

Commit

Permalink
Fix block pasting at bolp on empty line
Browse files Browse the repository at this point in the history
  • Loading branch information
tomdl89 committed May 13, 2024
1 parent 0b25d3c commit 8a06c5c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
19 changes: 10 additions & 9 deletions evil-common.el
Original file line number Diff line number Diff line change
Expand Up @@ -2441,12 +2441,15 @@ The tracked insertion is set to `evil-last-insertion'."

(defun evil-yank-block-handler (lines)
"Insert the current text as block."
(let ((count (or evil-paste-count 1))
(col (if (eq this-command 'evil-paste-after)
(1+ (current-column))
(current-column)))
(opoint (point))
(first t))
(let* ((count (or evil-paste-count 1))
shifted-forward
(col (if (and (eq this-command 'evil-paste-after)
(not (and (bolp) (eolp)))
(setq shifted-forward t))
(1+ (current-column))
(current-column)))
(opoint (point))
(first t))
(dolist (line lines)
;; maybe we have to insert a new line at eob
(if first
Expand Down Expand Up @@ -2485,9 +2488,7 @@ The tracked insertion is set to `evil-last-insertion'."
(if evil--cursor-after
(backward-char)
(goto-char opoint)
(when (and (eq this-command 'evil-paste-after)
(not (eolp)))
(forward-char)))))
(when shifted-forward (forward-char)))))

(defun evil-delete-yanked-rectangle (nrows ncols)
"Special function to delete the block yanked by a previous paste command.
Expand Down
22 changes: 20 additions & 2 deletions evil-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -3250,7 +3250,6 @@ word3[]"))
(evil-test-buffer
"[a]aaaaa\nbbbbb\ncccc"
("\C-v" "2j" "$" "\"xy" "G" "o" [escape] "\"xp")
;; TODO will fail because it inserts a left col of spaces
"aaaaaa\nbbbbb\ncccc\n[a]aaaaa\nbbbbb\ncccc")))

(ert-deftest evil-test-last-insert-register ()
Expand Down Expand Up @@ -7528,7 +7527,26 @@ Tiny "))
"
("\C-vfcjd")
"[b]c
")))
"))
(ert-info ("Pasting visual block")
(evil-test-buffer
"alpha [b]ravo charlie
delta echo foxtrot
golf hotel india
juliet kilo mike"
("\C-v" "jje" "y" "$" "p")
"alpha bravo charlie[b]rav
delta echo foxtrot echo
golf hotel india otel
juliet kilo mike"
("G" "o" [escape] "p")
"alpha bravo charliebrav
delta echo foxtrot echo
golf hotel india otel
juliet kilo mike
[b]rav
echo
otel")))

(ert-deftest evil-test-visual-restore ()
"Test restoring a previous selection"
Expand Down

0 comments on commit 8a06c5c

Please sign in to comment.