on master help sign in
fix: line numbers remain relative when helix loses focus (#7955)
b67d2c3woojiq
helix-term/src/ui/editor.rs+9−2
@@ -43,6 +43,8 @@ pub struct EditorView {
43 pub(crate) last_insert: (commands::MappableCommand, Vec<InsertEvent>),
43 pub(crate) last_insert: (commands::MappableCommand, Vec<InsertEvent>),
44 pub(crate) completion: Option<Completion>,
44 pub(crate) completion: Option<Completion>,
45 spinners: ProgressSpinners,
45 spinners: ProgressSpinners,
46+ /// Tracks if the terminal window is focused by reaction to terminal focus events
47+ terminal_focused: bool,
46}
48}
47
49
48#[derive(Debug, Clone)]
50#[derive(Debug, Clone)]
@@ -71,6 +73,7 @@ impl EditorView {
71 last_insert: (commands::MappableCommand::normal_mode, Vec::new()),
73 last_insert: (commands::MappableCommand::normal_mode, Vec::new()),
72 completion: None,
74 completion: None,
73 spinners: ProgressSpinners::default(),
75 spinners: ProgressSpinners::default(),
76+ terminal_focused: true,
74 }
77 }
75 }
78 }
76
79
@@ -171,7 +174,7 @@ impl EditorView {
171 view,
174 view,
172 view.area,
175 view.area,
173 theme,
176 theme,
174− is_focused,
177+ is_focused & self.terminal_focused,
175 &mut line_decorations,
178 &mut line_decorations,
176 );
179 );
177 }
180 }
@@ -1372,13 +1375,17 @@ impl Component for EditorView {
1372
1375
1373 Event::Mouse(event) => self.handle_mouse_event(event, &mut cx),
1376 Event::Mouse(event) => self.handle_mouse_event(event, &mut cx),
1374 Event::IdleTimeout => self.handle_idle_timeout(&mut cx),
1377 Event::IdleTimeout => self.handle_idle_timeout(&mut cx),
1375− Event::FocusGained => EventResult::Ignored(None),
1378+ Event::FocusGained => {
1379+ self.terminal_focused = true;
1380+ EventResult::Consumed(None)
1381+ }
1376 Event::FocusLost => {
1382 Event::FocusLost => {
1377 if context.editor.config().auto_save {
1383 if context.editor.config().auto_save {
1378 if let Err(e) = commands::typed::write_all_impl(context, false, false) {
1384 if let Err(e) = commands::typed::write_all_impl(context, false, false) {
1379 context.editor.set_error(format!("{}", e));
1385 context.editor.set_error(format!("{}", e));
1380 }
1386 }
1381 }
1387 }
1388+ self.terminal_focused = false;
1382 EventResult::Consumed(None)
1389 EventResult::Consumed(None)
1383 }
1390 }
1384 }
1391 }