question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Configurable keyboard shortcuts

See original GitHub issue

All the keyboard shortcuts are listed in the DefaultContainer component. I could see how people would want to use their own keybindings.

Something like:

{
  "a": "createLeaf",
  "shift+a": "createInternal"
  "space": "activate",
  "meta+DownArrow": "activate"
}

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
jameskerrcommented, Nov 29, 2022

@holloway I want to break up that giant onKeyDown event listener found in DefaultContainer. Each of those cases should be a named function with the TreeApi as the only argument. All of those could go in their own file called commands.ts.

The commands should be put in an object; the key is the name, the value is function.

Another object will map a keybinding string to the string name of the command function. A user could then configure this by passing their own object.

Then in the DefaultContainer#onKeyDown handler, we have some logic that turns that event into a keybinding string. We could follow VSCode’s example for how to structure the string (Shift+ArrowDown) for example. Then we run whatever command is mapped to that keybinding string using the object above.

I’m wondering if we want to only make a few of the keybindings available for customization. For example, “ArrowDown” should probably not be configurable. But “Space” should be.

Something Like

<DefaultContainer
  onKeyDown={(e) => {
    const keybinding = toKeyBinding(e)
    tree.runCommandAt(keybinding)
  }}
/>

class TreeApi() {
  runCommandAt(key: string) {
    const commandName = this.keybindings[key]
    const command = this.commands[commandName]
    if (command) command(this)
  }
}

1reaction
hilmanauzcommented, Nov 29, 2022

it works for me @jameskerr, thanks for your advice. I forgot there’s an onKeyDown prop in every element.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Customize keyboard shortcuts - Microsoft Support
You can customize keyboard shortcuts (or shortcut keys) by assigning them to a command, macro, font, style, or frequently used symbol.
Read more >
How to Create Custom Keyboard Shortcuts in Windows
Right-click the desired icon · At the bottom of the drop-down menu, above “unpin”, right-click the name of the program. · Left-click “properties”...
Read more >
Configurable Keyboard Shortcuts - Exposure Software
Customize keyboard shortcuts in Exposure's preferences. Either use the menu, or press Cmd on the Mac, and Ctrl on Windows. In the Preferences...
Read more >
Set keyboard shortcuts
Set keyboard shortcuts · Open the Activities overview and start typing Settings. · Click on Settings. · Click Keyboard Shortcuts in the sidebar...
Read more >
Configure keyboard shortcuts | PyCharm Documentation
On the Keymap page of the Settings/Preferences dialog Ctrl+Alt+S , right-click an action and select Add Keyboard Shortcut. · In the Keyboard ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found