-
Notifications
You must be signed in to change notification settings - Fork 2
Add configurable Arabic chat font settings and improve RTL chat rendering #5
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
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 | ||
|---|---|---|---|---|
|
|
@@ -65,6 +65,9 @@ import { | |||
| } from "~/lib/terminalContext"; | ||||
| import { cn } from "~/lib/utils"; | ||||
| import { basenameOfPath, getVscodeIconUrlForEntry, inferEntryKindFromPath } from "~/vscode-icons"; | ||||
| import { useSettings } from "../hooks/useSettings"; | ||||
| import { resolveChatTypographyClassName } from "~/lib/chatTypography"; | ||||
| import { resolveTextDirection } from "~/lib/textDirection"; | ||||
| import { | ||||
| COMPOSER_INLINE_CHIP_CLASS_NAME, | ||||
| COMPOSER_INLINE_CHIP_ICON_CLASS_NAME, | ||||
|
|
@@ -894,6 +897,17 @@ function ComposerPromptEditorInner({ | |||
| const [editor] = useLexicalComposerContext(); | ||||
| const onChangeRef = useRef(onChange); | ||||
| const initialCursor = clampCollapsedComposerCursor(value, cursor); | ||||
| const chatFontFamily = useSettings((settings) => settings.chatFontFamily); | ||||
| const composerDirection = resolveTextDirection(value); | ||||
| const composerTypographyClassName = useMemo( | ||||
| () => | ||||
| resolveChatTypographyClassName({ | ||||
| direction: composerDirection, | ||||
| fontFamily: chatFontFamily, | ||||
| variant: "composer", | ||||
| }), | ||||
| [chatFontFamily, composerDirection], | ||||
| ); | ||||
| const terminalContextsSignature = terminalContextSignature(terminalContexts); | ||||
| const terminalContextsSignatureRef = useRef(terminalContextsSignature); | ||||
| const snapshotRef = useRef({ | ||||
|
|
@@ -1092,8 +1106,11 @@ function ComposerPromptEditorInner({ | |||
| <PlainTextPlugin | ||||
| contentEditable={ | ||||
| <ContentEditable | ||||
| dir={composerDirection} | ||||
| lang={composerDirection === "rtl" ? "ar" : undefined} | ||||
| className={cn( | ||||
|
Comment on lines
+1109
to
1111
|
||||
| "block max-h-[200px] min-h-17.5 w-full overflow-y-auto whitespace-pre-wrap break-words bg-transparent text-[14px] leading-relaxed text-foreground focus:outline-none", | ||||
| composerTypographyClassName, | ||||
| className, | ||||
| )} | ||||
| data-testid="composer-editor" | ||||
|
|
@@ -1104,7 +1121,14 @@ function ComposerPromptEditorInner({ | |||
| } | ||||
| placeholder={ | ||||
| terminalContexts.length > 0 ? null : ( | ||||
| <div className="pointer-events-none absolute inset-0 text-[14px] leading-relaxed text-muted-foreground/35"> | ||||
| <div | ||||
| dir={composerDirection} | ||||
| lang={composerDirection === "rtl" ? "ar" : undefined} | ||||
|
||||
| lang={composerDirection === "rtl" ? "ar" : undefined} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -54,6 +54,7 @@ import { | |
| type ParsedTerminalContextEntry, | ||
| } from "~/lib/terminalContext"; | ||
| import { cn } from "~/lib/utils"; | ||
| import { useSettings } from "../../hooks/useSettings"; | ||
| import { type TimestampFormat } from "@t3tools/contracts/settings"; | ||
| import { formatTimestamp } from "../../timestampFormat"; | ||
| import { parseReviewReport, type ReviewFinding } from "../../review"; | ||
|
|
@@ -63,6 +64,8 @@ import { | |
| formatInlineTerminalContextLabel, | ||
| textContainsInlineTerminalContextLabels, | ||
| } from "./userMessageTerminalContexts"; | ||
| import { resolveChatTypographyClassName } from "~/lib/chatTypography"; | ||
| import { resolveTextDirection } from "~/lib/textDirection"; | ||
|
|
||
| const ALWAYS_UNVIRTUALIZED_TAIL_ROWS = 8; | ||
|
|
||
|
|
@@ -708,6 +711,17 @@ const UserMessageBody = memo(function UserMessageBody(props: { | |
| text: string; | ||
| terminalContexts: ParsedTerminalContextEntry[]; | ||
| }) { | ||
| const chatFontFamily = useSettings((settings) => settings.chatFontFamily); | ||
| const textDirection = resolveTextDirection(props.text); | ||
| const bodyClassName = cn( | ||
| "chat-message-inline-body whitespace-pre-wrap text-sm leading-relaxed text-foreground", | ||
| textDirection !== "rtl" && "font-mono", | ||
| resolveChatTypographyClassName({ | ||
| direction: textDirection, | ||
| fontFamily: chatFontFamily, | ||
| }), | ||
| ); | ||
|
|
||
| if (props.terminalContexts.length > 0) { | ||
| const hasEmbeddedInlineLabels = textContainsInlineTerminalContextLabels( | ||
| props.text, | ||
|
|
@@ -752,7 +766,11 @@ const UserMessageBody = memo(function UserMessageBody(props: { | |
| } | ||
|
|
||
| return ( | ||
| <div className="wrap-break-word whitespace-pre-wrap font-mono text-sm leading-relaxed text-foreground"> | ||
| <div | ||
| dir={textDirection} | ||
| lang={textDirection === "rtl" ? "ar" : undefined} | ||
| className={bodyClassName} | ||
|
Comment on lines
+769
to
+772
|
||
| > | ||
| {inlineNodes} | ||
| </div> | ||
| ); | ||
|
|
@@ -780,7 +798,11 @@ const UserMessageBody = memo(function UserMessageBody(props: { | |
| } | ||
|
|
||
| return ( | ||
| <div className="wrap-break-word whitespace-pre-wrap font-mono text-sm leading-relaxed text-foreground"> | ||
| <div | ||
| dir={textDirection} | ||
| lang={textDirection === "rtl" ? "ar" : undefined} | ||
| className={bodyClassName} | ||
|
Comment on lines
+801
to
+804
|
||
| > | ||
| {inlineNodes} | ||
| </div> | ||
| ); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -63,9 +63,7 @@ function splitPatch(patch: SettingsUpdatePatch): { | |
| * only re-render when the slice they care about changes. | ||
| */ | ||
|
|
||
| export function useSettings<T extends UnifiedSettings = UnifiedSettings>( | ||
| selector?: (s: UnifiedSettings) => T, | ||
| ): T { | ||
| export function useSettings<T = UnifiedSettings>(selector?: (s: UnifiedSettings) => T): T { | ||
|
||
| const serverSettings = useServerSettings(); | ||
| const [clientSettings] = useLocalStorage( | ||
| CLIENT_SETTINGS_STORAGE_KEY, | ||
|
|
||
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.
langis hardcoded to "ar" for any RTL text, but direction != language (e.g., Hebrew is RTL). This can degrade screen reader pronunciation and font shaping. Consider removinglanghere or computing it from Arabic-script detection separately fromresolveTextDirection.