From 17231f9151a2957db68cf6b02ba9ffb77b20d548 Mon Sep 17 00:00:00 2001 From: razavioo Date: Sun, 21 Jun 2026 18:12:01 +0330 Subject: [PATCH] Support RTL text in prompt input --- packages/app/src/components/prompt-input.tsx | 26 ++++++++++++++------ 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/packages/app/src/components/prompt-input.tsx b/packages/app/src/components/prompt-input.tsx index 8d40953ff2f9..31d8c6eeb8da 100644 --- a/packages/app/src/components/prompt-input.tsx +++ b/packages/app/src/components/prompt-input.tsx @@ -204,6 +204,8 @@ const EXAMPLES = [ "prompt.example.25", ] as const +const RTL_RE = /[\u0590-\u08FF\uFB1D-\uFDFF\uFE70-\uFEFF]/ + export const PromptInput: Component = (props) => { const sdk = useSDK() @@ -385,13 +387,19 @@ export const PromptInput: Component = (props) => { if (store.mode === "shell") return 0 return prompt.context.items().filter((item) => !!item.comment?.trim()).length }) - const blank = createMemo(() => { - const text = prompt + const promptText = createMemo(() => + prompt .current() .map((part) => ("content" in part ? part.content : "")) - .join("") - return text.trim().length === 0 && imageAttachments().length === 0 && commentCount() === 0 - }) + .join(""), + ) + const promptIsRtl = createMemo(() => store.mode === "normal" && RTL_RE.test(promptText())) + const promptDirection = createMemo(() => (promptIsRtl() ? "rtl" : "ltr")) + const promptTextStyle = createMemo(() => ({ + direction: promptDirection(), + "text-align": promptIsRtl() ? "right" : "left", + })) + const blank = createMemo(() => promptText().trim().length === 0 && imageAttachments().length === 0 && commentCount() === 0) const stopping = createMemo(() => working() && blank()) const tip = () => { if (stopping()) { @@ -1568,6 +1576,7 @@ export const PromptInput: Component = (props) => { role="textbox" aria-multiline="true" aria-label={designPlaceholder()} + dir={promptDirection()} contenteditable="true" autocapitalize={store.mode === "normal" ? "sentences" : "off"} autocorrect={store.mode === "normal" ? "on" : "off"} @@ -1588,11 +1597,13 @@ export const PromptInput: Component = (props) => { "[&_[data-type=agent]]:text-syntax-type": true, "font-mono!": store.mode === "shell", }} + style={promptTextStyle()} />
{designPlaceholder()}
@@ -1747,6 +1758,7 @@ export const PromptInput: Component = (props) => { role="textbox" aria-multiline="true" aria-label={placeholder()} + dir={promptDirection()} contenteditable="true" autocapitalize={store.mode === "normal" ? "sentences" : "off"} autocorrect={store.mode === "normal" ? "on" : "off"} @@ -1767,12 +1779,12 @@ export const PromptInput: Component = (props) => { "[&_[data-type=agent]]:text-syntax-type": true, "font-mono!": store.mode === "shell", }} - style={{ "padding-bottom": space }} + style={{ "padding-bottom": space, ...promptTextStyle() }} />
{placeholder()}