Skip to content

Commit 94e2b0b

Browse files
FrostyXjixiuf
authored andcommitted
Don't allow moving cursor below the last prompt via mouse
Without this patch, I am able to click somewhere below the last prompt line and move the cursor there. I don't think this was an intended feature, it feels more like a weird quirk. We don't have any function telling us the point or line number of the last prompt, and it doesn't seem to be easy to implement, so I needed to workaround this.
1 parent bb213bb commit 94e2b0b

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

vterm.el

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,7 @@ Exceptions are defined by `vterm-keymap-exceptions'."
642642
(define-key map [remap xterm-paste] #'vterm-xterm-paste)
643643
(define-key map [remap yank-pop] #'vterm-yank-pop)
644644
(define-key map [remap mouse-yank-primary] #'vterm-yank-primary)
645+
(define-key map [mouse-1] #'vterm-mouse-set-point)
645646
(define-key map (kbd "C-SPC") #'vterm--self-insert)
646647
(define-key map (kbd "S-SPC") #'vterm-send-space)
647648
(define-key map (kbd "C-_") #'vterm--self-insert)
@@ -1112,6 +1113,18 @@ Argument ARG is passed to `yank'"
11121113
(cl-letf (((symbol-function 'insert-for-yank) #'vterm-insert))
11131114
(yank-pop arg))))
11141115

1116+
(defun vterm-mouse-set-point (event &optional promote-to-region)
1117+
"Move point to the position clicked on with the mouse.
1118+
But when clicking to the unused area below the last prompt,
1119+
move the cursor to the prompt area."
1120+
(interactive "e\np")
1121+
(let ((pt (mouse-set-point event promote-to-region)))
1122+
(if (= (count-words pt (point-max)) 0)
1123+
(vterm-reset-cursor-point)
1124+
pt))
1125+
;; Otherwise it selects text for every other click
1126+
(keyboard-quit))
1127+
11151128
(defun vterm-send-string (string &optional paste-p)
11161129
"Send the string STRING to vterm.
11171130
Optional argument PASTE-P paste-p."

0 commit comments

Comments
 (0)