Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

[macOS] Fix Ctrl+Tab is broken #40706

Merged
merged 2 commits into from
Apr 18, 2023

Conversation

bleroux
Copy link
Contributor

@bleroux bleroux commented Mar 28, 2023

Description

This PR fixes Ctrl+Tab shortcut on macOS.

From https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/EventOverview/HandlingKeyEvents/HandlingKeyEvents.html#//apple_ref/doc/uid/10000060i-CH7-SW11, some key events, such as Ctrl+Tab, are notified by calling performKeyEvent: instead of keyDown:.

The text input plugin already implement this method, this is why the shortcut works only when there is a TextField (TextInputPlugin is then activated), see 'Step 6' of flutter/flutter#122084 description.

Implementation

I had to implement performKeyEvent: on FlutterViewWrapper because when adding it to FlutterView it was not called (see this similar comment related to setBackgroundColor: #36906 (comment)).

I also duplicated some code from FlutterTextInputPlugin.mm (the KeyEquivalentMarker definition) because FlutterViewWrapper.performKeyEvent: takes precedence over FlutterTextInputPlugin.performKeyEvent: so setting the marker is important to not break FlutterTextInputPlugin.handleKeyEvent:.

Related Issue

Fixes flutter/flutter#122084

Tests

Adds 1 test.

@chinmaygarde
Copy link
Member

cc @dkwingsmt @cbracken

@bleroux bleroux requested a review from cbracken April 4, 2023 05:55
@bleroux bleroux force-pushed the fix_ctrl_tab_on_macos branch 2 times, most recently from bff99f2 to e629820 Compare April 12, 2023 11:49
@chinmaygarde
Copy link
Member

cc @justinmc

Copy link
Contributor

@justinmc justinmc left a comment

Choose a reason for hiding this comment

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

LGTM 👍

I've re-run some tests that seem to be infra failures.

// responder, which might be FlutterTextInputPlugin. If that's the case, the
// plugin must not handle the event, otherwise the emoji picker would not
// work (due to first responder returning YES from performKeyEquivalent:)
// and there would be endless loop, because FlutterViewController will
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: "would be endless loop" => "would be an infinite loop"

Comment on lines +316 to +317
// When NSWindow is nextResponder, keyboard manager will send to it
// unhandled events (through [NSWindow keyDown:]). If event has both
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: "will send to it unhandled events" => "will send unhandled events to it"

@bleroux bleroux force-pushed the fix_ctrl_tab_on_macos branch from bc78b7b to e0b6fa8 Compare April 18, 2023 06:20
@bleroux bleroux added the autosubmit Merge PR when tree becomes green via auto submit App label Apr 18, 2023
@auto-submit auto-submit bot merged commit d297361 into flutter:main Apr 18, 2023
@bleroux bleroux deleted the fix_ctrl_tab_on_macos branch April 18, 2023 08:44
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Apr 18, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Apr 18, 2023
zanderso pushed a commit to flutter/flutter that referenced this pull request Apr 18, 2023
…125039)

flutter/engine@c4396f9...d297361

2023-04-18 [email protected] [macOS] Fix Ctrl+Tab is broken
(flutter/engine#40706)
2023-04-18 [email protected] Roll Fuchsia Mac SDK from
K1LGtKXyxRlW3Q9O1... to qZHSvkpAU1-YYGvYc... (flutter/engine#41293)
2023-04-18 [email protected] Roll buildroot to
059d155b4d452efd9c4427c45cddfd9445144869 (flutter/engine#41288)
2023-04-18 [email protected] [Impeller] Remove glyph pixel rounding
during text frame conversion (flutter/engine#41285)
2023-04-18 [email protected] Revert "Reland "Migrate mac_host_engine
to engine v2 builds."" (flutter/engine#41284)
2023-04-17 [email protected] focus SkiaGPUObject wrappers on only those
objects that need the protection (flutter/engine#41237)

Also rolling transitive DEPS:
  fuchsia/sdk/core/mac-amd64 from K1LGtKXyxRlW to qZHSvkpAU1-Y

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-engine-flutter-autoroll
Please CC [email protected],[email protected],[email protected] on
the revert to ensure that a human
is aware of the problem.

To file a bug in Flutter:
https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
@knopp
Copy link
Member

knopp commented May 25, 2023

Strong reference from FlutterViewWrapper to FlutterViewController creates a retain cycle.

@knopp
Copy link
Member

knopp commented Sep 17, 2023

This PR has duplicated the NSEvent (KeyEquivalentMarker) extension, including the associated object key, which is most likely wrong.

@knopp

This comment was marked as outdated.

@knopp
Copy link
Member

knopp commented Sep 17, 2023

Actually, the comment above was wrong. I assumed that if text input plugin is first responder, it will get priority over FlutterView since, they are at same depth in hierarchy, but that assumption was wrong.

@knopp knopp mentioned this pull request Sep 17, 2023
8 tasks
auto-submit bot pushed a commit that referenced this pull request Sep 28, 2023
#40706 added a duplicate `NSEvent (KeyEquivalentMarker)` category. This PR removes it. It also removes the call to `markAsKeyEquivalent` from `FlutterViewController`. That call is internal to `FlutterTextInputPlugin` and classes outside should not be calling it.

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
auto-submit bot pushed a commit that referenced this pull request Sep 28, 2023
Fixes the issue in original PR where `FlutterViewWrapper` does not pass the key equivalent to subviews thus prevents `TextInputPlugin` from receiving it. Also adds a regression test for this scenario.

Note that key equivalent flow does not respect the regular responder chain. It is passed from root view to down to subviews and if unhandled will be forwarded to menus.

Original message: 

#40706 added a duplicate `NSEvent (KeyEquivalentMarker)` category. This PR removes it. It also removes the call to `markAsKeyEquivalent` from `FlutterViewController`. That call is internal to `FlutterTextInputPlugin` and classes outside should not be calling it.

*If you had to change anything in the [flutter/tests] repo, include a link to the migration guide as per the [breaking change policy].*

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
harryterkelsen pushed a commit that referenced this pull request Oct 23, 2023
#40706 added a duplicate `NSEvent (KeyEquivalentMarker)` category. This PR removes it. It also removes the call to `markAsKeyEquivalent` from `FlutterViewController`. That call is internal to `FlutterTextInputPlugin` and classes outside should not be calling it.

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
harryterkelsen pushed a commit that referenced this pull request Oct 23, 2023
Fixes the issue in original PR where `FlutterViewWrapper` does not pass the key equivalent to subviews thus prevents `TextInputPlugin` from receiving it. Also adds a regression test for this scenario.

Note that key equivalent flow does not respect the regular responder chain. It is passed from root view to down to subviews and if unhandled will be forwarded to menus.

Original message: 

#40706 added a duplicate `NSEvent (KeyEquivalentMarker)` category. This PR removes it. It also removes the call to `markAsKeyEquivalent` from `FlutterViewController`. That call is internal to `FlutterTextInputPlugin` and classes outside should not be calling it.

*If you had to change anything in the [flutter/tests] repo, include a link to the migration guide as per the [breaking change policy].*

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects: desktop autosubmit Merge PR when tree becomes green via auto submit App platform-macos
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Keyboard shortcut "control + tab" broken on macOS.
5 participants