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

feat(frontend/settings): add customisable hotkeys #548

Merged
merged 22 commits into from
Oct 26, 2020

Conversation

Harjot1Singh
Copy link
Member

@Harjot1Singh Harjot1Singh commented May 23, 2020

Subject

Adds customisable hotkeys

Changes

I found the thread below hard to work against, so I've consolidated it here:

Linked issues

Closes #176, Closes #426

Before

N/A

After

6228c41f-ece6-401e-9347-046a5a24291c

Tests

  • Shift + any key as a modifier => deliberately ignores
  • Modifiers only => deliberately ignores
  • Maps to cmd on Mac
  • Required hotkeys are not removable or corrupted

TTR

At least 30 hours? Most time spent was not due to complexity of feature, but resolving 3rd party lib bugs.

Reviewers

@bhajneet

@bhajneet
Copy link
Member

bhajneet commented May 24, 2020

I cannot use the following hotkey combos:

  • ctrl w (closes window)
  • ctrl r (refreshes window)
  • ctrl m (minimizes window)

The following can be used but are already hotkeys:

  • ctrl a (selects all text)
  • ctrl - (minus text size)
  • ctrl shift = (plus text size)
  • ctrl 0 (resets zoom)

The following are reserved/taken, but don't work as intended perhaps:

  • ctrl q (does not quit app in settings window, does work in other windows -- btw this is a bit too easy to hit, no? perhaps it should be ctrl shift q)
  • ctrl g (goes to search when there is no history/navigator available, instead it should do nothing, reproduce by going to bookmarks and typing ctrl g on fresh open of shabad os)
  • ctrl , and ctrl p open new settings windows. I'm not sure there is a use case for multiple settings windows as there is for multiple controllers

The following are hotkeys I don't think need to be set:

  • ctrl shift x (duplicate of ctrl x)
  • ctrl shift h (duplicate of ctrl h)

I'm guessing some of these are because of dev. In the off chance they are not: Reserve all the hotkeys in first two lists and don't allow deletion of them or for them to be assigned elsewhere.

I cannot test mac, but I'm curious how some of these work with their hotkeys. I think cmd h is used to hide windows, what do we do to hide the controller vs hide the app on macOS?

EDIT:

Also note I can set some of these hotkeys as parts of sequence:
image

(This did not toggle fullscreen)

@bhajneet
Copy link
Member

Hotkey recording broken after shift+f (no actual hotkey after that is recorded). Better would be to tell the user yes, you typed shift+f but we don't allow that. ("Taken by reserved hotkeys list" or something).

@bhajneet
Copy link
Member

Lol:
image
This sequence actually worked, however it also triggered all the "jump to" hotkeys in the navigator for longer shabads...

Perhaps all sequences should require safe modifiers? Ctrl+C Ctrl+D Ctrl+K etc. Note this sequence also takes me to history and copies it from there:
image

@bhajneet
Copy link
Member

Reserve highly considered "safe" hotkeys like up and down arrow keys, space for autoselect, enter / return to select line. These are very critical to reserve. I would argue reserving b, page up, page down, esc, ctrl+shift+b are also key for using presenter/projector remotes.

Though I'm impressed this didn't break search much:
image

@bhajneet
Copy link
Member

Ctrl+X, Ctrl+H shows blank screen even if line is activated. Clicking on blank area will advance line. I think there might be an out-of-scope issue open for this. Need to check before creating an issue out of this comment.

@bhajneet
Copy link
Member

Side note, I cannot copy with the pop over, but the hotkey works for all lines haha:
image

@bhajneet
Copy link
Member

The second one will not work after the first one:
image
Ctrl Shift A is broken. Until I unfocus and refocus entire electron window. Happens with other Ctrl Shift hotkeys as well.

This doesn't happen with ctrl+shift+b for esc (reserved)

@bhajneet
Copy link
Member

I shouldn't be allowed to re-use a reserved hotkey... Wonder what will happen!
image

(It just escapes the screen, it doesn't quit the app haha)

@saihaj
Copy link
Member

saihaj commented May 24, 2020

Side note, I cannot copy with the pop over, but the hotkey works for all lines haha:
image

That is because it is a Bani and #500 will make it happen

@AkalUstat
Copy link
Contributor

AkalUstat commented May 24, 2020

btw @Harjot1Singh react-hotkeys has problems with hotkeys that begin with alt/option

source: my work on sttm-web shortcuts

@Harjot1Singh
Copy link
Member Author

Harjot1Singh commented Jul 11, 2020

I cannot use the following hotkey combos:

  • ctrl w (closes window)
  • ctrl r (refreshes window)
  • ctrl m (minimizes window)

The following can be used but are already hotkeys:

  • ctrl a (selects all text)
  • ctrl - (minus text size)
  • ctrl shift = (plus text size)
  • ctrl 0 (resets zoom)

These all are dev-only, except ctrl-a. Would you like to disable these anyway, since they apply in the browser?

ctrl shift h (duplicate of ctrl h)

This exists purely because in-browser, ctrl-h => history.

@Harjot1Singh
Copy link
Member Author

Ctrl+X, Ctrl+H shows blank screen even if line is activated. Clicking on blank area will advance line. I think there might be an out-of-scope issue open for this. Need to check before creating an issue out of this comment.

Not sure I can see what's going on here, appears to work for me.

@bhajneet
Copy link
Member

...
These all are dev-only, except ctrl-a. Would you like to disable these anyway, since they apply in the browser?

I think it would be nice to use zoom in and out in prod as well, have had a couple people ask about changing font sizes for navigator

ctrl shift h (duplicate of ctrl h)

This exists purely because in-browser, ctrl-h => history.

Okay, no worries on this

@bhajneet
Copy link
Member

Ctrl+X, Ctrl+H shows blank screen even if line is activated. Clicking on blank area will advance line. I think there might be an out-of-scope issue open for this. Need to check before creating an issue out of this comment.

Not sure I can see what's going on here, appears to work for me.

See here for example (notice the background)

new controller issue

@Harjot1Singh
Copy link
Member Author

Side note, I cannot copy with the pop over, but the hotkey works for all lines haha:
image

Seems to work for me btw, unless I misunderstood how to reproduce.

@saihaj
Copy link
Member

saihaj commented Jul 13, 2020

Seems to work for me btw, unless I misunderstood how to reproduce.

I think he meant that you can copy with hotkeys but you cannot press the copy button in popover. Don’t worry about this (we have separate issue in tracker)

@lgtm-com
Copy link

lgtm-com bot commented Jul 13, 2020

This pull request introduces 2 alerts when merging 3dca681 into 792fc77 - view on LGTM.com

new alerts:

  • 1 for Duplicate property
  • 1 for Unused variable, import, function or class

@bhajneet
Copy link
Member

bhajneet commented Jul 13, 2020

Prevent unusable hotkeys from being assigned

This is still incorrect. Go to the "open a new controller" hotkey, and assign a new one as Ctrl+F and it will say this is already assigned. However, because you can combo hotkeys, I can then do Ctrl+C (total hotkey chord becomes Ctrl+F, Ctrl+C) and this is allowed. Now in usage, if I do Ctrl+F it will fullscreen the window and then if I do Ctrl+C afterwards it opens a new controller.

This also causes lots of issues:
image

If a hotkey is being used as part of a chord, it must be used only as part of a chord. If a hotkey is used at the end of a chord or as a singular hotkey command, it cannot be used as part of a chord

Put another way:

  • Chord hotkeys cannot be hotkeys in and of themselves, they can only be used as part of a trigger / sequence to an end hotkey combo
  • The last key combo in a sequence or a single combo used as a hotkey cannot be used anywhere else, and definitely not as part of a sequence/chord.

Reserve "highly safe" hotkeys

Enter and Return are highly safe hotkeys, lol

Disable shift-f or even any shift-solo keys

What about this? I removed the hotkey and now I cannot re-assign it.

image

@bhajneet
Copy link
Member

Also being able to assign these hotkeys on their own will mess with navigator (I assume)

image

@Harjot1Singh
Copy link
Member Author

Sequenced hotkeys appear to muck up shorter sequences: greena13/react-hotkeys#219 and greena13/react-hotkeys#255.

Resolving.

@Harjot1Singh
Copy link
Member Author

tntmarket/roam-toolkit#2 is a great reference to resolve many of the issues we are also having

@Harjot1Singh
Copy link
Member Author

1 semi-serious limitation/bug remaining - if you carry on holding a modifier key after a hotkey has completed, it will not work again unless you focus away and back. Will try to resolve.

@bhajneet bhajneet removed their request for review October 19, 2020 12:32
@bhajneet
Copy link
Member

For notification purposes, I've removed myself from review until you're finished with the remaining fixes

@Harjot1Singh
Copy link
Member Author

@bhajneet

Prevent unusable hotkeys from being assigned

This is still incorrect. Go to the "open a new controller" hotkey, and assign a new one as Ctrl+F and it will say this is already assigned. However, because you can combo hotkeys, I can then do Ctrl+C (total hotkey chord becomes Ctrl+F, Ctrl+C) and this is allowed. Now in usage, if I do Ctrl+F it will fullscreen the window and then if I do Ctrl+C afterwards it opens a new controller.

This also causes lots of issues:
image

If a hotkey is being used as part of a chord, it must be used only as part of a chord. If a hotkey is used at the end of a chord or as a singular hotkey command, it cannot be used as part of a chord

Put another way:

  • Chord hotkeys cannot be hotkeys in and of themselves, they can only be used as part of a trigger / sequence to an end hotkey combo
  • The last key combo in a sequence or a single combo used as a hotkey cannot be used anywhere else, and definitely not as part of a sequence/chord.

Why not just prevent starting sequences being reused?

Case 1:

Action 1: ctrl+c g
Adding Action 2: ctrl+c <= Unassignable, since ctrl+c matches action 1 already

Case 2:

Action 1: ctrl+c g
Adding Action 2: g <= Ok, since does not match any sequence from the beginning. Keys also will not conflict, since if ctrl+c has been pressed, will wait for g or any other key and not trigger action 2.

Case 3:

Action 1: ctrl+a ctrl+c
Adding Action 2: ctrl+a ctrl+c d e f g <= fails, since we have a matching starting sequeunce
Adding Action 3: ctrl+c ctrl+a ctrl+c <= ok, since action 3 is not a subsequence from the beginning of any previous hotkeys
Adding Action 4: ctrl+a <= fails, since a subsequence of action 1

This way, no conflicts could ever happen, and it's logical/intuitive. What do you think?

Disable shift-f or even any shift-solo keys

What about this? I removed the hotkey and now I cannot re-assign it.

image

Did you want to reassign these mappings?

@bhajneet
Copy link
Member

Why not just prevent starting sequences being reused?

The logic is sound, go for it

Did you want to reassign these mappings?

I want them to be locked/permanent (non-removable), so then a user will not be in a situation where they are unable to "fix" them since shift keys are not allowed (afaicr)

Clears key history after a successful sequence using react-hotkeys internals.

Refactors GlobalHotKeys into local component
Copy link
Member

@bhajneet bhajneet left a comment

Choose a reason for hiding this comment

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

Congratulations ㊗️

Please file an issue to fix ctrlDown, hotkey, hotkey, ctrlUp only triggering once

Otherwise LGTM

🚀 Can squash and merge! :shipit:

@Harjot1Singh Harjot1Singh merged commit 57958bd into shabados:dev Oct 26, 2020
@Harjot1Singh Harjot1Singh deleted the 176-customisable-hotkeys branch October 26, 2020 02:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement non-deletable hotkeys and addable hotkeys for certain hotkey functions Customisable hotkeys
4 participants