User-configurable 'Press Enter' voice command — custom & multilingual trigger phrases - #231
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (3)
📝 WalkthroughWalkthroughThis PR replaces a hardcoded trailing “press enter” regex with user-configurable multilingual command phrases. It adds regex compilation and extraction utilities, persists custom phrases in ChangesCustomizable multi-language press-enter command parsing
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
Sources/MultilanguagePressEnter.swift (1)
10-23: 💤 Low valueSingle-word commands may cause false positives in edge cases.
Commands like
"enter","intro","entrée","retour","eingabe", and"invio"could match legitimate sentence endings. For example, "Please type your username and then enter" would be stripped to "Please type your username and then".The PR objectives indicate this is a known trade-off (commands must be at the absolute end), but consider whether users in specific locales might frequently end sentences with these words. If this becomes an issue, these single-word variants could be removed, requiring the verb prefix (e.g., "press enter" but not bare "enter").
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@Sources/MultilanguagePressEnter.swift` around lines 10 - 23, The commands array contains single-word entries that cause false positives; update the static let commands in MultilanguagePressEnter.swift to remove the bare single-word variants ("enter", "intro", "entrée", "retour", "eingabe", "invio") so only multi-word/verb-prefixed forms remain (e.g., "press enter", "presionar enter", etc.); locate the static let commands declaration and delete those standalone tokens (or comment them out) to ensure matches require the verb prefix.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@Sources/MultilanguagePressEnter.swift`:
- Around line 10-23: The commands array contains single-word entries that cause
false positives; update the static let commands in MultilanguagePressEnter.swift
to remove the bare single-word variants ("enter", "intro", "entrée", "retour",
"eingabe", "invio") so only multi-word/verb-prefixed forms remain (e.g., "press
enter", "presionar enter", etc.); locate the static let commands declaration and
delete those standalone tokens (or comment them out) to ensure matches require
the verb prefix.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 05a34741-f53d-4cdb-b32f-4cea49af9701
📒 Files selected for processing (2)
Sources/AppState.swiftSources/MultilanguagePressEnter.swift
6c793d1 to
235b6e5
Compare
There was a problem hiding this comment.
Actionable comments posted: 3
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
Sources/MultilanguagePressEnter.swift (1)
140-147:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winAvoid duplicating restored sentence punctuation.
If the transcript already keeps punctuation before the command, e.g.
Are you coming? press enter?, these branches append another?/!because they only remove,and..Proposed fix
- if savedPunctuation == "?" { - // If the person asked a question, we make sure the saved question mark goes back to the end of the text. - if currentTranscript.hasSuffix(",") || currentTranscript.hasSuffix(".") { currentTranscript.removeLast() } - currentTranscript.append("?") - } else if savedPunctuation == "!" { - // If the person made an exclamation, we return the exclamation mark to the text. - if currentTranscript.hasSuffix(",") || currentTranscript.hasSuffix(".") { currentTranscript.removeLast() } - currentTranscript.append("!") + if savedPunctuation == "?" || savedPunctuation == "!" { + // Replace any existing terminal punctuation before restoring the saved punctuation. + if let last = currentTranscript.last, ",.!?".contains(last) { + currentTranscript.removeLast() + } + currentTranscript.append(savedPunctuation)🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@Sources/MultilanguagePressEnter.swift` around lines 140 - 147, The punctuation restoration logic in the savedPunctuation conditionals only checks for and removes "," and "." before appending "?" or "!", but does not account for cases where the transcript already ends with the same punctuation mark being restored. This causes duplicate punctuation like "Are you coming??" when the saved punctuation is already present. Modify both the `savedPunctuation == "?"` and `savedPunctuation == "!"` branches to also check if currentTranscript already ends with that same punctuation mark using hasSuffix, and skip appending it if it already exists, or alternatively remove any existing punctuation mark before appending the restored one.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@Sources/MultilanguagePressEnter.swift`:
- Line 71: The regexPattern variable lacks word boundaries, causing commands to
match as substrings within other words (e.g., "enter" matching inside
"carpenter"). Add word boundary markers by wrapping the joinedCommands group
with \b anchors. Change the non-capturing group from (?:\(joinedCommands)) to
(?:\b(?:\(joinedCommands))\b) to ensure commands only match as complete words,
preventing partial word matches while still allowing the pattern to function
correctly.
In `@Sources/SettingsView.swift`:
- Around line 2853-2867: The remove button is only created and rendered when
isHovering is true, making it inaccessible to keyboard and VoiceOver users.
Refactor the code so that the Button wrapping the remove action is always
present and focusable, rather than conditionally rendered in the overlay. Keep
the visual switching between the command text and xmark icon using opacity
changes based on isHovering, but ensure the Button itself exists at all times.
This makes the control accessible via keyboard navigation and assistive
technologies while maintaining the same hover-based visual feedback for pointer
users.
- Around line 1248-1251: The closing `})` on line 1251 lacks a matching opening
`Button(action: {`. Wrap the withAnimation block (which toggles
showPressEnterCustomization) with the missing Button(action:) initializer so
that the entire animation block and subsequent button label content are enclosed
within Button(action: { ... }) syntax, fixing the compile error.
---
Outside diff comments:
In `@Sources/MultilanguagePressEnter.swift`:
- Around line 140-147: The punctuation restoration logic in the savedPunctuation
conditionals only checks for and removes "," and "." before appending "?" or
"!", but does not account for cases where the transcript already ends with the
same punctuation mark being restored. This causes duplicate punctuation like
"Are you coming??" when the saved punctuation is already present. Modify both
the `savedPunctuation == "?"` and `savedPunctuation == "!"` branches to also
check if currentTranscript already ends with that same punctuation mark using
hasSuffix, and skip appending it if it already exists, or alternatively remove
any existing punctuation mark before appending the restored one.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 2d519eeb-a37c-4261-8328-175e41d394fa
📒 Files selected for processing (3)
Sources/AppState.swiftSources/MultilanguagePressEnter.swiftSources/SettingsView.swift
|
Thanks @coderabbitai! All 3 issues have been addressed:
|
235b6e5 to
56ca120
Compare
|
Tip For best results, initiate chat on the files or code changes.
If you found this review helpful, would you consider giving us a shout-out on X? Thank you for using CodeRabbit! |
|
Pushed a small follow-up commit (
@coderabbitai review |
|
The PR description images show a polished "Recognize 'Press Enter'" settings card in both light and dark themes — active variation pill tags (press enter, hit enter, presionar enter, 回車), a collapsible Customize section with a text input + Add button, and a multilanguage Suggested variations grid (English, Portuguese, Spanish, French, German, Italian, Dutch, Russian, Japanese, Chinese).
✅ Action performedReview finished.
|
…iations Enhanced Press Enter command settings: configurable command variations and multilanguage support, so the spoken 'press enter' (and localized/again equivalents) trigger a Return keypress. Includes the CodeRabbit review fixes (word-boundary regex, accessibility, punctuation) and the compiledRegex optional (= nil) fix, folded in from 059f36a. Modified files: - Sources/AppState.swift - Sources/MultilanguagePressEnter.swift (new) - Sources/SettingsView.swift
059f36a to
4a3da2c
Compare
|
Rebased onto the latest It's intentionally self-contained: scoped to compile standalone against @coderabbitai review |
|
The PR description images show the polished "Recognize 'Press Enter'" settings card — light theme displaying active variation pills (press enter, hit enter, presionar enter, 回车) with a collapsible Customize chevron, and the dark theme showing the same card with the Customize section expanded, a text input + Add button, and the full multilanguage Suggested variations grid.
✅ Action performedReview finished.
|
Description
FreeFlow already had a single, hard-coded "press enter" trigger that presses Return after a dictation. This PR makes the trigger fully user-configurable.
What it adds
UI and UX
Color.accentColor.opacity(0.15)), and smooth hover states.@State) for tags was extracted into independent structures (PressEnterActiveTagViewandPressEnterSuggestedTagView). This isolation prevents the primarySettingsViewfrom continuously re-rendering during pointer interactions, ensuring high application performance.Technical Implementation
MultilanguagePressEnter.swiftto handle command compilation and extraction. The system compiles user-defined active commands into a single, optimized, case-insensitiveNSRegularExpression..hasSuffix()checks. The new engine correctly strips trigger phrases from the end of the transcript even when followed by punctuation (e.g., "?", "!"). Relevant punctuation is preserved and re-applied to the finalized transcript.Summary by CodeRabbit
New Features
Bug Fixes