Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: line numbers remain relative when helix loses focus #7955

Merged
merged 2 commits into from
Aug 29, 2023
Merged
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
11 changes: 9 additions & 2 deletions helix-term/src/ui/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ pub struct EditorView {
pub(crate) last_insert: (commands::MappableCommand, Vec<InsertEvent>),
pub(crate) completion: Option<Completion>,
spinners: ProgressSpinners,
/// Tracks if the terminal window is focused by reaction to terminal focus events
terminal_focused: bool,
}

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -71,6 +73,7 @@ impl EditorView {
last_insert: (commands::MappableCommand::normal_mode, Vec::new()),
completion: None,
spinners: ProgressSpinners::default(),
terminal_focused: true,
}
}

Expand Down Expand Up @@ -171,7 +174,7 @@ impl EditorView {
view,
view.area,
theme,
is_focused,
is_focused & self.terminal_focused,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The use of a single & here is a little confusing. Wouldn't it have been better to just use && here for clarity?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's already merged, I'm not going to create a PR for this small change.
Anyway, it is not difficult to learn bitwise operators and improve your programming knowledge a little.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's just no reason to add complexity by making this a bit-wise operation rather than a logical AND operation, especially in an open source project with this many moving pieces. I didn't expect a PR be made for this small change, was just pointing it out.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bitwise operation on bool is no less clearer than a logical operation. I prefer the code as is.

&mut line_decorations,
);
}
Expand Down Expand Up @@ -1372,13 +1375,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 => {
self.terminal_focused = 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));
}
}
self.terminal_focused = false;
EventResult::Consumed(None)
}
}
Expand Down