Skip to content

Commit

Permalink
Improve ModalCursorShapeConfig for various input modes (#1900)
Browse files Browse the repository at this point in the history
- 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).
  • Loading branch information
Freed-Wu authored Sep 25, 2024
1 parent 75615b1 commit 728983b
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/prompt_toolkit/cursor_shapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 728983b

Please sign in to comment.