Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion book/src/editor.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,9 @@ The following statusline elements can be configured:
### `[editor.cursor-shape]` Section

Defines the shape of cursor in each mode.
Valid values for these options are `block`, `bar`, `underline`, or `hidden`.
Valid values for these options are `block`, `bar`, `underline`, `hidden`, or `native`.

The `native` option uses the terminal's default cursor shape as configured by the user in their terminal settings.

> 💡 Due to limitations of the terminal environment, only the primary cursor can
> change shape.
Expand Down
18 changes: 16 additions & 2 deletions helix-term/src/ui/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1625,16 +1625,30 @@ impl Component for EditorView {
}

fn cursor(&self, _area: Rect, editor: &Editor) -> (Option<Position>, CursorKind) {
let (view, doc) = current_ref!(editor);
let has_multiple_selections = doc.selection(view.id).len() > 1;

match editor.cursor() {
// all block cursors are drawn manually
// Block cursors are always manually rendered via highlight spans
(pos, CursorKind::Block) => {
if self.terminal_focused {
(pos, CursorKind::Hidden)
} else {
// use terminal cursor when terminal loses focus
// Use terminal cursor as fallback when unfocused
(pos, CursorKind::Underline)
}
}
// Native cursor: use terminal for single selection, manual for multiple
(pos, CursorKind::Native) => {
if has_multiple_selections && self.terminal_focused {
// Can't use terminal cursor for multiple selections
(pos, CursorKind::Hidden)
} else {
// Pass through to terminal for native cursor rendering
(pos, CursorKind::Native)
}
}
// Bar/Underline: let the terminal render them
cursor => cursor,
}
}
Expand Down
1 change: 1 addition & 0 deletions helix-tui/src/backend/crossterm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ where
CursorKind::Block => SetCursorStyle::SteadyBlock,
CursorKind::Bar => SetCursorStyle::SteadyBar,
CursorKind::Underline => SetCursorStyle::SteadyUnderScore,
CursorKind::Native => SetCursorStyle::DefaultUserShape,
CursorKind::Hidden => unreachable!(),
};
execute!(self.buffer, Show, shape)
Expand Down
1 change: 1 addition & 0 deletions helix-tui/src/backend/termina.rs
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,7 @@ impl Backend for TerminaBackend {
CursorKind::Block => CursorStyle::SteadyBlock,
CursorKind::Bar => CursorStyle::SteadyBar,
CursorKind::Underline => CursorStyle::SteadyUnderline,
CursorKind::Native => CursorStyle::Default,
CursorKind::Hidden => unreachable!(),
};
write!(
Expand Down
2 changes: 2 additions & 0 deletions helix-view/src/graphics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ pub enum CursorKind {
Underline,
/// Hidden cursor, can set cursor position with this to let IME have correct cursor position.
Hidden,
/// Use the terminal's native/default cursor shape configured by the user.
Native,
}

impl Default for CursorKind {
Expand Down