feat(translate): add custom shortcut combo support for node translation#1722
feat(translate): add custom shortcut combo support for node translation#1722old9 wants to merge 3 commits into
Conversation
Allow users to set arbitrary modifier+key shortcut combos (Alt+T, Ctrl+Shift+D, etc.) for hover paragraph translation instead of being limited to single modifier keys (control/alt/shift) or backtick, which all cause accidental triggers. - Add 'custom' to HOTKEYS enum with customShortcut string field in config schema - Add frozen migration v079->v080 to append customShortcut: "" to existing configs - Reuse ShortcutKeyRecorder + page-translation-shortcut utilities for combo validation - Match combos on keydown (guarded by event.repeat) in the node translation trigger - Show ShortcutKeyRecorder in Options when hotkey is 'custom' - Display current combo in popup hotkey selector - Add i18n for custom hotkey in all 9 locales
π¦ Changeset detectedLatest commit: 9ed8a60 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Contributor trust score21/100 β New contributor This score estimates contributor familiarity with Outcome
Score breakdown
Signals used
Policy
Updated automatically when the PR changes or when a maintainer reruns the workflow. |
There was a problem hiding this comment.
π‘ Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: efaeed760a
βΉοΈ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with π.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| if (!event.repeat && matchesNodeCustomShortcut(event, config.translate.node.customShortcut)) { | ||
| triggerNodeTranslation(resolveTriggerPoint(), config) |
There was a problem hiding this comment.
Consume matched custom shortcut events
When a user configures a custom node shortcut that is also handled by the page/browser or another Read Frog hotkey, such as Ctrl+F or the selection-toolbar default Alt+T, this branch triggers node translation but then returns without consuming the keydown. The default action and other listeners can still run, so one key press can both translate the hovered node and open/run the other shortcut; consume the event after a successful match or route this through the shared hotkey manager.
Useful? React with πΒ / π.
There was a problem hiding this comment.
Fixed the event-consumption part by preventing matched custom shortcut events from continuing to page/browser handlers.
I kept the broader hotkey conflict behavior out of scope here. Existing page translation and selection toolbar shortcuts can already conflict with each other in the same way, so resolving cross-feature shortcut ownership should be handled in a separate PR, likely through the shared hotkey manager.
β¦-firing - Use initialConfig cache + storage watch for synchronous event consumption - Call preventDefault/stopPropagation/stopImmediatePropagation on matched custom shortcuts - Add tests for event consumption and config watcher cache refresh
There was a problem hiding this comment.
π‘ Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a2815c5391
βΉοΈ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with π.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| const didConsumeCustomShortcut = !shouldIgnoreEvent() | ||
| && !isEditableTarget(event.target) | ||
| && matchesCurrentNodeCustomShortcut(event, cachedConfig) |
There was a problem hiding this comment.
Refresh stale shortcut cache before consuming
When this tab misses storage.watch while frozen/inactive, cachedConfig can still contain the old enabled custom shortcut even though the later async getConfig() read would return the updated setting. Because this check consumes the keydown before that refresh, a disabled or changed custom shortcut can still block page/browser shortcuts once (for example the old Ctrl+F) or fail to consume the newly configured combo on its first press after returning to the tab.
Useful? React with πΒ / π.
Type of Changes
Description
Allow users to set arbitrary modifier+key shortcut combos (Alt+T, Ctrl+Shift+D,
etc.) for hover paragraph translation instead of being limited to single modifier
keys (control/option/shift), which all cause accidental triggers.
"custom"to HOTKEYS enum withcustomShortcutstring field in config schemacustomShortcut: ""to existing configsShortcutKeyRecorder+ page-translation-shortcut utilities for combo validationkeydown(guarded byevent.repeat) in the node translation triggerShortcutKeyRecorderin Options when hotkey is"custom"Related Issue
None β feature request from personal use.
How Has This Been Tested?
Added unit tests
Verified through manual testing
SKIP_FREE_API=true pnpm testβ 162 test files passed, 1376 tests passed, 1 skipped (free-api)pnpm lintβ 0 errorspnpm type-checkβ 0 errorsMigration auto-test (
all-migrations.test.ts) validates v079βv080 with 4 test seriesBuilt for Chrome and Firefox, loaded in Firefox as temporary extension, confirmed custom combo triggers paragraph translation
Checklist
Additional Information
The
ShortcutKeyRecordercomponent and combo validation utilities were already in the codebase for the page-translation-shortcut feature β this PR reuses them for node translation as well.