From 8497ee9072dbd0c82645d2db3533e07d39235b0a Mon Sep 17 00:00:00 2001 From: Hugo Plante Date: Fri, 6 Nov 2026 22:40:17 -0500 Subject: [PATCH 1/4] feat(desktop): choose spellcheck languages for the composer On Windows and Linux, Electron only loads the dictionary matching the OS locale, so anyone writing in another language sees every word underlined. Add a Spellcheck languages setting (Settings > Chat) that applies the chosen dictionaries to the main session at startup and on change. Empty keeps the OS default; macOS keeps its native multilingual spellchecker. Co-Authored-By: Claude Opus 5.5 --- apps/desktop/src/app/DesktopApp.test.ts | 4 + apps/desktop/src/app/DesktopApp.ts | 2 + apps/desktop/src/ipc/DesktopIpcHandlers.ts | 7 +- apps/desktop/src/ipc/channels.ts | 1 + .../desktop/src/ipc/methods/clientSettings.ts | 13 +++ apps/desktop/src/main.ts | 2 + apps/desktop/src/preload.ts | 1 + .../src/settings/DesktopSpellcheck.test.ts | 65 +++++++++++ .../desktop/src/settings/DesktopSpellcheck.ts | 72 ++++++++++++ .../components/settings/SettingsPanels.tsx | 32 ++++++ .../settings/SpellcheckLanguagesPicker.tsx | 105 ++++++++++++++++++ .../src/components/settings/settingsSearch.ts | 7 ++ packages/contracts/src/ipc.ts | 2 + packages/contracts/src/settings.ts | 8 ++ 14 files changed, 320 insertions(+), 1 deletion(-) create mode 100644 apps/desktop/src/settings/DesktopSpellcheck.test.ts create mode 100644 apps/desktop/src/settings/DesktopSpellcheck.ts create mode 100644 apps/web/src/components/settings/SpellcheckLanguagesPicker.tsx diff --git a/apps/desktop/src/app/DesktopApp.test.ts b/apps/desktop/src/app/DesktopApp.test.ts index 8b5f9f712dc10..fb47bc6989c3e 100644 --- a/apps/desktop/src/app/DesktopApp.test.ts +++ b/apps/desktop/src/app/DesktopApp.test.ts @@ -44,6 +44,7 @@ import * as PreviewPasskeys from "../preview/Passkeys.ts"; import * as DesktopAppSettings from "../settings/DesktopAppSettings.ts"; import * as DesktopShellEnvironment from "../shell/DesktopShellEnvironment.ts"; import * as DesktopSnapShot from "../snapShot/DesktopSnapShot.ts"; +import * as DesktopSpellcheck from "../settings/DesktopSpellcheck.ts"; import * as DesktopRendererHistory from "../telemetry/DesktopRendererHistory.ts"; import * as DesktopUpdates from "../updates/DesktopUpdates.ts"; import * as DesktopApplicationMenu from "../window/DesktopApplicationMenu.ts"; @@ -162,6 +163,9 @@ it.effect.each([false, true])( Effect.provideService(DesktopSnapShot.DesktopSnapShot, { initialize: Effect.void, } as DesktopSnapShot.DesktopSnapShot["Service"]), + Effect.provideService(DesktopSpellcheck.DesktopSpellcheck, { + initialize: Effect.void, + } as DesktopSpellcheck.DesktopSpellcheck["Service"]), Effect.provideService(DesktopState.DesktopState, { quitting, } as DesktopState.DesktopState["Service"]), diff --git a/apps/desktop/src/app/DesktopApp.ts b/apps/desktop/src/app/DesktopApp.ts index 3c5f499a1cb3c..1710cb7182048 100644 --- a/apps/desktop/src/app/DesktopApp.ts +++ b/apps/desktop/src/app/DesktopApp.ts @@ -35,6 +35,7 @@ import * as DesktopState from "./DesktopState.ts"; import * as DesktopRemoteUpdates from "../updates/DesktopRemoteUpdates.ts"; import * as DesktopUpdates from "../updates/DesktopUpdates.ts"; import * as DesktopSnapShot from "../snapShot/DesktopSnapShot.ts"; +import * as DesktopSpellcheck from "../settings/DesktopSpellcheck.ts"; import * as DesktopWslBackend from "../wsl/DesktopWslBackend.ts"; import * as DesktopRendererHistory from "../telemetry/DesktopRendererHistory.ts"; import * as HostProcess from "@t3tools/shared/HostProcess"; @@ -192,6 +193,7 @@ const bootstrap = Effect.gen(function* () { ); yield* snapShot.initialize; + yield* (yield* DesktopSpellcheck.DesktopSpellcheck).initialize; if (!settings.localEnvironmentEnabled) { yield* logBootstrapInfo("bootstrap skipping local environment (disabled in settings)"); diff --git a/apps/desktop/src/ipc/DesktopIpcHandlers.ts b/apps/desktop/src/ipc/DesktopIpcHandlers.ts index a46dbafab0f41..686a774bee368 100644 --- a/apps/desktop/src/ipc/DesktopIpcHandlers.ts +++ b/apps/desktop/src/ipc/DesktopIpcHandlers.ts @@ -3,7 +3,11 @@ import * as Effect from "effect/Effect"; import { receiveProviderAuthCallback, cancelProviderAuthCallback } from "./methods/providerAuth.ts"; import * as DesktopIpc from "./DesktopIpc.ts"; import { installNotificationBadge } from "./methods/notificationBadge.ts"; -import { getClientSettings, setClientSettings } from "./methods/clientSettings.ts"; +import { + getClientSettings, + getSpellcheckLanguages, + setClientSettings, +} from "./methods/clientSettings.ts"; import { getConnectionCatalog, setConnectionCatalog } from "./methods/connectionCatalog.ts"; import { getLocalEnvironmentEnabled, @@ -102,6 +106,7 @@ export const installDesktopIpcHandlers = Effect.fn("desktop.ipc.installHandlers" yield* ipc.handle(getClientSettings); yield* ipc.handle(setClientSettings); + yield* ipc.handle(getSpellcheckLanguages); yield* ipc.handle(getConnectionCatalog); yield* ipc.handle(getSnapShotState); yield* ipc.handle(setupSnapShot); diff --git a/apps/desktop/src/ipc/channels.ts b/apps/desktop/src/ipc/channels.ts index 1d7edaf683250..d1723f6ffa49d 100644 --- a/apps/desktop/src/ipc/channels.ts +++ b/apps/desktop/src/ipc/channels.ts @@ -41,6 +41,7 @@ export const GET_LOCAL_ENVIRONMENT_BEARER_TOKEN_CHANNEL = "desktop:get-local-environment-bearer-token"; export const GET_CLIENT_SETTINGS_CHANNEL = "desktop:get-client-settings"; export const SET_CLIENT_SETTINGS_CHANNEL = "desktop:set-client-settings"; +export const GET_SPELLCHECK_LANGUAGES_CHANNEL = "desktop:get-spellcheck-languages"; export const SETUP_SNAP_SHOT_CHANNEL = "desktop:setup-snap-shot"; export const PREVIEW_SNAP_SHOT_CONFIG_CHANNEL = "desktop:preview-snap-shot-config"; export const APPLY_SNAP_SHOT_CONFIG_CHANNEL = "desktop:apply-snap-shot-config"; diff --git a/apps/desktop/src/ipc/methods/clientSettings.ts b/apps/desktop/src/ipc/methods/clientSettings.ts index 7a647a58dc431..db70df4704d65 100644 --- a/apps/desktop/src/ipc/methods/clientSettings.ts +++ b/apps/desktop/src/ipc/methods/clientSettings.ts @@ -4,6 +4,7 @@ import * as Option from "effect/Option"; import * as Schema from "effect/Schema"; import * as DesktopClientSettings from "../../settings/DesktopClientSettings.ts"; +import * as DesktopSpellcheck from "../../settings/DesktopSpellcheck.ts"; import * as DesktopSnapShot from "../../snapShot/DesktopSnapShot.ts"; import * as IpcChannels from "../channels.ts"; import * as DesktopIpc from "../DesktopIpc.ts"; @@ -25,7 +26,19 @@ export const setClientSettings = DesktopIpc.makeIpcMethod({ handler: Effect.fn("desktop.ipc.clientSettings.set")(function* (settings) { const clientSettings = yield* DesktopClientSettings.DesktopClientSettings; const snapShot = yield* DesktopSnapShot.DesktopSnapShot; + const spellcheck = yield* DesktopSpellcheck.DesktopSpellcheck; yield* clientSettings.set(settings); yield* snapShot.configure(settings); + yield* spellcheck.configure(settings); + }), +}); + +export const getSpellcheckLanguages = DesktopIpc.makeIpcMethod({ + channel: IpcChannels.GET_SPELLCHECK_LANGUAGES_CHANNEL, + payload: Schema.Void, + result: Schema.Array(Schema.String), + handler: Effect.fn("desktop.ipc.clientSettings.getSpellcheckLanguages")(function* () { + const spellcheck = yield* DesktopSpellcheck.DesktopSpellcheck; + return yield* spellcheck.availableLanguages; }), }); diff --git a/apps/desktop/src/main.ts b/apps/desktop/src/main.ts index d109518be15e4..94440b47fafb8 100644 --- a/apps/desktop/src/main.ts +++ b/apps/desktop/src/main.ts @@ -55,6 +55,7 @@ import * as DesktopShutdown from "./app/DesktopShutdown.ts"; import * as DesktopObservability from "./app/DesktopObservability.ts"; import * as DesktopServerExposure from "./backend/DesktopServerExposure.ts"; import * as DesktopClientSettings from "./settings/DesktopClientSettings.ts"; +import * as DesktopSpellcheck from "./settings/DesktopSpellcheck.ts"; import * as DesktopSavedEnvironments from "./settings/DesktopSavedEnvironments.ts"; import * as DesktopSnapShot from "./snapShot/DesktopSnapShot.ts"; import * as DesktopAppSettings from "./settings/DesktopAppSettings.ts"; @@ -212,6 +213,7 @@ const layerDesktopApplication = Layer.mergeAll( DesktopApplicationMenu.layer, DesktopLinuxUrlHandler.layer, DesktopCliCommand.layer, + DesktopSpellcheck.layer, layerDesktopSsh, ).pipe( Layer.provideMerge(layerDesktopSnapShot), diff --git a/apps/desktop/src/preload.ts b/apps/desktop/src/preload.ts index 800f1e744c9d1..e4e86a23e9671 100644 --- a/apps/desktop/src/preload.ts +++ b/apps/desktop/src/preload.ts @@ -123,6 +123,7 @@ contextBridge.exposeInMainWorld("desktopBridge", { getClientSettings: () => ipcRenderer.invoke(IpcChannels.GET_CLIENT_SETTINGS_CHANNEL), setClientSettings: (settings) => ipcRenderer.invoke(IpcChannels.SET_CLIENT_SETTINGS_CHANNEL, settings), + getSpellcheckLanguages: () => ipcRenderer.invoke(IpcChannels.GET_SPELLCHECK_LANGUAGES_CHANNEL), requestSnapShotPermissions: (includeAccessibility) => ipcRenderer.invoke(IpcChannels.REQUEST_SNAP_SHOT_PERMISSIONS_CHANNEL, includeAccessibility), getSnapShotState: () => ipcRenderer.invoke(IpcChannels.GET_SNAP_SHOT_STATE_CHANNEL), diff --git a/apps/desktop/src/settings/DesktopSpellcheck.test.ts b/apps/desktop/src/settings/DesktopSpellcheck.test.ts new file mode 100644 index 0000000000000..878967ef1169c --- /dev/null +++ b/apps/desktop/src/settings/DesktopSpellcheck.test.ts @@ -0,0 +1,65 @@ +import { DEFAULT_CLIENT_SETTINGS } from "@t3tools/contracts"; +import * as HostProcess from "@t3tools/shared/HostProcess"; +import { it } from "@effect/vitest"; +import * as Effect from "effect/Effect"; +import * as Layer from "effect/Layer"; +import * as Option from "effect/Option"; +import { expect, vi } from "vite-plus/test"; + +const session = vi.hoisted(() => ({ + languages: ["en-US"] as string[], + availableSpellCheckerLanguages: ["en-US", "en-GB", "fr-FR", "de-DE"], + getSpellCheckerLanguages: () => [...session.languages], + setSpellCheckerLanguages: (languages: string[]) => { + session.languages = [...languages]; + }, +})); +vi.mock("electron", () => ({ session: { defaultSession: session } })); + +import * as DesktopClientSettings from "./DesktopClientSettings.ts"; +import * as DesktopSpellcheck from "./DesktopSpellcheck.ts"; + +const withLanguages = (spellcheckLanguages: ReadonlyArray) => ({ + ...DEFAULT_CLIENT_SETTINGS, + spellcheckLanguages, +}); + +const run = (platform: NodeJS.Platform, stored: ReadonlyArray) => + Effect.gen(function* () { + session.languages = ["en-US"]; + return yield* DesktopSpellcheck.DesktopSpellcheck; + }).pipe( + Effect.provide( + DesktopSpellcheck.layer.pipe( + Layer.provide(DesktopClientSettings.layerTest(Option.some(withLanguages(stored)))), + ), + ), + Effect.provideService(HostProcess.Platform, platform), + ); + +it.effect("applies stored languages, drops unknown codes, and restores the OS default", () => + Effect.gen(function* () { + const spellcheck = yield* run("linux", ["fr-FR", "xx-XX", "en-US", "fr-FR"]); + yield* spellcheck.initialize; + expect(session.languages).toEqual(["fr-FR", "en-US"]); + + yield* spellcheck.configure(withLanguages(["de-DE"])); + expect(session.languages).toEqual(["de-DE"]); + + yield* spellcheck.configure(withLanguages(["xx-XX"])); + expect(session.languages).toEqual(["en-US"]); + + yield* spellcheck.configure(withLanguages([])); + expect(session.languages).toEqual(["en-US"]); + expect(yield* spellcheck.availableLanguages).toEqual(session.availableSpellCheckerLanguages); + }), +); + +it.effect("leaves the native macOS spellchecker alone", () => + Effect.gen(function* () { + const spellcheck = yield* run("darwin", ["fr-FR"]); + yield* spellcheck.initialize; + expect(session.languages).toEqual(["en-US"]); + expect(yield* spellcheck.availableLanguages).toEqual([]); + }), +); diff --git a/apps/desktop/src/settings/DesktopSpellcheck.ts b/apps/desktop/src/settings/DesktopSpellcheck.ts new file mode 100644 index 0000000000000..93de63334a20c --- /dev/null +++ b/apps/desktop/src/settings/DesktopSpellcheck.ts @@ -0,0 +1,72 @@ +import { DEFAULT_CLIENT_SETTINGS, type ClientSettings } from "@t3tools/contracts"; +import * as HostProcess from "@t3tools/shared/HostProcess"; +import * as Context from "effect/Context"; +import * as Effect from "effect/Effect"; +import * as Layer from "effect/Layer"; +import * as Option from "effect/Option"; +import * as Ref from "effect/Ref"; +import * as Electron from "electron"; + +import * as DesktopClientSettings from "./DesktopClientSettings.ts"; + +export class DesktopSpellcheck extends Context.Service< + DesktopSpellcheck, + { + readonly initialize: Effect.Effect; + readonly configure: (settings: ClientSettings) => Effect.Effect; + /** Empty where the OS spellchecker picks languages itself (macOS). */ + readonly availableLanguages: Effect.Effect>; + } +>()("@t3tools/desktop/settings/DesktopSpellcheck") {} + +/** Unknown codes are dropped so a stale setting can never leave spellcheck with no language. */ +function resolveSpellCheckerLanguages( + requested: ReadonlyArray, + available: ReadonlyArray, + systemDefault: ReadonlyArray, +): ReadonlyArray { + const supported = new Set(available); + const languages = [...new Set(requested)].filter((language) => supported.has(language)); + return languages.length > 0 ? languages : systemDefault; +} + +/** @public */ +export const make = Effect.gen(function* () { + const clientSettings = yield* DesktopClientSettings.DesktopClientSettings; + const platform = yield* HostProcess.Platform; + // Electron's own locale-derived choice, captured before the first override so clearing the setting restores it. + const systemDefaultRef = yield* Ref.make(Option.none>()); + + const configure = Effect.fn("desktop.spellcheck.configure")(function* (settings: ClientSettings) { + // macOS always uses the native spellchecker, which ignores Electron's language list. + if (platform === "darwin") return; + const session = Electron.session.defaultSession; + const systemDefault = yield* Ref.modify(systemDefaultRef, (stored) => { + const value = Option.getOrElse(stored, () => session.getSpellCheckerLanguages()); + return [value, Option.some(value)] as const; + }); + const languages = resolveSpellCheckerLanguages( + settings.spellcheckLanguages, + session.availableSpellCheckerLanguages, + systemDefault, + ); + yield* Effect.annotateCurrentSpan({ languages: languages.join(",") }); + // Only throws for codes outside availableSpellCheckerLanguages, which resolve has dropped. + yield* Effect.sync(() => session.setSpellCheckerLanguages([...languages])); + }); + + return DesktopSpellcheck.of({ + initialize: clientSettings.get.pipe( + Effect.flatMap((stored) => + configure(Option.getOrElse(stored, () => DEFAULT_CLIENT_SETTINGS)), + ), + Effect.ignore, + ), + configure, + availableLanguages: Effect.sync(() => + platform === "darwin" ? [] : Electron.session.defaultSession.availableSpellCheckerLanguages, + ), + }); +}); + +export const layer = Layer.effect(DesktopSpellcheck, make); diff --git a/apps/web/src/components/settings/SettingsPanels.tsx b/apps/web/src/components/settings/SettingsPanels.tsx index d408d6c8d5d94..3a5868a7a06e7 100644 --- a/apps/web/src/components/settings/SettingsPanels.tsx +++ b/apps/web/src/components/settings/SettingsPanels.tsx @@ -42,6 +42,10 @@ import { } from "../../components/desktopUpdate.logic"; import { ProviderModelPicker } from "../chat/ProviderModelPicker"; import { TraitsPicker } from "../chat/TraitsPicker"; +import { + SpellcheckLanguagesPicker, + useAvailableSpellcheckLanguages, +} from "./SpellcheckLanguagesPicker"; import { isElectron } from "../../env"; import { buildHostedChannelSelectionUrl, type HostedAppChannel } from "../../hostedPairing"; import { @@ -525,6 +529,7 @@ export function useSettingsRestore(onRestored?: () => void) { ? ["Rich text composer"] : []), ...(settings.sendShortcut !== DEFAULT_UNIFIED_SETTINGS.sendShortcut ? ["Send shortcut"] : []), + ...(settings.spellcheckLanguages.length > 0 ? ["Spellcheck languages"] : []), ...(settings.followUpBehavior !== DEFAULT_UNIFIED_SETTINGS.followUpBehavior ? ["Follow-up behavior"] : []), @@ -644,6 +649,7 @@ export function useSettingsRestore(onRestored?: () => void) { showSkillsInSlashMenu: DEFAULT_UNIFIED_SETTINGS.showSkillsInSlashMenu, composerRichTextEnabled: DEFAULT_UNIFIED_SETTINGS.composerRichTextEnabled, sendShortcut: DEFAULT_UNIFIED_SETTINGS.sendShortcut, + spellcheckLanguages: DEFAULT_UNIFIED_SETTINGS.spellcheckLanguages, followUpBehavior: DEFAULT_UNIFIED_SETTINGS.followUpBehavior, contextWindowMeterEnabled: DEFAULT_UNIFIED_SETTINGS.contextWindowMeterEnabled, environmentIdentificationMode: DEFAULT_UNIFIED_SETTINGS.environmentIdentificationMode, @@ -1085,6 +1091,7 @@ export function ChatSettingsPanel() { ] as const; const settings = useScopedSettings(); const updateSettings = useUpdateScopedSettings(); + const spellcheckLanguages = useAvailableSpellcheckLanguages(); return ( @@ -1161,6 +1168,31 @@ export function ChatSettingsPanel() { } /> + {spellcheckLanguages.length > 0 ? ( + 0 ? ( + + updateSettings({ + spellcheckLanguages: DEFAULT_UNIFIED_SETTINGS.spellcheckLanguages, + }) + } + /> + ) : null + } + control={ + updateSettings({ spellcheckLanguages: languages })} + /> + } + /> + ) : null} ([]); + // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- reads the dictionary list from the Electron main process + useEffect(() => { + const bridge = window.desktopBridge; + if (!bridge) return; + let cancelled = false; + bridge.getSpellcheckLanguages().then( + (available) => { + if (!cancelled) setLanguages(available); + }, + () => {}, + ); + return () => { + cancelled = true; + }; + }, []); + return languages; +} + +export function SpellcheckLanguagesPicker({ + available, + selected, + onChange, +}: { + available: readonly string[]; + selected: readonly string[]; + onChange: (languages: string[]) => void; +}) { + const [query, setQuery] = useState(""); + const items = [...new Set([...selected, ...available])].toSorted((a, b) => + spellcheckLanguageLabel(a).localeCompare(spellcheckLanguageLabel(b)), + ); + const needle = query.trim().toLowerCase(); + const filteredItems = needle + ? items.filter( + (code) => + code.toLowerCase().includes(needle) || + spellcheckLanguageLabel(code).toLowerCase().includes(needle), + ) + : items; + const summary = + selected.length === 0 ? "System default" : selected.map(spellcheckLanguageLabel).join(", "); + + return ( + { + if (!open) setQuery(""); + }} + onValueChange={(next) => onChange(next)} + > + }> + {summary} + + + setQuery(event.target.value)} + /> + No matching languages. + + {(code: string) => ( + + {spellcheckLanguageLabel(code)} + {selected.includes(code) ? : null} + + )} + + + + ); +} diff --git a/apps/web/src/components/settings/settingsSearch.ts b/apps/web/src/components/settings/settingsSearch.ts index 4c890c05aa4e9..ceff3a4168800 100644 --- a/apps/web/src/components/settings/settingsSearch.ts +++ b/apps/web/src/components/settings/settingsSearch.ts @@ -701,6 +701,13 @@ export const SETTINGS_SEARCH_ITEMS = [ to: "/settings/chat", searchTerms: ["enter return command ctrl multiline prompt new line composer"], }, + { + id: "spellcheck-languages", + title: "Spellcheck languages", + to: "/settings/chat", + searchTerms: ["spelling dictionary dictionaries language red underline typo composer"], + desktopOnly: true, + }, { id: "follow-up-behavior", title: "Follow-up behavior", diff --git a/packages/contracts/src/ipc.ts b/packages/contracts/src/ipc.ts index 6f1354dcdd9dd..a06c172dbcae9 100644 --- a/packages/contracts/src/ipc.ts +++ b/packages/contracts/src/ipc.ts @@ -1054,6 +1054,8 @@ export interface DesktopBridge { getLocalEnvironmentBearerToken: () => Promise; getClientSettings: () => Promise; setClientSettings: (settings: ClientSettings) => Promise; + /** Dictionary codes `spellcheckLanguages` may name. Empty on macOS, which picks languages itself. */ + getSpellcheckLanguages: () => Promise; getConnectionCatalog: () => Promise; setConnectionCatalog: (catalog: string) => Promise; discoverSshHosts: () => Promise; diff --git a/packages/contracts/src/settings.ts b/packages/contracts/src/settings.ts index 8a4b25589121c..1cdbb722f8b51 100644 --- a/packages/contracts/src/settings.ts +++ b/packages/contracts/src/settings.ts @@ -372,6 +372,11 @@ export const VoiceTranscriptionDestination = Schema.Struct({ }); export type VoiceTranscriptionDestination = typeof VoiceTranscriptionDestination.Type; +export const SpellcheckLanguages = Schema.Array(TrimmedNonEmptyString).check( + Schema.isMaxLength(32), +); +export type SpellcheckLanguages = typeof SpellcheckLanguages.Type; + export const ClientSettingsSchema = Schema.Struct({ notificationMode: NotificationMode.pipe( Schema.withDecodingDefault(Effect.succeed("off" as const)), @@ -493,6 +498,8 @@ export const ClientSettingsSchema = Schema.Struct({ sendShortcut: Schema.Literals(["enter", "mod-enter-multiline", "mod-enter"]).pipe( Schema.withDecodingDefault(Effect.succeed("enter")), ), + // Desktop spellchecker dictionary codes (e.g. "fr-FR"). Empty follows the operating system. + spellcheckLanguages: SpellcheckLanguages.pipe(Schema.withDecodingDefault(Effect.succeed([]))), followUpBehavior: Schema.Literals(["queue", "steer"]).pipe( Schema.withDecodingDefault(Effect.succeed("steer")), ), @@ -1878,6 +1885,7 @@ export const ClientSettingsPatch = Schema.Struct({ contextWindowMeterEnabled: Schema.optionalKey(Schema.Boolean), composerRichTextEnabled: Schema.optionalKey(Schema.Boolean), sendShortcut: Schema.optionalKey(Schema.Literals(["enter", "mod-enter-multiline", "mod-enter"])), + spellcheckLanguages: Schema.optionalKey(SpellcheckLanguages), followUpBehavior: Schema.optionalKey(Schema.Literals(["queue", "steer"])), proactivePanelsEnabled: Schema.optionalKey(Schema.Boolean), showSkillsInSlashMenu: Schema.optionalKey(Schema.Boolean), From 11fce03288c147f8782f4ca7f1199fb6df932492 Mon Sep 17 00:00:00 2001 From: Hugo Plante Date: Fri, 6 Nov 2026 22:48:25 -0500 Subject: [PATCH 2/4] fix(desktop): clearing spellcheck languages restores the locale default after a restart Electron persists the spellchecker list, so the default captured at launch was the previous override. Derive the default from app.getLocale() and only reset a list this app applied. Hide the search entry on macOS, where the row never renders. Co-Authored-By: Claude Opus 5.5 --- .../src/settings/DesktopSpellcheck.test.ts | 40 ++++++++++++++---- .../desktop/src/settings/DesktopSpellcheck.ts | 41 +++++++++++-------- .../src/components/settings/settingsSearch.ts | 4 ++ 3 files changed, 60 insertions(+), 25 deletions(-) diff --git a/apps/desktop/src/settings/DesktopSpellcheck.test.ts b/apps/desktop/src/settings/DesktopSpellcheck.test.ts index 878967ef1169c..14e9d50fef08c 100644 --- a/apps/desktop/src/settings/DesktopSpellcheck.test.ts +++ b/apps/desktop/src/settings/DesktopSpellcheck.test.ts @@ -14,7 +14,10 @@ const session = vi.hoisted(() => ({ session.languages = [...languages]; }, })); -vi.mock("electron", () => ({ session: { defaultSession: session } })); +vi.mock("electron", () => ({ + app: { getLocale: () => "en-GB" }, + session: { defaultSession: session }, +})); import * as DesktopClientSettings from "./DesktopClientSettings.ts"; import * as DesktopSpellcheck from "./DesktopSpellcheck.ts"; @@ -24,9 +27,14 @@ const withLanguages = (spellcheckLanguages: ReadonlyArray) => ({ spellcheckLanguages, }); -const run = (platform: NodeJS.Platform, stored: ReadonlyArray) => +// `persisted` is the list Electron restored from its Preferences file at launch. +const run = ( + platform: NodeJS.Platform, + stored: ReadonlyArray, + persisted: ReadonlyArray = ["en-GB"], +) => Effect.gen(function* () { - session.languages = ["en-US"]; + session.languages = [...persisted]; return yield* DesktopSpellcheck.DesktopSpellcheck; }).pipe( Effect.provide( @@ -37,7 +45,7 @@ const run = (platform: NodeJS.Platform, stored: ReadonlyArray) => Effect.provideService(HostProcess.Platform, platform), ); -it.effect("applies stored languages, drops unknown codes, and restores the OS default", () => +it.effect("applies stored languages, drops unknown codes, and restores the locale default", () => Effect.gen(function* () { const spellcheck = yield* run("linux", ["fr-FR", "xx-XX", "en-US", "fr-FR"]); yield* spellcheck.initialize; @@ -47,19 +55,37 @@ it.effect("applies stored languages, drops unknown codes, and restores the OS de expect(session.languages).toEqual(["de-DE"]); yield* spellcheck.configure(withLanguages(["xx-XX"])); - expect(session.languages).toEqual(["en-US"]); + expect(session.languages).toEqual(["en-GB"]); yield* spellcheck.configure(withLanguages([])); - expect(session.languages).toEqual(["en-US"]); + expect(session.languages).toEqual(["en-GB"]); expect(yield* spellcheck.availableLanguages).toEqual(session.availableSpellCheckerLanguages); }), ); +it.effect("clearing an override after a restart restores the locale default", () => + Effect.gen(function* () { + const spellcheck = yield* run("linux", ["fr-FR"], ["fr-FR"]); + yield* spellcheck.initialize; + yield* spellcheck.configure(withLanguages([])); + expect(session.languages).toEqual(["en-GB"]); + }), +); + +it.effect("leaves a list it never overrode alone", () => + Effect.gen(function* () { + const spellcheck = yield* run("linux", [], ["en-US", "fr-FR"]); + yield* spellcheck.initialize; + yield* spellcheck.configure(withLanguages([])); + expect(session.languages).toEqual(["en-US", "fr-FR"]); + }), +); + it.effect("leaves the native macOS spellchecker alone", () => Effect.gen(function* () { const spellcheck = yield* run("darwin", ["fr-FR"]); yield* spellcheck.initialize; - expect(session.languages).toEqual(["en-US"]); + expect(session.languages).toEqual(["en-GB"]); expect(yield* spellcheck.availableLanguages).toEqual([]); }), ); diff --git a/apps/desktop/src/settings/DesktopSpellcheck.ts b/apps/desktop/src/settings/DesktopSpellcheck.ts index 93de63334a20c..32ddc83bb5299 100644 --- a/apps/desktop/src/settings/DesktopSpellcheck.ts +++ b/apps/desktop/src/settings/DesktopSpellcheck.ts @@ -19,39 +19,44 @@ export class DesktopSpellcheck extends Context.Service< } >()("@t3tools/desktop/settings/DesktopSpellcheck") {} -/** Unknown codes are dropped so a stale setting can never leave spellcheck with no language. */ -function resolveSpellCheckerLanguages( - requested: ReadonlyArray, +/** Electron seeds its list from the app locale; Chromium falls back to the base language. */ +function localeDefaultLanguages( + locale: string, available: ReadonlyArray, - systemDefault: ReadonlyArray, ): ReadonlyArray { - const supported = new Set(available); - const languages = [...new Set(requested)].filter((language) => supported.has(language)); - return languages.length > 0 ? languages : systemDefault; + const base = locale.split("-")[0] ?? locale; + const match = + available.find((language) => language === locale) ?? + available.find((language) => language === base) ?? + available.find((language) => language.startsWith(`${base}-`)); + return [match ?? "en-US"]; } /** @public */ export const make = Effect.gen(function* () { const clientSettings = yield* DesktopClientSettings.DesktopClientSettings; const platform = yield* HostProcess.Platform; - // Electron's own locale-derived choice, captured before the first override so clearing the setting restores it. - const systemDefaultRef = yield* Ref.make(Option.none>()); + // Electron persists the list across restarts, so only undo an override this app applied; + // a list the user set in Chromium's Preferences by hand is left alone. + const overriddenRef = yield* Ref.make(false); const configure = Effect.fn("desktop.spellcheck.configure")(function* (settings: ClientSettings) { // macOS always uses the native spellchecker, which ignores Electron's language list. if (platform === "darwin") return; const session = Electron.session.defaultSession; - const systemDefault = yield* Ref.modify(systemDefaultRef, (stored) => { - const value = Option.getOrElse(stored, () => session.getSpellCheckerLanguages()); - return [value, Option.some(value)] as const; - }); - const languages = resolveSpellCheckerLanguages( - settings.spellcheckLanguages, - session.availableSpellCheckerLanguages, - systemDefault, + const available = session.availableSpellCheckerLanguages; + const supported = new Set(available); + const requested = [...new Set(settings.spellcheckLanguages)].filter((language) => + supported.has(language), ); + const overridden = yield* Ref.getAndSet(overriddenRef, requested.length > 0); + if (requested.length === 0 && !overridden) return; + const languages = + requested.length > 0 + ? requested + : localeDefaultLanguages(Electron.app.getLocale(), available); yield* Effect.annotateCurrentSpan({ languages: languages.join(",") }); - // Only throws for codes outside availableSpellCheckerLanguages, which resolve has dropped. + // Only throws for codes outside availableSpellCheckerLanguages, which are filtered out above. yield* Effect.sync(() => session.setSpellCheckerLanguages([...languages])); }); diff --git a/apps/web/src/components/settings/settingsSearch.ts b/apps/web/src/components/settings/settingsSearch.ts index ceff3a4168800..934a2fa7005aa 100644 --- a/apps/web/src/components/settings/settingsSearch.ts +++ b/apps/web/src/components/settings/settingsSearch.ts @@ -57,6 +57,7 @@ export interface SettingsSearchItem { readonly scope?: SettingsSearchScope; readonly desktopOnly?: boolean; readonly macOnly?: boolean; + readonly nonMacOnly?: boolean; readonly windowsOnly?: boolean; readonly releaseChannelOnly?: boolean; readonly secretsFeatureOnly?: boolean; @@ -707,6 +708,8 @@ export const SETTINGS_SEARCH_ITEMS = [ to: "/settings/chat", searchTerms: ["spelling dictionary dictionaries language red underline typo composer"], desktopOnly: true, + // macOS spellchecks natively, so ChatSettingsPanel never renders this row there. + nonMacOnly: true, }, { id: "follow-up-behavior", @@ -1475,6 +1478,7 @@ export function settingsForThisPlatform( (!item.releaseChannelOnly || isElectron || HOSTED_APP_CHANNEL !== null) && (!item.secretsFeatureOnly || isSecretsFeatureEnabled) && (!item.macOnly || isMacPlatform(platform)) && + (!item.nonMacOnly || !isMacPlatform(platform)) && (!item.windowsOnly || isWindowsPlatform(platform)), ); } From 776a52a4b2c096b6b14d162dcd58040698bb63e0 Mon Sep 17 00:00:00 2001 From: Hugo Plante Date: Fri, 6 Nov 2026 23:23:18 -0500 Subject: [PATCH 3/4] fix(web): spellcheck picker shows active languages and respects the limit Read the static dictionary list over sync IPC so the picker needs no effect, and gate the settings search entry on that same list. The summary and checkmarks only count languages that have a dictionary, and selections beyond the shared MAX_SPELLCHECK_LANGUAGES limit are ignored. Co-Authored-By: Claude Opus 5.5 --- apps/desktop/src/ipc/DesktopIpcHandlers.ts | 2 +- .../desktop/src/ipc/methods/clientSettings.ts | 3 +- apps/desktop/src/preload.ts | 5 ++- .../components/settings/SettingsPanels.tsx | 4 +- .../settings/SpellcheckLanguagesPicker.tsx | 40 ++++++++----------- .../settings/settingsSearch.test.ts | 1 + .../src/components/settings/settingsSearch.ts | 10 ++--- .../useAvailableSettingsSearchItems.ts | 2 + packages/contracts/src/ipc.ts | 2 +- packages/contracts/src/settings.ts | 3 +- 10 files changed, 35 insertions(+), 37 deletions(-) diff --git a/apps/desktop/src/ipc/DesktopIpcHandlers.ts b/apps/desktop/src/ipc/DesktopIpcHandlers.ts index 686a774bee368..407c7474310be 100644 --- a/apps/desktop/src/ipc/DesktopIpcHandlers.ts +++ b/apps/desktop/src/ipc/DesktopIpcHandlers.ts @@ -106,7 +106,7 @@ export const installDesktopIpcHandlers = Effect.fn("desktop.ipc.installHandlers" yield* ipc.handle(getClientSettings); yield* ipc.handle(setClientSettings); - yield* ipc.handle(getSpellcheckLanguages); + yield* ipc.handleSync(getSpellcheckLanguages); yield* ipc.handle(getConnectionCatalog); yield* ipc.handle(getSnapShotState); yield* ipc.handle(setupSnapShot); diff --git a/apps/desktop/src/ipc/methods/clientSettings.ts b/apps/desktop/src/ipc/methods/clientSettings.ts index db70df4704d65..678093711970a 100644 --- a/apps/desktop/src/ipc/methods/clientSettings.ts +++ b/apps/desktop/src/ipc/methods/clientSettings.ts @@ -33,9 +33,8 @@ export const setClientSettings = DesktopIpc.makeIpcMethod({ }), }); -export const getSpellcheckLanguages = DesktopIpc.makeIpcMethod({ +export const getSpellcheckLanguages = DesktopIpc.makeSyncIpcMethod({ channel: IpcChannels.GET_SPELLCHECK_LANGUAGES_CHANNEL, - payload: Schema.Void, result: Schema.Array(Schema.String), handler: Effect.fn("desktop.ipc.clientSettings.getSpellcheckLanguages")(function* () { const spellcheck = yield* DesktopSpellcheck.DesktopSpellcheck; diff --git a/apps/desktop/src/preload.ts b/apps/desktop/src/preload.ts index e4e86a23e9671..89f226be80e0b 100644 --- a/apps/desktop/src/preload.ts +++ b/apps/desktop/src/preload.ts @@ -123,7 +123,10 @@ contextBridge.exposeInMainWorld("desktopBridge", { getClientSettings: () => ipcRenderer.invoke(IpcChannels.GET_CLIENT_SETTINGS_CHANNEL), setClientSettings: (settings) => ipcRenderer.invoke(IpcChannels.SET_CLIENT_SETTINGS_CHANNEL, settings), - getSpellcheckLanguages: () => ipcRenderer.invoke(IpcChannels.GET_SPELLCHECK_LANGUAGES_CHANNEL), + getSpellcheckLanguages: () => { + const result: unknown = ipcRenderer.sendSync(IpcChannels.GET_SPELLCHECK_LANGUAGES_CHANNEL); + return Array.isArray(result) && result.every((code) => typeof code === "string") ? result : []; + }, requestSnapShotPermissions: (includeAccessibility) => ipcRenderer.invoke(IpcChannels.REQUEST_SNAP_SHOT_PERMISSIONS_CHANNEL, includeAccessibility), getSnapShotState: () => ipcRenderer.invoke(IpcChannels.GET_SNAP_SHOT_STATE_CHANNEL), diff --git a/apps/web/src/components/settings/SettingsPanels.tsx b/apps/web/src/components/settings/SettingsPanels.tsx index 3a5868a7a06e7..211d12a62633c 100644 --- a/apps/web/src/components/settings/SettingsPanels.tsx +++ b/apps/web/src/components/settings/SettingsPanels.tsx @@ -44,7 +44,7 @@ import { ProviderModelPicker } from "../chat/ProviderModelPicker"; import { TraitsPicker } from "../chat/TraitsPicker"; import { SpellcheckLanguagesPicker, - useAvailableSpellcheckLanguages, + readAvailableSpellcheckLanguages, } from "./SpellcheckLanguagesPicker"; import { isElectron } from "../../env"; import { buildHostedChannelSelectionUrl, type HostedAppChannel } from "../../hostedPairing"; @@ -1091,7 +1091,7 @@ export function ChatSettingsPanel() { ] as const; const settings = useScopedSettings(); const updateSettings = useUpdateScopedSettings(); - const spellcheckLanguages = useAvailableSpellcheckLanguages(); + const spellcheckLanguages = readAvailableSpellcheckLanguages(); return ( diff --git a/apps/web/src/components/settings/SpellcheckLanguagesPicker.tsx b/apps/web/src/components/settings/SpellcheckLanguagesPicker.tsx index 2898d6ef58173..7ee740b116935 100644 --- a/apps/web/src/components/settings/SpellcheckLanguagesPicker.tsx +++ b/apps/web/src/components/settings/SpellcheckLanguagesPicker.tsx @@ -1,5 +1,6 @@ +import { MAX_SPELLCHECK_LANGUAGES } from "@t3tools/contracts"; import { CheckIcon } from "lucide-react"; -import { useEffect, useState } from "react"; +import { useState } from "react"; import { Combobox, @@ -22,25 +23,12 @@ function spellcheckLanguageLabel(code: string): string { } } -/** Dictionaries the desktop main process can load; empty on web and macOS. */ -export function useAvailableSpellcheckLanguages(): readonly string[] { - const [languages, setLanguages] = useState([]); - // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- reads the dictionary list from the Electron main process - useEffect(() => { - const bridge = window.desktopBridge; - if (!bridge) return; - let cancelled = false; - bridge.getSpellcheckLanguages().then( - (available) => { - if (!cancelled) setLanguages(available); - }, - () => {}, - ); - return () => { - cancelled = true; - }; - }, []); - return languages; +let availableSpellcheckLanguages: readonly string[] | undefined; + +/** Dictionaries the desktop main process can load; empty on web and macOS. Fixed per app session. */ +export function readAvailableSpellcheckLanguages(): readonly string[] { + availableSpellcheckLanguages ??= window.desktopBridge?.getSpellcheckLanguages() ?? []; + return availableSpellcheckLanguages; } export function SpellcheckLanguagesPicker({ @@ -53,7 +41,9 @@ export function SpellcheckLanguagesPicker({ onChange: (languages: string[]) => void; }) { const [query, setQuery] = useState(""); - const items = [...new Set([...selected, ...available])].toSorted((a, b) => + // Stored codes without a dictionary stay in `selected` but are not shown as active. + const active = selected.filter((code) => available.includes(code)); + const items = available.toSorted((a, b) => spellcheckLanguageLabel(a).localeCompare(spellcheckLanguageLabel(b)), ); const needle = query.trim().toLowerCase(); @@ -65,7 +55,7 @@ export function SpellcheckLanguagesPicker({ ) : items; const summary = - selected.length === 0 ? "System default" : selected.map(spellcheckLanguageLabel).join(", "); + active.length === 0 ? "System default" : active.map(spellcheckLanguageLabel).join(", "); return ( { if (!open) setQuery(""); }} - onValueChange={(next) => onChange(next)} + onValueChange={(next) => { + if (next.length <= MAX_SPELLCHECK_LANGUAGES) onChange(next); + }} > }> {summary} @@ -95,7 +87,7 @@ export function SpellcheckLanguagesPicker({ {(code: string) => ( {spellcheckLanguageLabel(code)} - {selected.includes(code) ? : null} + {active.includes(code) ? : null} )} diff --git a/apps/web/src/components/settings/settingsSearch.test.ts b/apps/web/src/components/settings/settingsSearch.test.ts index 0b26c01f0dea1..d1aada66a2811 100644 --- a/apps/web/src/components/settings/settingsSearch.test.ts +++ b/apps/web/src/components/settings/settingsSearch.test.ts @@ -141,6 +141,7 @@ describe("searchSettings", () => { "auto-settle-merged-threads", "days-before-auto-settle", "linked-environments", + "spellcheck-languages", ]); expect(available.map((item) => item.id).filter((id) => gatedIds.has(id))).toEqual([]); }); diff --git a/apps/web/src/components/settings/settingsSearch.ts b/apps/web/src/components/settings/settingsSearch.ts index 934a2fa7005aa..a6d1e0a6f5cff 100644 --- a/apps/web/src/components/settings/settingsSearch.ts +++ b/apps/web/src/components/settings/settingsSearch.ts @@ -57,7 +57,6 @@ export interface SettingsSearchItem { readonly scope?: SettingsSearchScope; readonly desktopOnly?: boolean; readonly macOnly?: boolean; - readonly nonMacOnly?: boolean; readonly windowsOnly?: boolean; readonly releaseChannelOnly?: boolean; readonly secretsFeatureOnly?: boolean; @@ -69,6 +68,7 @@ export interface SettingsSearchItem { readonly localEnvironmentOnly?: boolean; readonly wslAvailableOnly?: boolean; readonly managedTunnelOnly?: boolean; + readonly spellcheckAvailableOnly?: boolean; readonly peerLinksOnly?: boolean; readonly secondary?: boolean; readonly requiresThreadAutoSettlement?: boolean; @@ -85,6 +85,7 @@ export interface SettingsSearchAvailability { readonly hasThreadAutoSettlement: boolean; readonly managedTunnelActive?: boolean; readonly hasPeerLinkHost?: boolean; + readonly hasSpellcheckLanguages?: boolean; } export const SETTINGS_SECTION_LABELS: Readonly> = { @@ -708,8 +709,7 @@ export const SETTINGS_SEARCH_ITEMS = [ to: "/settings/chat", searchTerms: ["spelling dictionary dictionaries language red underline typo composer"], desktopOnly: true, - // macOS spellchecks natively, so ChatSettingsPanel never renders this row there. - nonMacOnly: true, + spellcheckAvailableOnly: true, }, { id: "follow-up-behavior", @@ -1463,7 +1463,8 @@ export function filterAvailableSettingsSearchItems( (!item.wslAvailableOnly || availability.isWslSettingsRowVisible) && (!item.requiresThreadAutoSettlement || availability.hasThreadAutoSettlement) && (!item.managedTunnelOnly || availability.managedTunnelActive === true) && - (!item.peerLinksOnly || availability.hasPeerLinkHost === true), + (!item.peerLinksOnly || availability.hasPeerLinkHost === true) && + (!item.spellcheckAvailableOnly || availability.hasSpellcheckLanguages === true), ); } @@ -1478,7 +1479,6 @@ export function settingsForThisPlatform( (!item.releaseChannelOnly || isElectron || HOSTED_APP_CHANNEL !== null) && (!item.secretsFeatureOnly || isSecretsFeatureEnabled) && (!item.macOnly || isMacPlatform(platform)) && - (!item.nonMacOnly || !isMacPlatform(platform)) && (!item.windowsOnly || isWindowsPlatform(platform)), ); } diff --git a/apps/web/src/components/settings/useAvailableSettingsSearchItems.ts b/apps/web/src/components/settings/useAvailableSettingsSearchItems.ts index 254673b0026c2..793f91fdeeded 100644 --- a/apps/web/src/components/settings/useAvailableSettingsSearchItems.ts +++ b/apps/web/src/components/settings/useAvailableSettingsSearchItems.ts @@ -16,6 +16,7 @@ import { filterAvailableSettingsSearchItems, getThreadAutoSettlementSearchAvailability, } from "./settingsSearch"; +import { readAvailableSpellcheckLanguages } from "./SpellcheckLanguagesPicker"; export function useAvailableSettingsSearchItems(scopeSearch: SettingsScopeSearch = {}) { const { environments } = useEnvironments(); @@ -69,5 +70,6 @@ export function useAvailableSettingsSearchItems(scopeSearch: SettingsScopeSearch hasThreadAutoSettlement, managedTunnelActive, hasPeerLinkHost, + hasSpellcheckLanguages: readAvailableSpellcheckLanguages().length > 0, }); } diff --git a/packages/contracts/src/ipc.ts b/packages/contracts/src/ipc.ts index a06c172dbcae9..b43f7c5e3acff 100644 --- a/packages/contracts/src/ipc.ts +++ b/packages/contracts/src/ipc.ts @@ -1055,7 +1055,7 @@ export interface DesktopBridge { getClientSettings: () => Promise; setClientSettings: (settings: ClientSettings) => Promise; /** Dictionary codes `spellcheckLanguages` may name. Empty on macOS, which picks languages itself. */ - getSpellcheckLanguages: () => Promise; + getSpellcheckLanguages: () => readonly string[]; getConnectionCatalog: () => Promise; setConnectionCatalog: (catalog: string) => Promise; discoverSshHosts: () => Promise; diff --git a/packages/contracts/src/settings.ts b/packages/contracts/src/settings.ts index 1cdbb722f8b51..795fa3fbbb770 100644 --- a/packages/contracts/src/settings.ts +++ b/packages/contracts/src/settings.ts @@ -372,8 +372,9 @@ export const VoiceTranscriptionDestination = Schema.Struct({ }); export type VoiceTranscriptionDestination = typeof VoiceTranscriptionDestination.Type; +export const MAX_SPELLCHECK_LANGUAGES = 32; export const SpellcheckLanguages = Schema.Array(TrimmedNonEmptyString).check( - Schema.isMaxLength(32), + Schema.isMaxLength(MAX_SPELLCHECK_LANGUAGES), ); export type SpellcheckLanguages = typeof SpellcheckLanguages.Type; From 67336d02d0e66ed38c8f9c3bccbd4014cad4d7a0 Mon Sep 17 00:00:00 2001 From: maria-rcks Date: Wed, 18 Nov 2026 09:42:54 +0000 Subject: [PATCH 4/4] fix(desktop): preserve system spellcheck defaults and picker access --- .../src/settings/DesktopSpellcheck.test.ts | 2 +- .../desktop/src/settings/DesktopSpellcheck.ts | 4 +- .../settings/SpellcheckLanguagesPicker.tsx | 46 ++++++++++++------- 3 files changed, 32 insertions(+), 20 deletions(-) diff --git a/apps/desktop/src/settings/DesktopSpellcheck.test.ts b/apps/desktop/src/settings/DesktopSpellcheck.test.ts index 14e9d50fef08c..df52da8fc21cf 100644 --- a/apps/desktop/src/settings/DesktopSpellcheck.test.ts +++ b/apps/desktop/src/settings/DesktopSpellcheck.test.ts @@ -15,7 +15,7 @@ const session = vi.hoisted(() => ({ }, })); vi.mock("electron", () => ({ - app: { getLocale: () => "en-GB" }, + app: { getLocale: () => "en-US", getSystemLocale: () => "en-GB" }, session: { defaultSession: session }, })); diff --git a/apps/desktop/src/settings/DesktopSpellcheck.ts b/apps/desktop/src/settings/DesktopSpellcheck.ts index 32ddc83bb5299..f8289b5351c43 100644 --- a/apps/desktop/src/settings/DesktopSpellcheck.ts +++ b/apps/desktop/src/settings/DesktopSpellcheck.ts @@ -19,7 +19,7 @@ export class DesktopSpellcheck extends Context.Service< } >()("@t3tools/desktop/settings/DesktopSpellcheck") {} -/** Electron seeds its list from the app locale; Chromium falls back to the base language. */ +/** Electron seeds its list from the system locale; Chromium falls back to the base language. */ function localeDefaultLanguages( locale: string, available: ReadonlyArray, @@ -54,7 +54,7 @@ export const make = Effect.gen(function* () { const languages = requested.length > 0 ? requested - : localeDefaultLanguages(Electron.app.getLocale(), available); + : localeDefaultLanguages(Electron.app.getSystemLocale(), available); yield* Effect.annotateCurrentSpan({ languages: languages.join(",") }); // Only throws for codes outside availableSpellCheckerLanguages, which are filtered out above. yield* Effect.sync(() => session.setSpellCheckerLanguages([...languages])); diff --git a/apps/web/src/components/settings/SpellcheckLanguagesPicker.tsx b/apps/web/src/components/settings/SpellcheckLanguagesPicker.tsx index 9a2bcbd1054da..4917029d8183e 100644 --- a/apps/web/src/components/settings/SpellcheckLanguagesPicker.tsx +++ b/apps/web/src/components/settings/SpellcheckLanguagesPicker.tsx @@ -1,7 +1,7 @@ import { MAX_SPELLCHECK_LANGUAGES } from "@t3tools/contracts"; -import { useGT } from "gt-react"; +import { useGT, useLocale } from "gt-react"; import { CheckIcon } from "lucide-react"; -import { useState } from "react"; +import { useId, useState } from "react"; import { Combobox, @@ -14,10 +14,15 @@ import { } from "../ui/combobox"; import { SelectButton } from "../ui/select"; -const languageNames = new Intl.DisplayNames(["en"], { type: "language", fallback: "code" }); +const languageNamesByLocale = new Map(); -function spellcheckLanguageLabel(code: string): string { +function spellcheckLanguageLabel(code: string, locale: string): string { try { + let languageNames = languageNamesByLocale.get(locale); + if (!languageNames) { + languageNames = new Intl.DisplayNames([locale], { type: "language", fallback: "code" }); + languageNamesByLocale.set(locale, languageNames); + } return languageNames.of(code) ?? code; } catch { return code; @@ -42,22 +47,20 @@ export function SpellcheckLanguagesPicker({ onChange: (languages: string[]) => void; }) { const gt = useGT(); + const locale = useLocale(); + const summaryId = useId(); + const label = (code: string) => spellcheckLanguageLabel(code, locale); const [query, setQuery] = useState(""); // Stored codes without a dictionary stay in `selected` but are not shown as active. const active = selected.filter((code) => available.includes(code)); - const items = available.toSorted((a, b) => - spellcheckLanguageLabel(a).localeCompare(spellcheckLanguageLabel(b)), - ); + const items = available.toSorted((a, b) => label(a).localeCompare(label(b), locale)); const needle = query.trim().toLowerCase(); const filteredItems = needle ? items.filter( - (code) => - code.toLowerCase().includes(needle) || - spellcheckLanguageLabel(code).toLowerCase().includes(needle), + (code) => code.toLowerCase().includes(needle) || label(code).toLowerCase().includes(needle), ) : items; - const summary = - active.length === 0 ? gt("System default") : active.map(spellcheckLanguageLabel).join(", "); + const summary = active.length === 0 ? gt("System default") : active.map(label).join(", "); return ( { if (!open) setQuery(""); @@ -74,8 +77,12 @@ export function SpellcheckLanguagesPicker({ if (next.length <= MAX_SPELLCHECK_LANGUAGES) onChange(next); }} > - }> - {summary} + } + > + {summary} {gt("No matching languages.")} {(code: string) => ( - - {spellcheckLanguageLabel(code)} + = MAX_SPELLCHECK_LANGUAGES && !selected.includes(code)} + > + {label(code)} {active.includes(code) ? : null} )}