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 improve-shortcut-help #5348

Merged
merged 4 commits into from
Feb 1, 2022
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 2 additions & 15 deletions source/features/improve-shortcut-help.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,11 @@ import onetime from 'onetime';
import features from '.';
import {isEditable} from '../helpers/dom-utils';

function splitKeys(keys: string): DocumentFragment[] {
return keys.split(' ').map(key => <> <kbd>{key}</kbd></>);
}

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>
Expand All @@ -30,18 +26,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);
Copy link
Member Author

@kidonng kidonng Jan 29, 2022

Choose a reason for hiding this comment

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

Fix #4962. The reason I "Can't replicate now" is that this feature stopped working completely as the command palette was added.

This was previously added in #1107 but it seems GitHub already separates the keys now. We just need to split ours.

observer.disconnect();
}
});
Expand All @@ -51,7 +38,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');
Copy link
Member Author

Choose a reason for hiding this comment

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

Without this it would match the command palette and stop working.

if (modal) {
observer.observe(modal, {childList: true});
}
Expand Down