Add option to append trailing space after pasted text#5
Add option to append trailing space after pasted text#5dannysmith wants to merge 1 commit intomainfrom
Conversation
WalkthroughA new feature adds an optional trailing space to pasted text. Changes include a new Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ 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.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (8)
src-tauri/src/clipboard.rs(1 hunks)src-tauri/src/lib.rs(1 hunks)src-tauri/src/settings.rs(2 hunks)src-tauri/src/shortcut.rs(1 hunks)src/bindings.ts(2 hunks)src/components/settings/AppendTrailingSpace.tsx(1 hunks)src/components/settings/debug/DebugSettings.tsx(2 hunks)src/stores/settingsStore.ts(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (5)
src-tauri/src/lib.rs (1)
src-tauri/src/shortcut.rs (1)
change_append_trailing_space_setting(698-704)
src/components/settings/debug/DebugSettings.tsx (1)
src/components/settings/AppendTrailingSpace.tsx (1)
AppendTrailingSpace(10-27)
src/stores/settingsStore.ts (1)
src/bindings.ts (1)
commands(7-601)
src/components/settings/AppendTrailingSpace.tsx (1)
src/hooks/useSettings.ts (1)
useSettings(46-78)
src-tauri/src/shortcut.rs (1)
src-tauri/src/settings.rs (2)
get_settings(562-578)write_settings(580-586)
🔇 Additional comments (9)
src-tauri/src/lib.rs (1)
256-256: LGTM!The new command
change_append_trailing_space_settingis correctly added to the command collection, following the established pattern for other settings commands.src/components/settings/debug/DebugSettings.tsx (1)
12-12: LGTM!The
AppendTrailingSpacecomponent is correctly imported and rendered with consistent props (descriptionMode="tooltip"andgrouped={true}), matching the pattern of other settings in the Debug group.Also applies to: 44-44
src/bindings.ts (2)
247-254: LGTM!The auto-generated binding for
changeAppendTrailingSpaceSettingfollows the established pattern for boolean setting commands.
613-613: LGTM!The
AppSettingstype correctly includes the newappend_trailing_space?: booleanfield, consistent with the Rust-side definition.src-tauri/src/settings.rs (2)
288-289: LGTM!The new
append_trailing_spacefield is correctly added with#[serde(default)]annotation, following the same pattern asmute_while_recording. This ensures backward compatibility when deserialising existing settings that lack this field.
488-488: LGTM!The default value of
falseis consistent with the#[serde(default)]behaviour for booleans.src-tauri/src/clipboard.rs (1)
237-242: LGTM!The conditional trailing space transformation is correctly implemented before the paste operation. The logic applies consistently across all paste methods.
Note: If the transcribed text already ends with a space, this will result in a double space. This is likely acceptable since it's a user-configurable convenience feature, but worth being aware of.
src/stores/settingsStore.ts (1)
124-125: LGTM!The settings updater for
append_trailing_spaceis correctly wired to call the backend command, following the established pattern for boolean settings.src-tauri/src/shortcut.rs (1)
696-704: LGTM!The
change_append_trailing_space_settingcommand follows the established pattern for boolean settings commands, correctly reading, updating, and persisting the setting.
| import React from "react"; | ||
| import { ToggleSwitch } from "../ui/ToggleSwitch"; | ||
| import { useSettings } from "../../hooks/useSettings"; | ||
|
|
||
| interface AppendTrailingSpaceProps { | ||
| descriptionMode?: "inline" | "tooltip"; | ||
| grouped?: boolean; | ||
| } | ||
|
|
||
| export const AppendTrailingSpace: React.FC<AppendTrailingSpaceProps> = | ||
| React.memo(({ descriptionMode = "tooltip", grouped = false }) => { | ||
| const { getSetting, updateSetting, isUpdating } = useSettings(); | ||
|
|
||
| const enabled = getSetting("append_trailing_space") ?? false; | ||
|
|
||
| return ( | ||
| <ToggleSwitch | ||
| checked={enabled} | ||
| onChange={(enabled) => updateSetting("append_trailing_space", enabled)} | ||
| isUpdating={isUpdating("append_trailing_space")} | ||
| label="Append Trailing Space" | ||
| description="Automatically add a space at the end of transcribed text, making it easier to dictate multiple sentences in a row." | ||
| descriptionMode={descriptionMode} | ||
| grouped={grouped} | ||
| /> | ||
| ); | ||
| }); |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
# First, let's check the broader context of this setting and PR
# Look for append_trailing_space usage elsewhere in the codebase
rg "append_trailing_space" --type ts --type tsx -B 2 -A 2Repository: dannysmith/Handy
Length of output: 87
🏁 Script executed:
# Check if there's a PR description or README that clarifies the behavior
git log --oneline -20Repository: dannysmith/Handy
Length of output: 121
🏁 Script executed:
# Look for related documentation or comments about pasted vs transcribed text
rg "pasted|transcribed" --type ts --type tsx --type md -B 2 -A 2Repository: dannysmith/Handy
Length of output: 87
🏁 Script executed:
# Examine the useSettings hook to understand the setting's purpose
fd "useSettings" --type ts --type tsx | head -5Repository: dannysmith/Handy
Length of output: 229
🏁 Script executed:
# Check the ToggleSwitch component to see standard parameter naming patterns
fd "ToggleSwitch" --type ts --type tsx | head -5Repository: dannysmith/Handy
Length of output: 229
🏁 Script executed:
# Search for append_trailing_space usage
rg "append_trailing_space" -B 2 -A 2Repository: dannysmith/Handy
Length of output: 4938
🏁 Script executed:
# Look for related context about pasted or transcribed text
rg "pasted|transcribed" -B 2 -A 2Repository: dannysmith/Handy
Length of output: 3502
🏁 Script executed:
# Find and examine useSettings hook
fd "useSettings"Repository: dannysmith/Handy
Length of output: 84
🏁 Script executed:
# Find and examine ToggleSwitch component
fd "ToggleSwitch"Repository: dannysmith/Handy
Length of output: 94
🏁 Script executed:
# Quick check of the ToggleSwitch component to see parameter naming patterns
head -50 src/components/ui/ToggleSwitch.tsxRepository: dannysmith/Handy
Length of output: 1856
🏁 Script executed:
# Verify the useSettings hook implementation
head -50 src/hooks/useSettings.tsRepository: dannysmith/Handy
Length of output: 1637
Fix description to match actual behavior
The description says "transcribed text" but the setting actually controls spacing during paste. The backend applies the trailing space when pasting to the clipboard (see src-tauri/src/clipboard.rs), not during transcription. Update the description to say "pasted text" instead of "transcribed text" for accuracy.
Avoid shadowing enabled in the onChange handler
The enabled variable from getSetting and the enabled parameter in the onChange callback share the same name, which reduces readability. Rename the callback parameter:
- <ToggleSwitch
- checked={enabled}
- onChange={(enabled) => updateSetting("append_trailing_space", enabled)}
+ <ToggleSwitch
+ checked={enabled}
+ onChange={(nextEnabled) =>
+ updateSetting("append_trailing_space", nextEnabled)
+ }
isUpdating={isUpdating("append_trailing_space")}
label="Append Trailing Space"
description="Automatically add a space at the end of pasted text, making it easier to dictate multiple sentences in a row."
descriptionMode={descriptionMode}
grouped={grouped}
/>📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| import React from "react"; | |
| import { ToggleSwitch } from "../ui/ToggleSwitch"; | |
| import { useSettings } from "../../hooks/useSettings"; | |
| interface AppendTrailingSpaceProps { | |
| descriptionMode?: "inline" | "tooltip"; | |
| grouped?: boolean; | |
| } | |
| export const AppendTrailingSpace: React.FC<AppendTrailingSpaceProps> = | |
| React.memo(({ descriptionMode = "tooltip", grouped = false }) => { | |
| const { getSetting, updateSetting, isUpdating } = useSettings(); | |
| const enabled = getSetting("append_trailing_space") ?? false; | |
| return ( | |
| <ToggleSwitch | |
| checked={enabled} | |
| onChange={(enabled) => updateSetting("append_trailing_space", enabled)} | |
| isUpdating={isUpdating("append_trailing_space")} | |
| label="Append Trailing Space" | |
| description="Automatically add a space at the end of transcribed text, making it easier to dictate multiple sentences in a row." | |
| descriptionMode={descriptionMode} | |
| grouped={grouped} | |
| /> | |
| ); | |
| }); | |
| import React from "react"; | |
| import { ToggleSwitch } from "../ui/ToggleSwitch"; | |
| import { useSettings } from "../../hooks/useSettings"; | |
| interface AppendTrailingSpaceProps { | |
| descriptionMode?: "inline" | "tooltip"; | |
| grouped?: boolean; | |
| } | |
| export const AppendTrailingSpace: React.FC<AppendTrailingSpaceProps> = | |
| React.memo(({ descriptionMode = "tooltip", grouped = false }) => { | |
| const { getSetting, updateSetting, isUpdating } = useSettings(); | |
| const enabled = getSetting("append_trailing_space") ?? false; | |
| return ( | |
| <ToggleSwitch | |
| checked={enabled} | |
| onChange={(nextEnabled) => | |
| updateSetting("append_trailing_space", nextEnabled) | |
| } | |
| isUpdating={isUpdating("append_trailing_space")} | |
| label="Append Trailing Space" | |
| description="Automatically add a space at the end of pasted text, making it easier to dictate multiple sentences in a row." | |
| descriptionMode={descriptionMode} | |
| grouped={grouped} | |
| /> | |
| ); | |
| }); |
🤖 Prompt for AI Agents
In src/components/settings/AppendTrailingSpace.tsx around lines 1 to 27, the UI
description is inaccurate and the onChange callback shadows the outer enabled
variable; update the description string to reference "pasted text" (e.g.,
"Automatically add a space at the end of pasted text...") to match backend
behavior, and rename the onChange parameter from enabled to a different name
like newValue or checked to avoid shadowing the local enabled constant, then
pass that renamed parameter into updateSetting.
Summary by CodeRabbit
Release Notes
✏️ Tip: You can customize this high-level summary in your review settings.