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

Use the current document and view for mode-change hooks #3508

Merged

Conversation

the-mikedavis
Copy link
Member

@the-mikedavis the-mikedavis commented Aug 22, 2022

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.

Instead of handling the event in the newly focused view, we should handle
the event in the original view.

@archseer
Copy link
Member

I've pushed e4c9d40 but I think this PR should be applied as well.

Comment on lines 1213 to 1217
// The focused view has changed. Consume the event and do not execute mode
// transition hooks.
if view.id != focus {
return EventResult::Consumed(None);
}
Copy link
Member

Choose a reason for hiding this comment

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

Actually, with the changes in master, these hooks should still run (if the doc exited from insert mode, we do want a history state).

We just need to fetch the doc matching the original focus rather than current!

When changing focus, the lookup with `current!` may change the
view and end up executing mode transition hooks on the newly
focused view. We should use the same view and document to execute
mode transition hooks so that switching away from a view triggers
history save points.
@the-mikedavis the-mikedavis removed this from the 22.08 milestone Aug 23, 2022
@the-mikedavis the-mikedavis changed the title Consume editor events when changing focus Use the current document and view for mode-change hooks Aug 23, 2022
@archseer archseer merged commit 9e24f2a into helix-editor:master Aug 31, 2022
@the-mikedavis the-mikedavis deleted the md-consume-focus-transitions branch August 31, 2022 01:35
thomasskk pushed a commit to thomasskk/helix that referenced this pull request Sep 9, 2022
…ditor#3508)

When changing focus, the lookup with `current!` may change the
view and end up executing mode transition hooks on the newly
focused view. We should use the same view and document to execute
mode transition hooks so that switching away from a view triggers
history save points.
jdrst pushed a commit to jdrst/helix that referenced this pull request Sep 13, 2022
…ditor#3508)

When changing focus, the lookup with `current!` may change the
view and end up executing mode transition hooks on the newly
focused view. We should use the same view and document to execute
mode transition hooks so that switching away from a view triggers
history save points.
herkhinah pushed a commit to herkhinah/helix that referenced this pull request Dec 11, 2022
…ditor#3508)

When changing focus, the lookup with `current!` may change the
view and end up executing mode transition hooks on the newly
focused view. We should use the same view and document to execute
mode transition hooks so that switching away from a view triggers
history save points.
pascalkuthe added a commit that referenced this pull request Jan 8, 2024
This change effectively reverts #3508 and #3633.
When a view is changed we must make history commits (and ensure that
the cursor is in view) for the newly focused view. Not the old view.

These changes were originally introduced to fix mode switch hooks.
However, the mode switch hooks have been moved elsewhere so that concern
doesn't apply anymore. In particular, because modes are now editor wide
and not per view and also because view switches now always reset the
editor back to normal mode.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants