From 64a28b3f60c2b4a1634ff281f9d00341bd597381 Mon Sep 17 00:00:00 2001 From: woojiq Date: Tue, 15 Aug 2023 20:39:20 +0300 Subject: [PATCH 1/2] fix: line numbers remain relative when helix loses focus If `line number = relative` and a new window is opened in helix, lines inside unfocused windows will be `absolute`. This commit adds the same thing when helix becomes unfocused in a terminal emulator. --- helix-term/src/ui/editor.rs | 6 +++++- helix-view/src/editor.rs | 2 ++ helix-view/src/gutter.rs | 3 ++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index aa159d40dce5..64f8868591c4 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -1372,13 +1372,17 @@ impl Component for EditorView { Event::Mouse(event) => self.handle_mouse_event(event, &mut cx), Event::IdleTimeout => self.handle_idle_timeout(&mut cx), - Event::FocusGained => EventResult::Ignored(None), + Event::FocusGained => { + context.editor.focused_in_terminal = true; + EventResult::Consumed(None) + } Event::FocusLost => { if context.editor.config().auto_save { if let Err(e) = commands::typed::write_all_impl(context, false, false) { context.editor.set_error(format!("{}", e)); } } + context.editor.focused_in_terminal = false; EventResult::Consumed(None) } } diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index 66542e898e23..e3db59d883f2 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -929,6 +929,7 @@ pub struct Editor { /// The `RwLock` blocks the editor from performing the render until an exclusive lock can be acquired pub redraw_handle: RedrawHandle, pub needs_redraw: bool, + pub focused_in_terminal: bool, /// Cached position of the cursor calculated during rendering. /// The content of `cursor_cache` is returned by `Editor::cursor` if /// set to `Some(_)`. The value will be cleared after it's used. @@ -1063,6 +1064,7 @@ impl Editor { needs_redraw: false, cursor_cache: Cell::new(None), completion_request_handle: None, + focused_in_terminal: true, } } diff --git a/helix-view/src/gutter.rs b/helix-view/src/gutter.rs index a332a8a324cc..801c256d76fe 100644 --- a/helix-view/src/gutter.rs +++ b/helix-view/src/gutter.rs @@ -176,7 +176,8 @@ pub fn line_numbers<'doc>( let relative = line_number == LineNumber::Relative && mode != Mode::Insert && is_focused - && current_line != line; + && current_line != line + && editor.focused_in_terminal; let display_num = if relative { abs_diff(current_line, line) From db9c9e22067a1a3e6f5d2533f7999347ddd189b0 Mon Sep 17 00:00:00 2001 From: woojiq Date: Tue, 15 Aug 2023 22:30:04 +0300 Subject: [PATCH 2/2] partial rebase --- helix-term/src/ui/editor.rs | 9 ++++++--- helix-view/src/editor.rs | 2 -- helix-view/src/gutter.rs | 3 +-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index 64f8868591c4..0840749f8901 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -43,6 +43,8 @@ pub struct EditorView { pub(crate) last_insert: (commands::MappableCommand, Vec), pub(crate) completion: Option, spinners: ProgressSpinners, + /// Tracks if the terminal window is focused by reaction to terminal focus events + terminal_focused: bool, } #[derive(Debug, Clone)] @@ -71,6 +73,7 @@ impl EditorView { last_insert: (commands::MappableCommand::normal_mode, Vec::new()), completion: None, spinners: ProgressSpinners::default(), + terminal_focused: true, } } @@ -171,7 +174,7 @@ impl EditorView { view, view.area, theme, - is_focused, + is_focused & self.terminal_focused, &mut line_decorations, ); } @@ -1373,7 +1376,7 @@ impl Component for EditorView { Event::Mouse(event) => self.handle_mouse_event(event, &mut cx), Event::IdleTimeout => self.handle_idle_timeout(&mut cx), Event::FocusGained => { - context.editor.focused_in_terminal = true; + self.terminal_focused = true; EventResult::Consumed(None) } Event::FocusLost => { @@ -1382,7 +1385,7 @@ impl Component for EditorView { context.editor.set_error(format!("{}", e)); } } - context.editor.focused_in_terminal = false; + self.terminal_focused = false; EventResult::Consumed(None) } } diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index e3db59d883f2..66542e898e23 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -929,7 +929,6 @@ pub struct Editor { /// The `RwLock` blocks the editor from performing the render until an exclusive lock can be acquired pub redraw_handle: RedrawHandle, pub needs_redraw: bool, - pub focused_in_terminal: bool, /// Cached position of the cursor calculated during rendering. /// The content of `cursor_cache` is returned by `Editor::cursor` if /// set to `Some(_)`. The value will be cleared after it's used. @@ -1064,7 +1063,6 @@ impl Editor { needs_redraw: false, cursor_cache: Cell::new(None), completion_request_handle: None, - focused_in_terminal: true, } } diff --git a/helix-view/src/gutter.rs b/helix-view/src/gutter.rs index 801c256d76fe..a332a8a324cc 100644 --- a/helix-view/src/gutter.rs +++ b/helix-view/src/gutter.rs @@ -176,8 +176,7 @@ pub fn line_numbers<'doc>( let relative = line_number == LineNumber::Relative && mode != Mode::Insert && is_focused - && current_line != line - && editor.focused_in_terminal; + && current_line != line; let display_num = if relative { abs_diff(current_line, line)