Skip to content

Commit

Permalink
Fix improve-shortcut-help (#5348)
Browse files Browse the repository at this point in the history
  • Loading branch information
kidonng committed Feb 1, 2022
1 parent c033722 commit ecda2dd
Showing 1 changed file with 3 additions and 12 deletions.
15 changes: 3 additions & 12 deletions source/features/improve-shortcut-help.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ function improveShortcutHelp(dialog: Element): void {
select('.Box-body .col-5 .Box:first-child', dialog)!.after(
<div className="Box Box--condensed m-4">
<div className="Box-header">
<h3 className="Box-title">Added by Refined GitHub</h3>
<h2 className="Box-title">Refined GitHub</h2>
</div>

<ul>
{[...features.shortcutMap].map(([hotkey, description]) => (
<li className="Box-row d-flex flex-row">
<div className="flex-auto">{description}</div>
<div className="ml-2 no-wrap">
<kbd>{hotkey}</kbd>
{splitKeys(hotkey)}
</div>
</li>
))}
Expand All @@ -30,18 +30,9 @@ function improveShortcutHelp(dialog: Element): void {
);
}

function fixKeys(dialog: Element): void {
for (const key of select.all('kbd', dialog)) {
if (key.textContent!.includes(' ')) {
key.replaceWith(...splitKeys(key.textContent!));
}
}
}

const observer = new MutationObserver(([{target}]) => {
if (target instanceof Element && !select.exists('.js-details-dialog-spinner', target)) {
improveShortcutHelp(target);
fixKeys(target);
observer.disconnect();
}
});
Expand All @@ -51,7 +42,7 @@ function observeShortcutModal({key, target}: KeyboardEvent): void {
return;
}

const modal = select('body > details > details-dialog');
const modal = select('body > details:not(.js-command-palette-dialog) > details-dialog');
if (modal) {
observer.observe(modal, {childList: true});
}
Expand Down

0 comments on commit ecda2dd

Please sign in to comment.