Skip to content

Commit 9b6be32

Browse files
committed
fix: RTL text layout support in web UI (anomalyco#16875)
- Convert hardcoded physical CSS properties to logical properties (padding-left → padding-inline-start, margin-left → margin-inline-start, text-align: left → text-align: start, border-left → border-inline-start) - Expand RTL locale detection beyond Arabic to include Hebrew (he), Persian/Farsi (fa), and Urdu (ur) - Add shared @opencode-ai/util/rtl module for RTL direction detection - Add isRtl() export alongside dir() in console language utility - Preserve direction:rtl truncation-trick comments for clarity Fixes RTL text appearing wrongly indented and disconnected in the web/console UI. TUI (terminal) layer still needs OpenTUI bidi support (separate effort).
1 parent 4c4eef4 commit 9b6be32

11 files changed

Lines changed: 66 additions & 36 deletions

File tree

‎packages/console/app/src/lib/language.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,11 +216,17 @@ export function tag(locale: Locale) {
216216
return TAG[locale]
217217
}
218218

219+
const RTL_LOCALES: ReadonlySet<string> = new Set(["ar", "he", "fa", "ur"])
220+
219221
export function dir(locale: Locale) {
220-
if (locale === "ar") return "rtl"
222+
if (RTL_LOCALES.has(locale)) return "rtl"
221223
return "ltr"
222224
}
223225

226+
export function isRtl(locale: Locale) {
227+
return RTL_LOCALES.has(locale)
228+
}
229+
224230
function match(input: string): Locale | null {
225231
const value = input.trim().toLowerCase()
226232
if (!value) return null

‎packages/ui/src/components/card.css‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
&::before {
4040
content: "";
4141
position: absolute;
42-
left: 0;
42+
inset-inline-start: 0;
4343
top: var(--card-line-pad);
4444
bottom: var(--card-line-pad);
4545
width: 2px;
@@ -89,6 +89,6 @@
8989
}
9090

9191
:where([data-card="actions"], [data-slot="card-actions"]) {
92-
padding-left: var(--card-indent);
92+
padding-inline-start: var(--card-indent);
9393
}
9494
}

‎packages/ui/src/components/dialog.css‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
[data-slot="dialog-description"] {
7878
display: flex;
7979
padding: 16px;
80-
padding-left: 24px;
80+
padding-inline-start: 24px;
8181
padding-top: 0;
8282
margin-top: -8px;
8383
justify-content: space-between;

‎packages/ui/src/components/file.css‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@
3030
color: var(--text-base);
3131
width: var(--diffs-column-content-width);
3232
left: var(--diffs-column-number-width);
33-
padding-left: 8px;
33+
padding-inline-start: 8px;
3434
user-select: none;
3535
cursor: default;
36-
text-align: left;
36+
text-align: start;
3737

3838
[data-slot="diff-hunk-separator-content-span"] {
3939
mix-blend-mode: var(--text-mix-blend-mode);

‎packages/ui/src/components/markdown.css‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@
6060
ol {
6161
margin-top: 0.5rem;
6262
margin-bottom: 1rem;
63-
margin-left: 0;
64-
padding-left: 1.5rem;
63+
margin-inline-start: 0;
64+
padding-inline-start: 1.5rem;
6565
list-style-position: outside;
6666
}
6767

@@ -71,7 +71,7 @@
7171

7272
ol {
7373
list-style-type: decimal;
74-
padding-left: 2.25rem;
74+
padding-inline-start: 2.25rem;
7575
}
7676

7777
li {
@@ -97,18 +97,18 @@
9797
li > ol {
9898
margin-top: 0.25rem;
9999
margin-bottom: 0.25rem;
100-
padding-left: 1rem; /* Minimal indent for nesting only */
100+
padding-inline-start: 1rem; /* Minimal indent for nesting only */
101101
}
102102

103103
li > ol {
104-
padding-left: 1.75rem;
104+
padding-inline-start: 1.75rem;
105105
}
106106

107107
/* Blockquotes */
108108
blockquote {
109-
border-left: 2px solid var(--border-weak-base);
109+
border-inline-start: 2px solid var(--border-weak-base);
110110
margin: 1.5rem 0;
111-
padding-left: 0.5rem;
111+
padding-inline-start: 0.5rem;
112112
color: var(--text-weak);
113113
font-style: normal;
114114
}
@@ -240,7 +240,7 @@
240240
/* Minimal borders for structure, matching TUI "lines" roughly but keeping it web-clean */
241241
border-bottom: 1px solid var(--border-weaker-base);
242242
padding: 0.75rem 0.5rem;
243-
text-align: left;
243+
text-align: start;
244244
vertical-align: top;
245245
}
246246

‎packages/ui/src/components/message-nav.css‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
display: flex;
44
flex-direction: column;
55
align-items: flex-start;
6-
padding-left: 0;
6+
padding-inline-start: 0;
77
list-style: none;
88

99
&[data-size="normal"] {
@@ -77,7 +77,7 @@
7777
overflow: hidden;
7878
text-overflow: ellipsis;
7979
min-width: 0;
80-
text-align: left;
80+
text-align: start;
8181

8282
&[data-active] {
8383
color: var(--text-strong);

‎packages/ui/src/components/message-part.css‎

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
gap: 8px;
3131
width: fit-content;
3232
max-width: min(82%, 64ch);
33-
margin-left: auto;
33+
margin-inline-start: auto;
3434
}
3535

3636
[data-slot="user-message-attachment"] {
@@ -115,7 +115,7 @@
115115
[data-slot="user-message-body"] {
116116
width: fit-content;
117117
max-width: min(82%, 64ch);
118-
margin-left: auto;
118+
margin-inline-start: auto;
119119
display: flex;
120120
flex-direction: column;
121121
align-items: flex-end;
@@ -167,7 +167,7 @@
167167

168168
[data-slot="user-message-meta"] {
169169
user-select: none;
170-
text-align: right;
170+
text-align: end;
171171
flex: 1 1 auto;
172172
min-width: 0;
173173
overflow: hidden;
@@ -189,7 +189,7 @@
189189
user-select: none;
190190
flex: 0 0 auto;
191191
white-space: nowrap;
192-
text-align: right;
192+
text-align: end;
193193
}
194194

195195
&:hover [data-slot="user-message-copy-wrapper"],
@@ -488,8 +488,8 @@
488488
text-overflow: ellipsis;
489489
overflow: hidden;
490490
white-space: nowrap;
491-
direction: rtl;
492-
text-align: left;
491+
direction: rtl; /* truncate-start: shows end of file path */
492+
text-align: left; /* override RTL alignment for short paths */
493493
}
494494

495495
[data-slot="message-part-filename"] {
@@ -637,9 +637,9 @@
637637

638638
[data-component="context-tool-group-list"] {
639639
padding-top: 6px;
640-
padding-right: 0;
640+
padding-inline-end: 0;
641641
padding-bottom: 4px;
642-
padding-left: 13px;
642+
padding-inline-start: 13px;
643643
display: flex;
644644
flex-direction: column;
645645
gap: 8px;
@@ -815,8 +815,7 @@
815815
gap: 8px;
816816

817817
[data-component="button"] {
818-
padding-left: 12px;
819-
padding-right: 12px;
818+
padding-inline: 12px;
820819
}
821820
}
822821
}
@@ -950,7 +949,7 @@
950949
border: 1px solid var(--border-weak-base);
951950
border-radius: 6px;
952951
box-shadow: none;
953-
text-align: left;
952+
text-align: start;
954953
width: 100%;
955954
cursor: pointer;
956955
transition:
@@ -1066,7 +1065,7 @@
10661065
}
10671066

10681067
[data-slot="question-custom-input-wrap"] {
1069-
padding-left: 36px;
1068+
padding-inline-start: 36px;
10701069
}
10711070

10721071
[data-slot="question-custom-input"] {
@@ -1196,8 +1195,8 @@
11961195
text-overflow: ellipsis;
11971196
overflow: hidden;
11981197
white-space: nowrap;
1199-
direction: rtl;
1200-
text-align: left;
1198+
direction: rtl; /* truncate-start: shows end of file path */
1199+
text-align: left; /* override RTL alignment for short paths */
12011200
}
12021201

12031202
[data-slot="apply-patch-filename"] {

‎packages/ui/src/components/session-review.css‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@
119119
text-overflow: ellipsis;
120120
overflow: hidden;
121121
white-space: nowrap;
122-
direction: rtl;
123-
text-align: left;
122+
direction: rtl; /* truncate-start: shows end of file path */
123+
text-align: left; /* override RTL alignment for short paths */
124124
}
125125

126126
[data-slot="session-review-filename"] {

‎packages/ui/src/components/session-turn.css‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,8 @@
179179
overflow: hidden;
180180
text-overflow: ellipsis;
181181
white-space: nowrap;
182-
direction: rtl;
183-
text-align: left;
182+
direction: rtl; /* truncate-start: shows end of file path */
183+
text-align: left; /* override RTL alignment for short paths */
184184
}
185185

186186
[data-slot="session-turn-diff-filename"] {

‎packages/ui/src/components/tool-error-card.css‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616

1717
[data-slot="tool-error-card-content"] {
1818
position: relative;
19-
padding-left: 24px;
19+
padding-inline-start: 24px;
2020
margin-bottom: 8px;
2121
-webkit-user-select: text;
2222
user-select: text;
2323
}
2424

2525
> [data-component="collapsible"].tool-collapsible[data-open="true"] [data-slot="tool-error-card-content"] {
26-
padding-right: 40px;
26+
padding-inline-end: 40px;
2727
}
2828

2929
[data-slot="tool-error-card-copy"] {

0 commit comments

Comments
 (0)