'd' delete with a mouse click mispositions cursor location
Issue type
- Bug report
Environment
Emacs version: GNU Emacs 26.3 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.20) of 2020-05-19
Operation System: manjaro arch linux
Evil version: Evil version evil-git-2a7df6d9
Evil installation type: MELPA
Graphical/Terminal: issue in both
Tested in a make emacs session: Yes
Issue
when using evil mode, pressing 'd' in normal mode and then clicking a position deletes what ever is in between the current cursor location and the clicked position. The issue I noticed was that when the cursor location is at a position located before the position clicked, the cursor isn't placed on the click character afterwards. Illustration
Reproduction steps
- emacs in evil mode
- open new buffer and create string "bob john this emacs foobar"
- place the cursor on 'j' of "john"
- then press 'd' and click on 'i' of "this"
Expected behavior
the string to now be "bob is emacs foobar" where the cursor is on 'i' of "is", this is the default behavior in vim.
Actual behavior
but the cursor is on 's' of "emacs".
Further notes
executing evil-go-to-mark or pop-to-mark-command afterwards moves the cursor to 'i' of "is". it works as expected if I had placed the cursor on 'i' of "this" and then pressed 'd' and clicked in on 'j' of "john", basically done the reverse.
I believe this is caused because the cursor keeps its column or x-axis location after the sequence of commands, while in actuality it should be updated.
Investigated more and found that (goto-char (posn-point position)))) within posn-set-point is the cause. maybe we can do something that doesn't call this function as long as the current cursor location comes after the pervious location.
fixed. place the following in init. posn-set-point is ran two times when clicking to delete. I don't know why but this modification handles that as well.
(defun posn-set-point (position)
"Move point to POSITION.
Select the corresponding window as well."
(if (not (windowp (posn-window position)))
(error "Position not in text area of window"))
(select-window (posn-window position))
(let ((new-pos (posn-point position))
(old-pos (point)))
; (print old-pos)
; (print new-pos)
(if (and (numberp new-pos) (> old-pos new-pos))
(goto-char new-pos)))
)
this made me figure out how to implement a feature I was looking for. selection with mouse without having to press down mouse on my touchpad.
#+begin_src emacs-lisp
(evil-define-operator evil-select (beg end type register yank-handler)
"Delete text from BEG to END with TYPE.
Save in REGISTER or in the kill-ring with YANK-HANDLER."
(interactive "<R><x><y>")
(evil-visual-select beg end evil-visual-char (evil-visual-direction))
)
(define-key evil-normal-state-map "v" 'evil-select)
#+end_src