Skip to content

Commit

Permalink
Consume editor events when changing focus
Browse files Browse the repository at this point in the history
When changing the focused view with C-w for example, the w event was
being handled in the EditorView event handler as if it belonged to
the newly focused window.

Instead of handling the event for the newly focused window, we should
return early. We don't want the change in focus to trigger a history
checkpoint (following block) and we don't want to execute the mode
transition hooks (the block after). With some configs this can cause
a panic, for example

    keys.normal.w = ["no_op"]
    # or
    keys.normal.C-w.m = "rotate_view"

since these fall into the `unimplemented!` in the mode transition block.
  • Loading branch information
the-mikedavis committed Aug 22, 2022
1 parent 18909aa commit 638e8ba
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion helix-term/src/ui/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1142,7 +1142,8 @@ impl Component for EditorView {
// clear status
cx.editor.status_msg = None;

let doc = doc!(cx.editor);
let (view, doc) = current!(cx.editor);
let focus = view.id;
let mode = doc.mode();

if let Some(on_next_key) = self.on_next_key.take() {
Expand Down Expand Up @@ -1209,6 +1210,12 @@ impl Component for EditorView {
let (view, doc) = current!(cx.editor);
view.ensure_cursor_in_view(doc, config.scrolloff);

// The focused view has changed. Consume the event and do not execute mode
// transition hooks.
if view.id != focus {
return EventResult::Consumed(None);
}

// Store a history state if not in insert mode. This also takes care of
// committing changes when leaving insert mode.
if doc.mode() != Mode::Insert {
Expand Down

0 comments on commit 638e8ba

Please sign in to comment.