evil-collection icon indicating copy to clipboard operation
evil-collection copied to clipboard

evil append does not promote the cursor position appropriately

Open bram209 opened this issue 2 years ago • 8 comments

The following PR seems to have introduced a bug: https://github.com/emacs-evil/evil-collection/pull/638 After appending, the cursor will visually show the correct position, but as soon as you start typing it basically inserts instead of appends.

Effectively reverting the above-mentioned PR, it works as expected (using doom emacs):

(after! evil-collection
  (defun evil-collection-vterm-append ()
    "Append character after cursor."
    (interactive)
    (vterm-goto-char (1+ (point)))
    (call-interactively #'evil-append)))

@quangIO @mjlbach any idea why it (seems to) behave differently on different setups?

bram209 avatar Jul 07 '22 12:07 bram209

You are right. #638 worked correctly at the time I created the PR. After I upgraded doom today, it behaved incorrectly like the way you describe (not sure about the root cause)

Does your fix have the correct cursor position and work correctly when cursor is under end of line position?

quangIO avatar Jul 07 '22 13:07 quangIO

Does your fix have the correct cursor position and work correctly when cursor is under end of line position?

No, it does not have the correct cursor position, the behavior is the inverse: the cursor is visually incorrect (1 position ahead), but as soon as you start typing it appends correctly.

At the end of a line, both the cursor position & the append behavior works correctly with the above-mentioned fix

bram209 avatar Jul 08 '22 09:07 bram209

Does your fix have the correct cursor position and work correctly when cursor is under end of line position?

No, it does not have the correct cursor position, the behavior is the inverse: the cursor is visually incorrect (1 position ahead), but as soon as you start typing it appends correctly.

At the end of a line, both the cursor position & the append behavior works correctly with the above-mentioned fix

I think using evil insert as a workaround will fix the cursor position problem, but that may not work when cursor is at elop.

  (defun evil-collection-vterm-append ()
    "Append character after cursor."
    (interactive)
    (vterm-goto-char (1+ (point)))
    (call-interactively #'evil-insert)))

It would be nicer if we can chase the root cause.

quangIO avatar Jul 08 '22 09:07 quangIO

evil-insert seems to be working fine, except that the cursor after "appending" should be one position back. so if you are not at the end of the line, after appending & exiting insert mode, the cursor has moved to the next character.

bram209 avatar Jul 08 '22 09:07 bram209

@bram209 this thread has the workaround https://github.com/akermu/emacs-libvterm/issues/313.

TLDR: add something like to your config.

(defadvice! +vterm-update-cursor (orig-fn &rest args) :before #'vterm-send-key (vterm-goto-char (point)))
(defadvice! +vterm-update-cursor-boon (orig-fn &rest args) :before #'boon-insert (vterm-goto-char (point)))

x to delete currently doesn't work though.

quangIO avatar Sep 11 '22 17:09 quangIO

@bram209 this thread has the workaround akermu/emacs-libvterm#313.

TLDR: add something like to your config.

(defadvice! +vterm-update-cursor (orig-fn &rest args) :before #'vterm-send-key (vterm-goto-char (point)))
(defadvice! +vterm-update-cursor-boon (orig-fn &rest args) :before #'boon-insert (vterm-goto-char (point)))

x to delete currently doesn't work though.

This solved the issue for me

Mrngilles avatar Nov 30 '22 14:11 Mrngilles

the cursor is visually incorrect (1 position ahead), but as soon as you start typing it appends correctly.

Yeah this seems to be a common annoying problem because apparently the "internal cursor position" is different from what we see visually. Personally I have the following code to workaround this issue:

(add-hook 'evil-insert-state-entry-hook #'vterm-reset-cursor-point nil t)

blahgeek avatar Dec 11 '22 09:12 blahgeek

Is there something actionable on evil-collection's end here? @quangIO @blahgeek

jojojames avatar Mar 09 '23 19:03 jojojames