Skip to content

Keyboard shortcut "control + tab" broken on macOS. #122084

@fdennis

Description

@fdennis

Steps to Reproduce

  1. Create a control + tab keyboard shortcut with LogicalKeySet and/or SingleActivator on macOS. See code sample for an example.
  2. Notice that nothing happens when the keys are pressed.
  3. Try other combinations and note that they work, such as tab + shift.
  4. Remove the comment around the TextField in the sample.
  5. Move to to the TextField, for example with arrow keys or tab.
  6. Now try the shortcuts again. This time control + tab works. But as soon as you move away from the TextField it stops working.

In the code sample I have demonstrated this behavior with both SingleActivator and LogicalKeyset.

This works as expected on Windows. The shortcut ctrl + tab works everywhere. For some reason there is an issue on macOS.

Expected results:
That I can create a keyboard shortcut for control + tab everywhere, not just in a textfield, for macOS.

Actual results:
I cannot create a proper keyboard shortcut for control + tab (on macOS), but for some reason it works when I am in a textfield. I can create a shortcut for many other combinations containing the tab key, for example tab + shift. This is demonstrated in the sample code.

Code sample
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

void main() {
  runApp(const MyApp());
}

class ActivatorIntent extends Intent {
  const ActivatorIntent();
}

class KeySetIntent extends Intent {
  const KeySetIntent();
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text(widget.title),
        ),
        body: Shortcuts(
            shortcuts: {
              SingleActivator(LogicalKeyboardKey.tab, control: true):
                  ActivatorIntent(),
              SingleActivator(LogicalKeyboardKey.tab, shift: true):
                  ActivatorIntent(),
              /*LogicalKeySet(LogicalKeyboardKey.tab, LogicalKeyboardKey.control):
                  KeySetIntent(),
              LogicalKeySet(LogicalKeyboardKey.tab, LogicalKeyboardKey.shift):
                  KeySetIntent(),*/
            },
            child: Actions(
              actions: {
                ActivatorIntent: CallbackAction<ActivatorIntent>(onInvoke: (_) {
                  debugPrint('ActivatorIntent shortcut activated');
                  return null;
                }),
                KeySetIntent: CallbackAction<KeySetIntent>(onInvoke: (_) {
                  debugPrint('KeySetIntent shortcut activated');
                  return null;
                })
              },
              child: Center(
                child: Padding(
                  padding: const EdgeInsets.symmetric(horizontal: 18.0),
                  child: Column(
                    children: [
                      ElevatedButton(
                        onPressed: () {
                          debugPrint('a');
                        },
                        child: const Text('Button 1'),
                      ),
                      //TextField(),
                      ElevatedButton(
                        onPressed: () {
                          debugPrint('b');
                        },
                        child: const Text('Button 2'),
                      ),
                    ],
                  ),
                ),
              ),
            )));
  }
}

Logs

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work lista: desktopRunning on desktopengineflutter/engine related. See also e: labels.f: focusFocus traversal, gaining or losing focusfound in release: 3.7Found to occur in 3.7found in release: 3.9Found to occur in 3.9has reproducible stepsThe issue has been confirmed reproducible and is ready to work onplatform-macBuilding on or for macOS specificallyr: fixedIssue is closed as already fixed in a newer version

Type

No type

Projects

Status

Done (PR merged)

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions