-
Notifications
You must be signed in to change notification settings - Fork 6.3k
fix(chat): align messages with their text direction #10779
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
haithamassoli44
wants to merge
71
commits into
pingdotgg:main
from
haithamassoli:fix/chat-message-direction
Closed
Changes from all commits
Commits
Show all changes
71 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 2eb6914
Merge origin/main into fix/chat-message-direction
haithamassoli44 6492bb5
Merge branch 'main' into fix/chat-message-direction
haithamassoli 0527c5b
Merge branch 'main' into fix/chat-message-direction
haithamassoli da9bcf6
Merge branch 'main' into fix/chat-message-direction
haithamassoli 95ffbb1
Merge branch 'main' into fix/chat-message-direction
haithamassoli 0445a49
fix(chat): direct composer questions by content
haithamassoli44 3a500a7
Merge branch 'main' into fix/chat-message-direction
haithamassoli 50a1993
fix(chat): detect RTL-dominant mixed text
haithamassoli44 37106ad
Merge branch 'main' into fix/chat-message-direction
haithamassoli def51aa
Merge branch 'main' into fix/chat-message-direction
haithamassoli a83fab1
Merge branch 'main' into fix/chat-message-direction
haithamassoli f78aa08
Merge branch 'main' into fix/chat-message-direction
haithamassoli 6a98f73
Merge branch 'main' into fix/chat-message-direction
haithamassoli 7b33641
Merge branch 'main' of github.com:pingdotgg/t3code into fix/chat-mess…
haithamassoli44 19ec4a2
Merge branch 'main' into fix/chat-message-direction
haithamassoli 874fd64
Merge branch 'main' into fix/chat-message-direction
haithamassoli44 c5ddfa3
Merge branch 'main' into fix/chat-message-direction
haithamassoli 32ce82a
Merge branch 'main' into fix/chat-message-direction
haithamassoli 7cb9c28
Merge branch 'main' into fix/chat-message-direction
haithamassoli e5b37e9
Merge branch 'main' into fix/chat-message-direction
haithamassoli b1ab514
Merge branch 'main' into fix/chat-message-direction
haithamassoli44 7b03def
Merge branch 'main' into fix/chat-message-direction
haithamassoli44 641c6bc
Merge branch 'main' into fix/chat-message-direction
haithamassoli44 913ef37
Merge branch 'main' into fix/chat-message-direction
haithamassoli d733822
Merge branch 'main' into fix/chat-message-direction
haithamassoli44 e068479
Merge branch 'main' into fix/chat-message-direction
haithamassoli44 f6d6422
Merge branch 'main' into fix/chat-message-direction
haithamassoli44 6dccbca
Merge branch 'main' into fix/chat-message-direction
haithamassoli 61c5e30
Merge branch 'main' into fix/chat-message-direction
haithamassoli 03000d3
Merge branch 'main' into fix/chat-message-direction
haithamassoli 171afe7
Merge branch 'main' into fix/chat-message-direction
haithamassoli 7d83025
Merge branch 'main' into fix/chat-message-direction
haithamassoli44 05fe6f7
Merge branch 'main' into fix/chat-message-direction
haithamassoli 2ca6183
Merge branch 'main' into fix/chat-message-direction
haithamassoli 45c3ca6
Merge branch 'main' into fix/chat-message-direction
haithamassoli bd3c06f
Merge branch 'main' into fix/chat-message-direction
haithamassoli44 b3170ba
Merge branch 'main' into fix/chat-message-direction
haithamassoli44 8840efd
Merge branch 'main' into fix/chat-message-direction
haithamassoli 96d40b3
Merge remote-tracking branch 'origin/main' into fix/chat-message-dire…
haithamassoli44 ed50c1e
Merge branch 'main' into fix/chat-message-direction
haithamassoli44 d60f80c
Merge branch 'main' into fix/chat-message-direction
haithamassoli d6b10a4
Merge branch 'main' into fix/chat-message-direction
haithamassoli 54cd408
Merge branch 'main' into fix/chat-message-direction
haithamassoli aa8c488
Merge remote-tracking branch 'origin/main' into fix/chat-message-dire…
haithamassoli44 6a3937f
Merge branch 'main' into fix/chat-message-direction
haithamassoli fc3ec70
Merge branch 'main' into fix/chat-message-direction
haithamassoli 2679c6f
Merge branch 'main' into fix/chat-message-direction
haithamassoli bdaa341
Merge branch 'main' into fix/chat-message-direction
haithamassoli c44064f
Merge branch 'main' into fix/chat-message-direction
haithamassoli e2f5c80
Merge branch 'main' into fix/chat-message-direction
haithamassoli44 567359f
Merge branch 'main' into fix/chat-message-direction
haithamassoli 2ef2db2
Merge branch 'main' into fix/chat-message-direction
haithamassoli fdefc58
Merge branch 'main' into fix/chat-message-direction
haithamassoli 62a5ced
Merge branch 'main' into fix/chat-message-direction
haithamassoli 47af104
Merge branch 'main' into fix/chat-message-direction
haithamassoli c1eda04
Merge branch 'main' into fix/chat-message-direction
haithamassoli ad5c1c1
Merge branch 'main' into fix/chat-message-direction
haithamassoli44 e128403
Merge branch 'main' into fix/chat-message-direction
haithamassoli 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,78 @@ | ||
| 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"); | ||
| expect(resolveTextDirection("React Server Components האם להשתמש בהם בפרויקט החדש שלנו?")).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,41 @@ | ||
| import { resolveTextDirection, type TextDirection } from "@t3tools/shared/textDirection"; | ||
| import type { MarkdownNode } from "react-native-nitro-markdown"; | ||
|
|
||
| const GITHUB_ALERT_MARKER = /\[!(?:NOTE|TIP|IMPORTANT|WARNING|CAUTION)\]/giu; | ||
| const MAX_MARKDOWN_PROSE_CODE_UNITS = 17_408; | ||
|
|
||
| function collectMarkdownProse( | ||
| node: MarkdownNode, | ||
| chunks: string[], | ||
| remainingCodeUnits: number, | ||
| ): number { | ||
| if (remainingCodeUnits === 0) return 0; | ||
| if (node.type === "code_inline" || node.type === "code_block" || node.type === "image") { | ||
| return remainingCodeUnits; | ||
| } | ||
|
|
||
| if (node.type === "text") { | ||
| const text = (node.content ?? "").slice(0, remainingCodeUnits).replace(GITHUB_ALERT_MARKER, ""); | ||
| chunks.push(text); | ||
| return remainingCodeUnits - text.length; | ||
| } | ||
|
|
||
| for (const child of node.children ?? []) { | ||
| remainingCodeUnits = collectMarkdownProse(child, chunks, remainingCodeUnits); | ||
| if (remainingCodeUnits === 0) break; | ||
| } | ||
| return remainingCodeUnits; | ||
| } | ||
|
|
||
| function markdownProse(node: MarkdownNode): string { | ||
| const chunks: string[] = []; | ||
| collectMarkdownProse(node, chunks, MAX_MARKDOWN_PROSE_CODE_UNITS); | ||
| return chunks.join(""); | ||
| } | ||
|
|
||
| export function resolveMarkdownNodeTextDirection(node: MarkdownNode): TextDirection { | ||
| return resolveTextDirection(markdownProse(node)); | ||
| } | ||
|
|
||
| export { resolveTextDirection }; | ||
| export type { TextDirection }; |
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
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.