Repository navigation
fix(chat): align messages with their text direction #7466
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
Closed
ShlomiPorush
wants to merge
13
commits into
pingdotgg:main
from
ShlomiPorush:fix/chat-message-direction
Closed
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
712f715
fix(chat): align messages with their text direction
ShlomiPorush 4f0ab2a
fix(chat): preserve RTL markdown layout
ShlomiPorush 364f2cb
fix(web): mirror alert chrome in RTL
ShlomiPorush 49b039b
Merge remote-tracking branch 'origin/main' into fix/chat-message-dire…
ShlomiPorush 8f8a069
fix(mobile): parse markdown fences before RTL detection
ShlomiPorush ea22c78
fix(mobile): align RTL markdown containers
ShlomiPorush 39da1ee
fix(chat): preserve RTL direction in markdown edge cases
ShlomiPorush 4adb4fe
fix(chat): ignore markdown code during direction detection
ShlomiPorush c094fe0
refactor(mobile): derive text direction from markdown AST
ShlomiPorush 028c681
fix(mobile): keep RTL list markers at inline start
ShlomiPorush ef11976
fix(web): align markdown details summaries logically
ShlomiPorush ba1a24b
fix(web): isolate skill labels from message direction
ShlomiPorush f124b9f
fix(web): isolate artifact cards from message direction
ShlomiPorush File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| import type { MarkdownNode } from "react-native-nitro-markdown"; | ||
| import { describe, expect, it } from "vite-plus/test"; | ||
|
|
||
| import { resolveMarkdownNodeTextDirection, resolveTextDirection } from "./textDirection"; | ||
|
|
||
| const documentWith = (...children: MarkdownNode[]): MarkdownNode => ({ | ||
| type: "document", | ||
| children, | ||
| }); | ||
|
|
||
| describe("resolveTextDirection", () => { | ||
| it("resolves Hebrew and Arabic text as right-to-left", () => { | ||
| expect(resolveTextDirection("הודעה בעברית")).toBe("rtl"); | ||
| expect(resolveTextDirection("رسالة بالعربية")).toBe("rtl"); | ||
| }); | ||
|
|
||
| it("resolves English and other left-to-right scripts as left-to-right", () => { | ||
| expect(resolveTextDirection("English message")).toBe("ltr"); | ||
| expect(resolveTextDirection("日本語のメッセージ")).toBe("ltr"); | ||
| }); | ||
|
|
||
| it("ignores neutral prefixes before the first letter", () => { | ||
| expect(resolveTextDirection("👋 123... שלום")).toBe("rtl"); | ||
| expect(resolveTextDirection("(123) Hello")).toBe("ltr"); | ||
| }); | ||
|
|
||
| it("defaults neutral-only content to left-to-right", () => { | ||
| expect(resolveTextDirection("👋 123...")).toBe("ltr"); | ||
| }); | ||
|
|
||
| it("uses parsed prose instead of code content", () => { | ||
| expect( | ||
| resolveMarkdownNodeTextDirection( | ||
| documentWith( | ||
| { type: "code_block", content: "npm test" }, | ||
| { | ||
| type: "paragraph", | ||
| children: [ | ||
| { type: "code_inline", content: "English inline code" }, | ||
| { type: "text", content: " שלום" }, | ||
| ], | ||
| }, | ||
| ), | ||
| ), | ||
| ).toBe("rtl"); | ||
|
|
||
| expect( | ||
| resolveMarkdownNodeTextDirection( | ||
| documentWith({ | ||
| type: "paragraph", | ||
| children: [ | ||
| { type: "code_inline", content: "שלום" }, | ||
| { type: "text", content: " English prose" }, | ||
| ], | ||
| }), | ||
| ), | ||
| ).toBe("ltr"); | ||
| }); | ||
|
|
||
| it("ignores synthesized GitHub alert markers", () => { | ||
| expect( | ||
| resolveMarkdownNodeTextDirection( | ||
| documentWith({ | ||
| type: "blockquote", | ||
| children: [ | ||
| { | ||
| type: "paragraph", | ||
| children: [{ type: "text", content: "[!NOTE] הודעת התראה בעברית." }], | ||
| }, | ||
| ], | ||
| }), | ||
| ), | ||
| ).toBe("rtl"); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import type { MarkdownNode } from "react-native-nitro-markdown"; | ||
|
|
||
| export type TextDirection = "ltr" | "rtl"; | ||
|
|
||
| const LETTER_CHARACTER = /^\p{Letter}$/u; | ||
| const RTL_SCRIPT_CHARACTER = | ||
| /^[\u0590-\u08ff\ufb1d-\ufdff\ufe70-\ufeff\u{10800}-\u{10fff}\u{1e800}-\u{1eeff}]$/u; | ||
| const GITHUB_ALERT_MARKER = /\[!(?:NOTE|TIP|IMPORTANT|WARNING|CAUTION)\]/giu; | ||
|
|
||
| function markdownProse(node: MarkdownNode): string { | ||
| if (node.type === "code_inline" || node.type === "code_block" || node.type === "image") { | ||
| return ""; | ||
| } | ||
|
|
||
| if (node.type === "text") { | ||
| return (node.content ?? "").replace(GITHUB_ALERT_MARKER, ""); | ||
| } | ||
|
|
||
| return node.children?.map(markdownProse).join("") ?? ""; | ||
| } | ||
|
|
||
| export function resolveTextDirection(text: string): TextDirection { | ||
| for (const character of text) { | ||
| if (!LETTER_CHARACTER.test(character)) continue; | ||
| return RTL_SCRIPT_CHARACTER.test(character) ? "rtl" : "ltr"; | ||
| } | ||
| return "ltr"; | ||
| } | ||
|
|
||
| export function resolveMarkdownNodeTextDirection(node: MarkdownNode): TextDirection { | ||
| return resolveTextDirection(markdownProse(node)); | ||
| } | ||
|
cursor[bot] marked this conversation as resolved.
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.