Merge relprep/rtl fix(response-viewer): lay out Persian, Arabic and Hebrew right to left (#715)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Codeman maintainer committed 2026-11-06 05:02:36 +01:00
commit cddfc07550
13 files changed
+320 -14

No files matched your search

+39
View File
@@ -2847,6 +2847,14 @@ class CodemanApp {
a.setAttribute('target', '_blank');
a.setAttribute('rel', 'noopener noreferrer');
});
// Code and preformatted text are always left to right. `dir="ltr"`
// also isolates them, and `dir="auto"` skips any descendant that
// carries a `dir`, so `npm install` at the head of a Persian sentence
// no longer turns the whole sentence left to right (issue #715). The
// `dir="auto"` itself is `_applyBlockDirection`'s, never this string's.
tmpl.content.querySelectorAll('pre, code').forEach((el) => {
if (!el.hasAttribute('dir')) el.setAttribute('dir', 'ltr');
});
return tmpl.innerHTML;
} catch { /* fall through */ }
}
@@ -3004,10 +3012,38 @@ class CodemanApp {
renderedText.className = 'rv-text';
renderedText.innerHTML = this._renderMarkdown(text);
this._linkifyFilePaths(renderedText);
this._applyBlockDirection(renderedText);
div.appendChild(renderedText);
return div;
}
/**
* Right-to-left text (issue #715). With no `dir`, every block was laid out
* left to right, so a Persian, Arabic or Hebrew answer was left-aligned, its
* punctuation landed on the wrong end and its lists and quotes hung off the
* left edge. Each OUTERMOST prose block now takes its direction from its own
* first letter (`dir="auto"`, what GitHub does for rendered markdown), so an
* RTL paragraph beside an English one reads correctly in both; nested blocks
* inherit, which keeps a list's markers and indent on one side. A `dir` the
* agent wrote (the sanitizer allows it) is kept, and so is what it covers.
*
* ⚠️ Call this LAST, on the DOM, once nothing else inserts under `root`: an
* element that already carries `dir="auto"` re-resolves its direction on every
* insertion beneath it, and a block whose letters all sit in `dir` children
* (a code-only or path-only list) walks its whole subtree each time. Set
* during `_renderMarkdown` or before the linkifier, that made rendering
* quadratic, for English documents too: a 200 KB list of inline code froze
* the tab for 40 s. Not part of `_linkifyFilePaths`, which returns early when
* a stale constants.js has no `findFilePathLinks`.
*/
_applyBlockDirection(root) {
if (!root) return;
for (const el of root.querySelectorAll('p, h1, h2, h3, h4, h5, h6, ul, ol, dl, blockquote, .rv-table-wrap')) {
if (el.parentElement?.closest('[dir]') || el.hasAttribute('dir')) continue;
el.setAttribute('dir', 'auto');
}
}
/**
* Make file paths in a rendered message clickable: absolute, `~/` and
* relative ones (`findFilePathLinks`, constants.js).
@@ -3108,6 +3144,9 @@ class CodemanApp {
link.dataset.path = path;
link.dataset.linkified = '1';
if (folder) link.dataset.folder = '1';
// A path reads left to right, and in a right-to-left sentence it must
// not vote on the sentence's direction (`_applyBlockDirection`, issue #715).
link.dir = 'ltr';
link.title = path;
link.textContent = path;
frag.appendChild(link);
+3 -1
View File
@@ -1371,7 +1371,7 @@ const KeyboardAccessoryBar = {
<strong>Compose prompt</strong>
<span>Enter adds a new line</span>
</div>
<textarea class="paste-textarea prompt-composer-textarea" aria-label="Prompt" placeholder="Write your prompt…" autocorrect="on" autocapitalize="sentences" spellcheck="true"></textarea>
<textarea class="paste-textarea prompt-composer-textarea" dir="auto" aria-label="Prompt" placeholder="Write your prompt…" autocorrect="on" autocapitalize="sentences" spellcheck="true"></textarea>
<div class="paste-actions prompt-composer-actions">
<button type="button" class="prompt-composer-terminal">Use terminal keyboard</button>
<button type="button" class="paste-image">📎 Attach</button>
@@ -1384,6 +1384,8 @@ const KeyboardAccessoryBar = {
this._composerOverlay = overlay;
const textarea = overlay.querySelector('.prompt-composer-textarea');
// The textarea's dir="auto" lays a prompt written in Persian, Arabic or
// Hebrew out right to left, from its first letter (#715).
// i18n.js skips <textarea> subtrees (what is typed there is user content),
// so the placeholder and label are translated here, when the dialog is built.
const i18n = typeof window !== 'undefined' ? window.CodemanI18n : undefined;
+1
View File
@@ -5138,6 +5138,7 @@ Object.assign(CodemanApp.prototype, {
const doc = tmpl.content.firstElementChild;
this._rebaseFilePreviewMarkdownRefs(doc, info);
this._linkifyFilePaths(doc);
this._applyBlockDirection(doc);
// The linkifier's absolute paths name no session; give them the
// preview's, like the rebased links, or they open in the active tab's.
for (const a of doc.querySelectorAll('a.rv-path:not([data-session-id])')) a.dataset.sessionId = info.sessionId;
+10 -6
View File
@@ -15251,7 +15251,7 @@ html:is([data-skin="paper-gray"], [data-skin="solarized-light"], [data-skin="cat
.rv-text ul, .rv-text ol,
.response-viewer-body > ul, .response-viewer-body > ol {
margin: 0.6em 0;
padding-left: 1.5em;
padding-inline-start: 1.5em;
}
.rv-text li,
@@ -15263,12 +15263,16 @@ html:is([data-skin="paper-gray"], [data-skin="solarized-light"], [data-skin="cat
.rv-text blockquote,
.response-viewer-body > blockquote {
border-left: 3px solid var(--accent);
border-inline-start: 3px solid var(--accent);
background: rgba(var(--accent-rgb), 0.06);
margin: 0.8em 0;
padding: 0.5em 14px;
color: var(--text-dim);
border-radius: 0 6px 6px 0;
/* Logical corners: the bar sits on the start side, right-to-left too (#715). */
border-start-start-radius: 0;
border-end-start-radius: 0;
border-start-end-radius: 6px;
border-end-end-radius: 6px;
}
.rv-text strong,
@@ -15338,9 +15342,9 @@ html:is([data-skin="paper-gray"], [data-skin="solarized-light"], [data-skin="cat
.response-viewer-body > table td,
.rv-table-wrap th, .rv-table-wrap td {
border-bottom: 1px solid var(--border);
border-right: 1px solid var(--border);
border-inline-end: 1px solid var(--border);
padding: 8px 12px;
text-align: left;
text-align: start;
vertical-align: top;
white-space: normal;
}
@@ -15349,7 +15353,7 @@ html:is([data-skin="paper-gray"], [data-skin="solarized-light"], [data-skin="cat
.response-viewer-body > table th:last-child,
.response-viewer-body > table td:last-child,
.rv-table-wrap th:last-child, .rv-table-wrap td:last-child {
border-right: none;
border-inline-end: none;
}
.rv-text tr:last-child td,