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

[Hotkeys] Hide hotkeys dialog on 'shift + ?' keypress #1301

Merged
merged 5 commits into from
Jul 27, 2017
Merged

Conversation

cmslewis
Copy link
Contributor

Fixes #1238

Checklist

  • Include tests (couldn't write a passing test for the life of me) :/

Changes proposed in this pull request:

If the hotkeys dialog is visible, close it when shift + ? is pressed. That hotkey now acts as a toggle.

@blueprint-bot
Copy link

Hide dialog after delay on 'shift + ?' press

Preview: documentation
Coverage: core | datetime

@llorca
Copy link
Contributor

llorca commented Jun 29, 2017

@cmslewis this is working so nicely, thanks taking care of this 🏆

@@ -30,7 +30,8 @@ class HotkeysDialog {
private container: HTMLElement;
private hotkeysQueue = [] as IHotkeyProps[][];
private isDialogShowing = false;
private timeoutToken = 0;
private showTimeoutToken = 0;
private hideTimeoutToken = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

feels more accurate to declare these as number rather than initialize to a likely invalid ID (although clearTimeout happily ignores invalid IDs)

return;
}

const combo = getKeyCombo(e);

if (comboMatches(parseKeyCombo(SHOW_DIALOG_KEY), combo)) {
showHotkeysDialog(this.actions.map((action) => action.props));
if (isHotkeysDialogShowing()) {
hideHotkeysDialogAfterDelay();
Copy link
Contributor

Choose a reason for hiding this comment

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

why is the delay necessary here? what's wrong with simply hideHotkeysDialog?

Copy link
Contributor Author

@cmslewis cmslewis Jul 10, 2017

Choose a reason for hiding this comment

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

Because a bunch of disjoint hotkey keydown listeners will fire in succession. If you synchronously call hideHotkeysDialog in any one of them, then immediate successive calls to isHotkeysDialogShowing would return false, causing the hotkeys dialog to reopen (because the same hotkey that opens that dialog is now overloaded to close it too).

Introducing a small delay is the only way to guarantee all those keydown listeners execute before the dialog actually gets hidden.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a comment.

@blueprint-bot
Copy link

Respond to CR feedback

Preview: documentation | table
Coverage: core | datetime

@cmslewis
Copy link
Contributor Author

@giladgray can you take another look at this so we can get it merged?

@blueprint-bot
Copy link

Fix build

Preview: documentation | table
Coverage: core | datetime

/**
* Since one hotkey toggles the dialog open and closed, we need to
* introduce a delay to ensure that all hotkey listeners fire with the
* dialog in a consistent state.
Copy link
Contributor

Choose a reason for hiding this comment

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

this is not a /** */ doc comment; it's a code comment explaining why we must do it this way. i'd move it inside the function body and use //.

Copy link
Contributor

Choose a reason for hiding this comment

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

could also just edit this text so it's useful to a consumer, to explain why you'd want to call this function instead of regular hide().

@blueprint-bot
Copy link

Move function comment

Preview: documentation | table
Coverage: core | datetime

@cmslewis cmslewis merged commit 842db8f into master Jul 27, 2017
@cmslewis cmslewis deleted the cl/hotkeys-1238 branch July 27, 2017 00:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants