Expose normalized bindings on keydownHandler fn #9

Closed
sch wants to merge 1 commit from expose-normalized-keybindings into master
sch commented 2026-01-29 02:27:00 +01:00 (Migrated from github.com)

I'd like to support two use cases that are made easier by having access to the normalized key bindings:

  • Conditionally rendering editor toolbar buttons based on what plugins are enabled
  • Dynamically generating a "keyboard shortcuts" help page and button tooltips using that platform's keyboard conventions

With this change, I can loop over my editor's plugins and build the platform-specific version of the keyboard shortcut from the props.handleKeyDown function itself.

I'd like to support two use cases that are made easier by having access to the normalized key bindings: - Conditionally rendering editor toolbar buttons based on what plugins are enabled - Dynamically generating a "keyboard shortcuts" help page and button tooltips using that platform's keyboard conventions With this change, I can loop over my editor's plugins and build the platform-specific version of the keyboard shortcut from the `props.handleKeyDown` function itself.
marijnh commented 2026-01-29 08:49:45 +01:00 (Migrated from github.com)

Sorry, but I don't like this at all. It seems too specific to a use case, and too surprising in terms of interface design. I think your best bet for doing what you want is to either ensure your key bindings are pre-normalized, or define your own normalization function to map bindings to whatever you want the user-readable strings to look like—this could be a one-line regexp replace.

Sorry, but I don't like this at all. It seems too specific to a use case, and too surprising in terms of interface design. I think your best bet for doing what you want is to either ensure your key bindings are pre-normalized, or define your own normalization function to map bindings to whatever you want the user-readable strings to look like—this could be a one-line regexp replace.
sch commented 2026-01-29 13:51:57 +01:00 (Migrated from github.com)

Fair enough. Would you accept a PR that exposes the normalizeKeys function and the inner function in keydownHandler, so people can build this functionality in userland? Or are you thinking you don’t want to be tied down to supporting that in the public interface forever?

Fair enough. Would you accept a PR that exposes the `normalizeKeys` function and the inner function in `keydownHandler`, so people can build this functionality in userland? Or are you thinking you don’t want to be tied down to supporting that in the public interface forever?
marijnh commented 2026-01-29 14:05:26 +01:00 (Migrated from github.com)

The normalized format is an internal thing. I'm suggesting you write your own—it's simple enough, and that way you have actual control over the way you present the key names.

The normalized format is an internal thing. I'm suggesting you write your own—it's simple enough, and that way you have actual control over the way you present the key names.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
prosemirror/prosemirror-keymap!9
No description provided.