Skip to content

feat(translate): add custom shortcut combo support for node translation#1722

Open
old9 wants to merge 3 commits into
mengxi-ream:mainfrom
old9:feat/node-translation-custom-shortcut
Open

feat(translate): add custom shortcut combo support for node translation#1722
old9 wants to merge 3 commits into
mengxi-ream:mainfrom
old9:feat/node-translation-custom-shortcut

Conversation

@old9

@old9 old9 commented Jun 20, 2026

Copy link
Copy Markdown

Type of Changes

  • ✨ New feature (feat)
  • πŸ› Bug fix (fix)
  • πŸ“ Documentation change (docs)
  • πŸ’„ UI/style change (style)
  • ♻️ Code refactoring (refactor)
  • ⚑ Performance improvement (perf)
  • βœ… Test related (test)
  • πŸ”§ Build or dependencies update (build)
  • πŸ”„ CI/CD related (ci)
  • 🌐 Internationalization (i18n)
  • 🧠 AI model related (ai)
  • πŸ”„ Revert a previous commit (revert)
  • πŸ“¦ Other changes that do not modify src or test files (chore)

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.

  • 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 (en, zh-CN, and 7 other locales)

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 errors

  • pnpm type-check β†’ 0 errors

  • Migration auto-test (all-migrations.test.ts) validates v079β†’v080 with 4 test series

  • Built for Chrome and Firefox, loaded in Firefox as temporary extension, confirmed custom combo triggers paragraph translation

Checklist

  • I have tested these changes locally
  • I have updated the documentation accordingly if necessary
  • My code follows the code style of this project
  • My changes do not break existing functionality
  • If my code was generated by AI, I have proofread and improved it as necessary.

Additional Information

The ShortcutKeyRecorder component and combo validation utilities were already in the codebase for the page-translation-shortcut feature β€” this PR reuses them for node translation as well.

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-bot

changeset-bot Bot commented Jun 20, 2026

Copy link
Copy Markdown

πŸ¦‹ Changeset detected

Latest commit: 9ed8a60

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@read-frog/extension Minor

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

@github-actions github-actions Bot added feat contrib-trust:new PR author trust score is 0-29. needs-maintainer-review Contributor trust automation recommends maintainer review. labels Jun 20, 2026
@github-actions

github-actions Bot commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

Contributor trust score

21/100 β€” New contributor

This score estimates contributor familiarity with mengxi-ream/read-frog using public GitHub signals. It is advisory only and does not block merges automatically.

Outcome

Score breakdown

Dimension Score Signals
Repo familiarity 0/35 commits in repo, merged PRs, reviews
Community standing 8/25 account age, followers, repo role
OSS influence 8/20 stars on owned non-fork repositories
PR track record 5/20 merge rate across resolved PRs in this repo

Signals used

  • Repo commits: 0 (author commits reachable from the repository default branch)
  • Repo PR history: merged 0, open 1, closed-unmerged 0
  • Repo reviews: 0
  • PR changed lines: 2217 (+2187 / -30)
  • Repo permission: read
  • Followers: 21
  • Account age: 185 months
  • Owned non-fork repos considered: max 84, total 92 (old9/ppttimer (84), old9/on-having-layout-zh-cns (8), old9/nitro_issue_demo (0))

Policy

  • Low-score review threshold: < 30
  • Auto-close: score < 20 and changed lines > 1000
  • Policy version: v1.1

Updated automatically when the PR changes or when a maintainer reruns the workflow.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

πŸ’‘ 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".

Comment on lines +253 to +254
if (!event.repeat && matchesNodeCustomShortcut(event, config.translate.node.customShortcut)) {
triggerNodeTranslation(resolveTriggerPoint(), config)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 πŸ‘Β / πŸ‘Ž.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

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

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

πŸ’‘ 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".

Comment on lines +265 to +267
const didConsumeCustomShortcut = !shouldIgnoreEvent()
&& !isEditableTarget(event.target)
&& matchesCurrentNodeCustomShortcut(event, cachedConfig)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 πŸ‘Β / πŸ‘Ž.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contrib-trust:new PR author trust score is 0-29. feat needs-maintainer-review Contributor trust automation recommends maintainer review. on-hold

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants