fix: set dir="auto" after the linkifier so code-only documents stay linear (release review)

`_renderMarkdown` wrote dir="auto" into its string, before the code pins and
the linkifier. An element carrying dir="auto" re-resolves its direction on
every insertion under it, and a block whose letters all sit in `dir` children
walks its whole subtree each time, so a code-only or path-only document went
quadratic, English ones included.

Measured in real Chromium through the real File Viewer, before and after:
9000 inline-code items 8.7 s to 0.35 s, 9000 bare paths 5.6 s to 0.23 s, a
209 KB out-of-workspace list 41.9 s to 1.4 s. All three now match master.

The pass is now `_applyBlockDirection()`, run last on the DOM by both
consumers. The direction results are unchanged. Tests pin that the rendered
string holds no dir="auto" and that the pass runs after the linkifier.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Codeman maintainer committed 2026-11-06 04:49:02 +01:00
1 parent f37f101137
commit 4413240c5f
4 files changed
+89 -27

No files matched your search

+14
View File
@@ -151,6 +151,7 @@ function loadApp(prefs: Record<string, string> = {}) {
app.filePreviewContent = '';
app._renderMarkdown = vi.fn(() => MARKDOWN_HTML);
app._linkifyFilePaths = vi.fn();
app._applyBlockDirection = vi.fn();
app._bindResponseViewerInteractions = vi.fn();
const byId = (id: string) => document.getElementById(id) as HTMLButtonElement;
@@ -177,6 +178,11 @@ describe('file viewer rendered markdown', () => {
expect(app._renderMarkdown).toHaveBeenCalledWith(MD_CONTENT, { breaks: false });
// Identity, not deep equality: DOM nodes are compared by reference here.
expect(app._linkifyFilePaths.mock.calls[0][0]).toBe(doc);
// After the linkifier: a dir="auto" block re-resolves on every insertion under it (#715).
expect(app._applyBlockDirection.mock.calls[0][0]).toBe(doc);
expect(app._applyBlockDirection.mock.invocationCallOrder[0]).toBeGreaterThan(
app._linkifyFilePaths.mock.invocationCallOrder[0]
);
expect(app._bindResponseViewerInteractions.mock.calls[0][0]).toBe(body);
// The source stays what Copy copies.
expect(app.filePreviewContent).toBe(MD_CONTENT);
@@ -463,6 +469,14 @@ describe('file viewer markdown line breaks', () => {
expect(chatPara.querySelectorAll('br')).toHaveLength(1);
expect(chatPara.textContent).toBe(WRAPPED.replace('\n', ''));
});
it('lets a document read right to left through the shipped viewer (#715)', async () => {
const app = loadShippingApp('سلام، این یک تست است.\n');
await app.openFilePreview('docs/README.md', 's1');
expect(document.querySelector('#filePreviewBody .file-preview-md p')?.getAttribute('dir')).toBe('auto');
});
});
describe('FILE_PREVIEW_EXTENSIONS', () => {