-
Notifications
You must be signed in to change notification settings - Fork 149
feat: add spell check and auto correct settings #206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -106,6 +106,10 @@ interface ThemeContextType { | |
| reloadSettings: () => Promise<void>; | ||
| textDirection: TextDirection; | ||
| setTextDirection: (dir: TextDirection) => void; | ||
| spellCheckEnabled: boolean; | ||
| setSpellCheckEnabled: (enabled: boolean) => void; | ||
| autoCorrectEnabled: boolean; | ||
| setAutoCorrectEnabled: (enabled: boolean) => void; | ||
| editorWidth: EditorWidth; | ||
| setEditorWidth: (width: EditorWidth) => void; | ||
| interfaceZoom: number; | ||
|
|
@@ -186,6 +190,8 @@ export function ThemeProvider({ children }: ThemeProviderProps) { | |
| Required<EditorFontSettings> | ||
| >(defaultEditorFontSettings); | ||
| const [textDirection, setTextDirectionState] = useState<TextDirection>("auto"); | ||
| const [spellCheckEnabled, setSpellCheckEnabledState] = useState(false); | ||
| const [autoCorrectEnabled, setAutoCorrectEnabledState] = useState(false); | ||
| const [editorWidth, setEditorWidthState] = useState<EditorWidth>("normal"); | ||
| const [interfaceZoom, setInterfaceZoomState] = useState(1.0); | ||
| const [customEditorWidthPx, setCustomEditorWidthPxState] = useState<number>( | ||
|
|
@@ -225,6 +231,11 @@ export function ThemeProvider({ children }: ThemeProviderProps) { | |
| if (isTextDirection(settings.textDirection)) { | ||
| setTextDirectionState(settings.textDirection); | ||
| } | ||
| const isSpellCheckEnabled = settings.spellCheckEnabled === true; | ||
| setSpellCheckEnabledState(isSpellCheckEnabled); | ||
| setAutoCorrectEnabledState( | ||
| isSpellCheckEnabled && settings.autoCorrectEnabled === true, | ||
| ); | ||
| if ( | ||
| settings.editorWidth === "narrow" || | ||
| settings.editorWidth === "normal" || | ||
|
|
@@ -431,6 +442,40 @@ export function ThemeProvider({ children }: ThemeProviderProps) { | |
| } | ||
| }, []); | ||
|
|
||
| const setSpellCheckEnabled = useCallback(async (enabled: boolean) => { | ||
| setSpellCheckEnabledState(enabled); | ||
| if (!enabled) { | ||
| setAutoCorrectEnabledState(false); | ||
| } | ||
| try { | ||
| const settings = await getSettings(); | ||
| await updateSettings({ | ||
| ...settings, | ||
| spellCheckEnabled: enabled, | ||
| autoCorrectEnabled: enabled && autoCorrectEnabled, | ||
| }); | ||
| } catch (error) { | ||
| console.error("Failed to save spell check setting:", error); | ||
| } | ||
|
Comment on lines
+457
to
+459
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win Report and recover from persistence failures. The setters update local state before persistence. If Show a user-facing error and restore the last persisted values, or return the failure to the caller for display. As per coding guidelines, “Implement error handling with user-friendly messages.” Also applies to: 474-476 🤖 Prompt for AI AgentsSource: Coding guidelines |
||
| }, [autoCorrectEnabled]); | ||
|
|
||
| const setAutoCorrectEnabled = useCallback(async (enabled: boolean) => { | ||
| setAutoCorrectEnabledState(enabled); | ||
| if (enabled) { | ||
| setSpellCheckEnabledState(true); | ||
| } | ||
| try { | ||
| const settings = await getSettings(); | ||
| await updateSettings({ | ||
| ...settings, | ||
| spellCheckEnabled: enabled || spellCheckEnabled, | ||
| autoCorrectEnabled: enabled, | ||
| }); | ||
| } catch (error) { | ||
| console.error("Failed to save auto correct setting:", error); | ||
| } | ||
| }, [spellCheckEnabled]); | ||
|
Comment on lines
+445
to
+477
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift Make writing-assistance persistence atomic. Each setter reads a complete Add one Tauri command that updates both writing-assistance fields atomically. Use that command from both setters. This also prevents these setters from overwriting unrelated settings that changed after 🤖 Prompt for AI Agents |
||
|
|
||
| // Save and set editor width | ||
| const setEditorWidth = useCallback(async (width: EditorWidth) => { | ||
| setEditorWidthState(width); | ||
|
|
@@ -620,6 +665,10 @@ export function ThemeProvider({ children }: ThemeProviderProps) { | |
| reloadSettings, | ||
| textDirection, | ||
| setTextDirection, | ||
| spellCheckEnabled, | ||
| setSpellCheckEnabled, | ||
| autoCorrectEnabled, | ||
| setAutoCorrectEnabled, | ||
| editorWidth, | ||
| setEditorWidth, | ||
| interfaceZoom, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: erictli/scratch
Length of output: 1263
🏁 Script executed:
Repository: erictli/scratch
Length of output: 11627
Add accessible state to the On/Off controls.
Buttononly forwards props and adds no state semantics. Addaria-pressedor radio semantics to each option, and associate each group with an accessible label.🤖 Prompt for AI Agents