diff --git a/extensions/vi-mode/binds.lisp b/extensions/vi-mode/binds.lisp index c6dffc20c..906ef2e77 100644 --- a/extensions/vi-mode/binds.lisp +++ b/extensions/vi-mode/binds.lisp @@ -128,6 +128,7 @@ (define-key *normal-keymap* "g U" 'vi-upcase) (define-key *normal-keymap* "g u" 'vi-downcase) (define-key *normal-keymap* "g ~" 'vi-swapcase) +(define-key *normal-keymap* "~" 'vi-swapcase-and-forward-char) (define-key *normal-keymap* "u" 'vi-undo) (define-key *normal-keymap* "C-r" 'vi-redo) (define-key *motion-keymap* 'delete-previous-char 'vi-backward-char) diff --git a/extensions/vi-mode/commands.lisp b/extensions/vi-mode/commands.lisp index 0c8c50b15..fadeae2a2 100644 --- a/extensions/vi-mode/commands.lisp +++ b/extensions/vi-mode/commands.lisp @@ -90,6 +90,7 @@ :vi-upcase :vi-downcase :vi-swapcase + :vi-swapcase-and-forward-char :vi-undo :vi-redo :vi-record-macro @@ -639,6 +640,12 @@ Move the cursor to the first non-blank character of the line." (apply-visual-range #'swapcase-region) (swapcase-region start end)))) +(define-command vi-swapcase-and-forward-char () () + (let* ((start (copy-point (current-point))) + (end (character-offset (current-point) 1))) + (vi-swapcase start end (current-state))) + (vi-forward-char)) + (define-command vi-undo (&optional (n 1)) (:universal) (undo n)) diff --git a/src/mouse.lisp b/src/mouse.lisp index ff2943e73..0ef505997 100644 --- a/src/mouse.lisp +++ b/src/mouse.lisp @@ -215,6 +215,15 @@ (funcall callback window point) t)) +(defun sync-mark-start-point-for-vi-mode (start-point) + (when (typep (lem:current-global-mode) 'lem-vi-mode:vi-mode) + ;; Ensure current main state is visual-char. + (unless (lem-vi-mode/visual:visual-char-p) + (lem-vi-mode/commands::vi-visual-char)) + ;; Override the *start-point* in vi-visual mode. + (setf lem-vi-mode/visual::*start-point* start-point) + )) + (defmethod handle-mouse-hover (buffer mouse-event &key window x y) (case (mouse-event-button mouse-event) ((nil) @@ -224,6 +233,8 @@ (handle-mouse-unhover-buffer window point)))) (:button-1 (when (window-last-mouse-button-down-point window) + (sync-mark-start-point-for-vi-mode (window-last-mouse-button-down-point window)) + (move-current-point-to-x-y-position window x y) (set-current-mark (window-last-mouse-button-down-point window)))))) @@ -310,6 +321,8 @@ (multiple-value-bind (start end) (get-select-expression-points (current-point)) (when start + (sync-mark-start-point-for-vi-mode start) + (set-current-mark start) (move-point (current-point) end))))