Skip to content

Commit

Permalink
Don't allow moving cursor below the last prompt via mouse
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
FrostyX authored and jixiuf committed Apr 17, 2023
1 parent bb213bb commit 94e2b0b
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions vterm.el
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,7 @@ Exceptions are defined by `vterm-keymap-exceptions'."
(define-key map [remap xterm-paste] #'vterm-xterm-paste)
(define-key map [remap yank-pop] #'vterm-yank-pop)
(define-key map [remap mouse-yank-primary] #'vterm-yank-primary)
(define-key map [mouse-1] #'vterm-mouse-set-point)
(define-key map (kbd "C-SPC") #'vterm--self-insert)
(define-key map (kbd "S-SPC") #'vterm-send-space)
(define-key map (kbd "C-_") #'vterm--self-insert)
Expand Down Expand Up @@ -1112,6 +1113,18 @@ Argument ARG is passed to `yank'"
(cl-letf (((symbol-function 'insert-for-yank) #'vterm-insert))
(yank-pop arg))))

(defun vterm-mouse-set-point (event &optional promote-to-region)
"Move point to the position clicked on with the mouse.
But when clicking to the unused area below the last prompt,
move the cursor to the prompt area."
(interactive "e\np")
(let ((pt (mouse-set-point event promote-to-region)))
(if (= (count-words pt (point-max)) 0)
(vterm-reset-cursor-point)
pt))
;; Otherwise it selects text for every other click
(keyboard-quit))

(defun vterm-send-string (string &optional paste-p)
"Send the string STRING to vterm.
Optional argument PASTE-P paste-p."
Expand Down

0 comments on commit 94e2b0b

Please sign in to comment.