Skip to content

Commit 457ac07

Browse files
authored
Fix c-o at eol for cursor-forward commands, replace state, add tests (#1464)
Properly fixes #1463 * Fix c-o at eol for cursor-forward commands, replace state, add tests
1 parent f0fdfef commit 457ac07

File tree

2 files changed

+47
-5
lines changed

2 files changed

+47
-5
lines changed

evil-commands.el

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4635,11 +4635,16 @@ if the previous state was Emacs state."
46354635
(when (evil-emacs-state-p)
46364636
(evil-normal-state (and message 1))))))
46374637

4638+
(evil-define-local-var evil--execute-normal-eol-pos nil
4639+
"Vim has special behaviour for executing in normal state at eol.
4640+
This var stores the eol position, so it can be restored when necessary.")
4641+
46384642
(defun evil-execute-in-normal-state ()
46394643
"Execute the next command in Normal state."
46404644
(interactive)
46414645
(evil-delay '(not (memq this-command
46424646
'(evil-execute-in-normal-state
4647+
evil-replace-state
46434648
evil-use-register
46444649
digit-argument
46454650
negative-argument
@@ -4649,10 +4654,17 @@ if the previous state was Emacs state."
46494654
universal-argument-other-key)))
46504655
`(progn
46514656
(with-current-buffer ,(current-buffer)
4652-
(evil-change-state ',evil-state)
4657+
(when (and evil--execute-normal-eol-pos
4658+
(= (point) (1- evil--execute-normal-eol-pos))
4659+
(not (memq this-command '(evil-insert
4660+
evil-goto-mark))))
4661+
(forward-char))
4662+
(unless (eq 'replace evil-state)
4663+
(evil-change-state ',evil-state))
46534664
(setq evil-move-cursor-back ',evil-move-cursor-back
46544665
evil-move-beyond-eol ',evil-move-beyond-eol)))
46554666
'post-command-hook)
4667+
(setq evil--execute-normal-eol-pos (when (eolp) (point)))
46564668
(setq evil-move-cursor-back nil)
46574669
(evil-normal-state)
46584670
(setq evil-move-beyond-eol t)

evil-tests.el

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -309,10 +309,40 @@ with `M-x evil-tests-run'"))
309309
("bcdef[]\n"))
310310
(ert-info ("Cursor is placed correctly afterwards")
311311
(evil-test-buffer
312-
:state insert
313-
"abcdefg[]"
314-
("\C-o~")
315-
"abcdefG[]"))))
312+
:state insert
313+
"abcdefg[]"
314+
("\C-o~")
315+
"abcdefG[]")
316+
(evil-test-buffer
317+
:state insert
318+
"abcdefg[]"
319+
("\C-ozz")
320+
"abcdefg[]")
321+
(evil-test-buffer
322+
:state insert
323+
"abc[]defg"
324+
("\C-o$")
325+
"abcdefg[]")
326+
(evil-test-buffer
327+
:state insert
328+
"abcdefg[]"
329+
("\C-o^")
330+
"[]abcdefg")
331+
(evil-test-buffer
332+
:state insert
333+
"abcdefg[]"
334+
("\C-oi")
335+
"abcdef[]g")
336+
(evil-test-buffer
337+
"line1\nli[n]e2"
338+
("ma" "kA" "\C-o`a")
339+
"line1\nli[]ne2"))
340+
(ert-info ("Can enter replace state and stay in it")
341+
(evil-test-buffer
342+
:state insert
343+
"abc[]defg"
344+
("\C-oRfoo")
345+
"abcfoog"))))
316346

317347
(defun evil-test-suppress-keymap (state)
318348
"Verify that `self-insert-command' is suppressed in STATE"

0 commit comments

Comments
 (0)