From 728983be0ec4e290905a6282bcc6c7c3ffd15cda Mon Sep 17 00:00:00 2001 From: wzy <32936898+Freed-Wu@users.noreply.github.com> Date: Wed, 25 Sep 2024 17:55:35 +0800 Subject: [PATCH] Improve `ModalCursorShapeConfig` for various input modes (#1900) - Also display a beam cursor for Vi "insert multiple" mode (visual block insert). - Also display an underline cursor for Vi "replace single" mode. - Display a beam in Emacs mode (like Vi's insert). --- src/prompt_toolkit/cursor_shapes.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/prompt_toolkit/cursor_shapes.py b/src/prompt_toolkit/cursor_shapes.py index 453b72c3c..cbd8e593f 100644 --- a/src/prompt_toolkit/cursor_shapes.py +++ b/src/prompt_toolkit/cursor_shapes.py @@ -69,10 +69,23 @@ class ModalCursorShapeConfig(CursorShapeConfig): def get_cursor_shape(self, application: Application[Any]) -> CursorShape: if application.editing_mode == EditingMode.VI: - if application.vi_state.input_mode == InputMode.INSERT: + if application.vi_state.input_mode in { + InputMode.NAVIGATION, + }: + return CursorShape.BLOCK + if application.vi_state.input_mode in { + InputMode.INSERT, + InputMode.INSERT_MULTIPLE, + }: return CursorShape.BEAM - if application.vi_state.input_mode == InputMode.REPLACE: + if application.vi_state.input_mode == { + InputMode.REPLACE, + InputMode.REPLACE_SINGLE, + }: return CursorShape.UNDERLINE + elif application.editing_mode == EditingMode.EMACS: + # like vi's INSERT + return CursorShape.BEAM # Default return CursorShape.BLOCK