Skip to content

Commit ceea1e1

Browse files
committed
fix(web): wait for settings before the rich text shortcut flips them
Before client settings hydrate, composerRichTextEnabled reads as its default, so the shortcut could write the value the user already had and leave the focus restore armed for a later Settings change. The shortcut now waits for hydration. Its when clause also gets the full shortcut context, so editableFocus, previewFocus and platform conditions evaluate.
1 parent 3b92ec9 commit ceea1e1

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

‎apps/web/src/components/chat/ChatComposer.tsx‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -983,7 +983,10 @@ import {
983983
} from "@t3tools/client-runtime/providerSkills";
984984
import { searchProviderSkills } from "../../providerSkillSearch";
985985
import { useDelayedStatus } from "../../hooks/useDelayedStatus";
986-
import { useUpdateClientSettings } from "../../hooks/useSettings";
986+
import { useClientSettingsHydrated, useUpdateClientSettings } from "../../hooks/useSettings";
987+
import { isElectron } from "../../env";
988+
import { isEditableFocused } from "../../lib/editableFocus";
989+
import { isPreviewFocused } from "../../lib/previewFocus";
987990
import { useMediaQuery } from "../../hooks/useMediaQuery";
988991
import { usePanelAnimationSettings } from "../../panelAnimations";
989992
import { useAtomCommand } from "../../state/use-atom-command";
@@ -2142,16 +2145,20 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
21422145
const hasMultilinePrompt = prompt.includes("\n") || hasWrappedPrompt;
21432146
const [isStashMenuOpen, setIsStashMenuOpen] = useState(false);
21442147
const updateClientSettings = useUpdateClientSettings();
2148+
const clientSettingsHydrated = useClientSettingsHydrated();
21452149
// Flipping the setting remounts the editor, which drops focus. The flag
21462150
// tells the new instance that the user asked for this from the composer's
21472151
// shortcut and wants the caret back; changing the same setting from
21482152
// Settings leaves it alone. Rich text is a client setting rather than
21492153
// composer state, so both entry points drive the same switch.
21502154
const [pendingComposerFocusRestore, setPendingComposerFocusRestore] = useState(false);
21512155
const toggleComposerRichText = useCallback(() => {
2156+
// Before hydration the setting reads as its default, so flipping it could
2157+
// write the value the user already has and leave the restore armed.
2158+
if (!clientSettingsHydrated) return;
21522159
setPendingComposerFocusRestore(true);
21532160
void updateClientSettings({ composerRichTextEnabled: !settings.composerRichTextEnabled });
2154-
}, [settings.composerRichTextEnabled, updateClientSettings]);
2161+
}, [clientSettingsHydrated, settings.composerRichTextEnabled, updateClientSettings]);
21552162
const [isTasksDrawerOpen, setIsTasksDrawerOpen] = useState(false);
21562163
const [stashPulse, setStashPulse] = useState<{ key: number; active: boolean }>({
21572164
key: 0,
@@ -5237,7 +5244,11 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
52375244
context: {
52385245
terminalFocus: getTerminalFocusOwner() !== null,
52395246
terminalOpen,
5247+
previewFocus: isPreviewFocused(),
5248+
editableFocus: isEditableFocused(event.target),
52405249
modelPickerOpen: isComposerModelPickerOpen,
5250+
isWeb: !isElectron,
5251+
isDesktop: isElectron,
52415252
},
52425253
});
52435254
if (command !== "composer.toggleRichText") return;

0 commit comments

Comments
 (0)