Keys: release a held modifier the browser says is up

After Ctrl+A switched Pipelines/Runs, Alt+K sometimes did nothing while
Ctrl+K worked: the framework still held Ctrl from a lost release, so Alt+K
read as Ctrl+Alt+K. Each key event's own modifier flags now release any
modifier the framework holds that the browser reports up.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-02 14:27:38 +00:00
parent 1be33c0d46
commit 3e817a189b
2 changed files with 38 additions and 0 deletions
@@ -126,6 +126,14 @@ class KeyModifierSync {
_released[key] = logical;
_lift(key, logical, data.timeStamp);
changed = true;
} else if (!modifier.flag(flags)) {
// The event says this modifier is up, yet the framework still
// holds it: its release was lost (a chord ended while the page
// moved, a key event the engine never saw). Left held, it turns
// the next Alt+K into Ctrl+Alt+K and no shortcut matches. The
// event's own flags are the truth, so release it for good.
final logical = _keyboard.lookUpLayout(key);
if (logical != null) _lift(key, logical, data.timeStamp);
}
}
}
@@ -207,6 +207,36 @@ void main() {
});
});
test('a real Ctrl whose release was lost is let go by the next key '
'that says Ctrl is up, so Alt+K stays Alt+K', () {
final h = SyncHarness();
final ctrl = (
PhysicalKeyboardKey.controlLeft,
LogicalKeyboardKey.controlLeft,
);
final alt = (PhysicalKeyboardKey.altLeft, LogicalKeyboardKey.altLeft);
final k = (PhysicalKeyboardKey.keyK, LogicalKeyboardKey.keyK);
// Ctrl+A, then Ctrl's release never reaches the framework.
h.send(_key(_down, ctrl), _ctrl);
h.send(
_key(_down, (PhysicalKeyboardKey.keyA, LogicalKeyboardKey.keyA)),
_ctrl,
);
h.send(
_key(_up, (PhysicalKeyboardKey.keyA, LogicalKeyboardKey.keyA)),
_ctrl,
);
expect(h.pressed.keys, contains(PhysicalKeyboardKey.controlLeft));
// Alt+K: the event's flags hold Alt only.
const altOnly = KeyEventModifiers(alt: true);
h.send(_key(_down, alt), altOnly);
h.send(_key(_down, k), altOnly);
expect(h.pressed.keys, {
PhysicalKeyboardKey.altLeft,
PhysicalKeyboardKey.keyK,
});
});
test('unknown flags leave the event alone', () {
final h = SyncHarness();
h.send(_key(_down, _c));