vterm: prevent moving the cursor below the last prompt line by `j' button

It is not 100% bulletproof but 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.
This commit is contained in:
Jakub Kadlcik 2023-02-10 16:54:55 +01:00 committed by Youmu
parent 692fb0fc86
commit 5fbfc359b4
1 changed files with 12 additions and 1 deletions

View File

@ -213,6 +213,16 @@ Save in REGISTER or in the kill-ring with YANK-HANDLER."
(interactive "<r><x>")
(evil-collection-vterm-change beg end 'line register yank-handler))
(evil-define-motion evil-collection-vterm-next-line (count)
"Move the cursor COUNT lines down.
But don't allow the cursor to move bellow the last prompt line."
:type line
;; This successfully prevents the `j' button from moving to an empty line
;; bellow the last prompt. However, it still can be bugged for example by
;; going to the one line above the last prompt and doing `10j'.
(when (> (count-words (point) (point-max)) 0)
(evil-next-line count)))
;;;###autoload
(defun evil-collection-vterm-setup ()
"Set up `evil' bindings for `vterm'."
@ -267,7 +277,8 @@ Save in REGISTER or in the kill-ring with YANK-HANDLER."
"c" 'evil-collection-vterm-change
"C" 'evil-collection-vterm-change-line
"s" 'evil-collection-vterm-substitute
"S" 'evil-collection-vterm-substitute-line)
"S" 'evil-collection-vterm-substitute-line
"j" 'evil-collection-vterm-next-line)
(evil-collection-define-key 'visual 'vterm-mode-map
"d" 'evil-collection-vterm-delete