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

Fix supertab freezing the app #6965

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 3 additions & 21 deletions ts/services/addGlobalKeyboardShortcuts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export function addGlobalKeyboardShortcuts(): void {
return;
}

// Super tab :)
// Super tab :(
Copy link
Author

Choose a reason for hiding this comment

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

Signal Spirits haunt this codebase. Let the frown scare them away.

if (
(commandOrCtrl && key === 'F6') ||
(commandOrCtrl && !shiftKey && (key === 't' || key === 'T'))
Expand All @@ -55,10 +55,7 @@ export function addGlobalKeyboardShortcuts(): void {
const focusedIndexes: Array<number> = [];

targets.forEach((target, index) => {
if (
(focusedElement != null && target === focusedElement) ||
target.contains(focusedElement)
) {
if (target.contains(focusedElement)) {
Copy link
Author

Choose a reason for hiding this comment

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

target.contains(focusedElement) makes the preceding condition pointless because .contains() allows a null parameter and considers elements to also contain themselves.

focusedIndexes.push(index);
}
});
Expand All @@ -75,22 +72,7 @@ export function addGlobalKeyboardShortcuts(): void {
// elements match (generally going to be a parent element)
const focusedIndex = focusedIndexes.at(-1) ?? -1;

const lastIndex = targets.length - 1;
const increment = shiftKey ? -1 : 1;

let index;
if (focusedIndex < 0 || focusedIndex >= lastIndex) {
index = 0;
} else {
index = focusedIndex + increment;
}

while (!targets[index]) {
index += increment;
if (index > lastIndex || index < 0) {
index = 0;
}
}
const index = (focusedIndex + 1) % targets.length;
Copy link
Author

Choose a reason for hiding this comment

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

I removed shiftKey handling because it's disabled for Ctrl+T as Ctrl+Shift+T is the shortcut for focusing the composer field. Ctrl+Shift+F6 would still be possible if you think users would suddenly start caring about that shortcut, since it's been broken for a long time without anyone noticing.

Suggested change
const index = (focusedIndex + 1) % targets.length;
const lastIndex = targets.length - 1;
let index;
if (focusedIndex < 0) {
index = shiftKey ? lastIndex : 0;
} else {
const increment = shiftKey ? lastIndex : 1;
index = (focusedIndex + increment) % targets.length;
}


const node = targets[index];
const firstFocusableElement = matchOrQueryFocusable(node);
Expand Down