on master help sign in
use crossterm cursor in editor when out of focus (#6858)
71fd858Hendrik Norkowski
helix-term/src/ui/editor.rs+17−4
@@ -158,6 +158,7 @@ impl EditorView {
158 view,
158 view,
159 theme,
159 theme,
160 &config.cursor_shape,
160 &config.cursor_shape,
161+ self.terminal_focused,
161 ),
162 ),
162 );
163 );
163 let focused_view_elements = Self::highlight_focused_view_elements(view, doc, theme);
164 let focused_view_elements = Self::highlight_focused_view_elements(view, doc, theme);
@@ -420,6 +421,7 @@ impl EditorView {
420 view: &View,
421 view: &View,
421 theme: &Theme,
422 theme: &Theme,
422 cursor_shape_config: &CursorShapeConfig,
423 cursor_shape_config: &CursorShapeConfig,
424+ is_terminal_focused: bool,
423 ) -> Vec<(usize, std::ops::Range<usize>)> {
425 ) -> Vec<(usize, std::ops::Range<usize>)> {
424 let text = doc.text().slice(..);
426 let text = doc.text().slice(..);
425 let selection = doc.selection(view.id);
427 let selection = doc.selection(view.id);
@@ -490,13 +492,17 @@ impl EditorView {
490 cursor_start
492 cursor_start
491 };
493 };
492 spans.push((selection_scope, range.anchor..selection_end));
494 spans.push((selection_scope, range.anchor..selection_end));
495+ // add block cursors
496+ // skip primary cursor if terminal is unfocused - crossterm cursor is used in that case
493− if !selection_is_primary || cursor_is_block {
497+ if !selection_is_primary || (cursor_is_block && is_terminal_focused) {
494 spans.push((cursor_scope, cursor_start..range.head));
498 spans.push((cursor_scope, cursor_start..range.head));
495 }
499 }
496 } else {
500 } else {
497 // Reverse case.
501 // Reverse case.
498 let cursor_end = next_grapheme_boundary(text, range.head);
502 let cursor_end = next_grapheme_boundary(text, range.head);
503+ // add block cursors
504+ // skip primary cursor if terminal is unfocused - crossterm cursor is used in that case
499− if !selection_is_primary || cursor_is_block {
505+ if !selection_is_primary || (cursor_is_block && is_terminal_focused) {
500 spans.push((cursor_scope, range.head..cursor_end));
506 spans.push((cursor_scope, range.head..cursor_end));
501 }
507 }
502 // non block cursors look like they exclude the cursor
508 // non block cursors look like they exclude the cursor
@@ -1520,8 +1526,15 @@ impl Component for EditorView {
1520
1526
1521 fn cursor(&self, _area: Rect, editor: &Editor) -> (Option<Position>, CursorKind) {
1527 fn cursor(&self, _area: Rect, editor: &Editor) -> (Option<Position>, CursorKind) {
1522 match editor.cursor() {
1528 match editor.cursor() {
1523− // All block cursors are drawn manually
1529+ // all block cursors are drawn manually
1530+ (pos, CursorKind::Block) => {
1531+ if self.terminal_focused {
1524− (pos, CursorKind::Block) => (pos, CursorKind::Hidden),
1532+ (pos, CursorKind::Hidden)
1533+ } else {
1534+ // use crossterm cursor when terminal loses focus
1535+ (pos, CursorKind::Underline)
1536+ }
1537+ }
1525 cursor => cursor,
1538 cursor => cursor,
1526 }
1539 }
1527 }
1540 }