Skip to content

Commit a164a63

Browse files
JohnMcLearclaude
andcommitted
fix: RTL content option no longer flips the whole page (#7900)
The pad's RTL content option (rtlIsTrue) is a per-pad setting that should only change the direction of the editor's text contents. The setter in ace2_inner.ts wrote the direction to the top-level `document.documentElement` (`document` there resolves to the main pad page, since the editor iframes are derived from it), which flipped the entire page — toolbar and chrome included. The page direction is owned solely by the UI language (l10n.ts sets it from html10n.getDirection()). Apply the content direction to the inner editor document (`targetDoc.documentElement`) instead, so enabling RTL content leaves the surrounding interface untouched. Adds a frontend test asserting the inner editor flips to RTL while the top-level <html> dir stays ltr. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 0110d88 commit a164a63

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

src/static/js/ace2_inner.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,11 @@ function Ace2Inner(editorInfo, cssManagers) {
683683
rtlistrue: (value) => {
684684
targetBody.classList.toggle('rtl', value);
685685
targetBody.classList.toggle('ltr', !value);
686-
document.documentElement.dir = value ? 'rtl' : 'ltr';
686+
// Apply the base direction to the inner editor document only. Using the
687+
// top-level `document` here would flip the whole page (toolbar, chrome)
688+
// even though this is a per-pad content option — see issue #7900. The
689+
// page direction is governed solely by the UI language (see l10n.ts).
690+
targetDoc.documentElement.dir = value ? 'rtl' : 'ltr';
687691
},
688692
fadeinactiveauthorcolors: (value) => {
689693
fadeInactiveAuthorColors = `${value}` !== 'false';

src/tests/frontend-new/specs/rtl_url_param.spec.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,20 @@ test.describe('RTL URL parameter', function () {
3434
await page.waitForSelector('#editorcontainer.initialized');
3535
await expect(page.locator('#options-rtlcheck')).not.toBeChecked();
3636
});
37+
38+
test('rtl content option flips only the pad inner contents, not the whole page', {tag: '@feature:rtl-toggle'}, async function ({page}) {
39+
await appendQueryParams(page, {rtl: 'true'});
40+
await expect(page.locator('#options-rtlcheck')).toBeChecked();
41+
42+
// The inner editor document is flipped to RTL...
43+
const innerBody = page.frame('ace_inner')!.locator('#innerdocbody');
44+
await expect(innerBody).toHaveClass(/\brtl\b/);
45+
const innerDirection = await innerBody.evaluate((el) =>
46+
el.ownerDocument.defaultView!.getComputedStyle(el).direction);
47+
expect(innerDirection).toBe('rtl');
48+
49+
// ...but the top-level page (toolbar, chrome) is governed by the UI
50+
// language, not the pad's RTL content option, and must stay LTR.
51+
await expect(page.locator('html')).toHaveAttribute('dir', 'ltr');
52+
});
3753
});

0 commit comments

Comments
 (0)