Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions src/static/css/pad.css
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ input {
.history-banner {
display: flex;
align-items: center;
gap: 12px;
flex-wrap: wrap;
gap: 4px 12px;
padding: 10px 16px;
background: #fff8e1;
border-bottom: 1px solid #f0d27a;
Expand All @@ -135,8 +136,23 @@ input {
}
.history-banner[hidden] { display: none; }
.history-banner-label { font-weight: 600; }
.history-banner-label,
.history-banner-rev,
.history-banner-date { opacity: 0.85; }
.history-banner-date { opacity: 0.85; white-space: nowrap; }
.history-banner-authors {
opacity: 0.85;
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
/* Narrow screens: the banner's other segments fill the first row; give the
* authors their own full-width row so they are not squeezed to a sliver. */
@media (max-width: 600px) {
.history-banner-authors {
flex: 1 1 100%;
}
}
.history-banner #history-banner-return { margin-left: auto; }

/* The history iframe takes the place of the live ACE editor by occupying the
Expand Down
49 changes: 45 additions & 4 deletions src/static/js/pad_mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,11 @@ class PadModeController {
private mount: HTMLElement;
private revLabel: HTMLElement;
private dateLabel: HTMLElement;
private bannerAuthors: HTMLElement;
private padId: string;
private innerHashChangeHandler: (() => void) | null = null;
private revObserver: MutationObserver | null = null;
private authorsObserver: MutationObserver | null = null;
// Watches the embedded slider's #ui-slider-bar so saved revisions added live
// (NEW_SAVEDREV from a collaborator while we're in history mode) get mirrored
// onto the outer slider — clientVars only carries the entry-time snapshot.
Expand All @@ -75,6 +77,7 @@ class PadModeController {
this.mount = document.getElementById('history-frame-mount')!;
this.revLabel = document.getElementById('history-banner-rev')!;
this.dateLabel = document.getElementById('history-banner-date')!;
this.bannerAuthors = document.getElementById('history-banner-authors')!;
// /p/:pad → ['', 'p', ':pad'].
const parts = window.location.pathname.split('/').filter(Boolean);
this.padId = decodeURIComponent(parts[parts.length - 1] || '');
Expand Down Expand Up @@ -198,6 +201,7 @@ class PadModeController {
}
this.revLabel.textContent = '';
this.dateLabel.textContent = '';
this.bannerAuthors.textContent = '';
const stars = document.getElementById('history-slider-stars');
if (stars) {
stars.replaceChildren();
Expand Down Expand Up @@ -257,6 +261,10 @@ class PadModeController {
this.revObserver.disconnect();
this.revObserver = null;
}
if (this.authorsObserver) {
this.authorsObserver.disconnect();
this.authorsObserver = null;
}
if (this.savedRevObserver) {
this.savedRevObserver.disconnect();
this.savedRevObserver = null;
Expand Down Expand Up @@ -328,6 +336,26 @@ class PadModeController {
};
registerHook();

// The banner authors also change without a slider callback: html10n
// translates the label asynchronously, and live NEW_CHANGES /
// NEW_AUTHORDATA rewrite #authorsList while the slider is parked
// (broadcast.ts setAuthors). Mirror those the same way revObserver
// mirrors the revision label.
const authorsObserver = new MutationObserver(() => { this.syncAuthorsPanel(win); });
const innerAuthorsList = doc.getElementById('authorsList');
if (innerAuthorsList) {
authorsObserver.observe(
innerAuthorsList, {childList: true, subtree: true, characterData: true});
}
const innerAuthorsLabel = doc.querySelector('.authors-label');
if (innerAuthorsLabel) {
authorsObserver.observe(
innerAuthorsLabel, {childList: true, subtree: true, characterData: true});
}
// Unlike revObserver, this observer is per-mount: keep it in a field so
// unmountIframe can disconnect it when the iframe is torn down.
this.authorsObserver = authorsObserver;

this.snapshotForHistory();
this.wireSettingsBridges(win);
this.wireHistoryControls(win);
Expand Down Expand Up @@ -556,13 +584,26 @@ class PadModeController {
}

// Mirror the inner timeslider's #authorsList (rendered by broadcast.ts)
// into the outer users panel. We replace the live user table while in
// history mode and restore it on exit.
// into the outer users panel and the history banner. The banner is the
// only always-visible carrier: the embedded slider bar is collapsed and
// the users popup is closed by default (ether/etherpad#8593). We replace
// the live user table while in history mode and restore it on exit.
private syncAuthorsPanel(innerWin: Window): void {
const innerAuthors = (innerWin.document as Document).getElementById('authorsList');
const tbl = document.getElementById('otheruserstable');
if (!innerAuthors || !tbl) return;
if (!innerAuthors) return;
const text = innerAuthors.textContent || '';
const innerLabel = (innerWin.document as Document).querySelector<HTMLElement>('.authors-label');
const label = innerLabel?.textContent || '';
const bannerText = (label ? `${label} ` : '') + text;
// Equality guard: syncAuthorsPanel runs on every slider step AND on every
// inner #authorsList mutation; skip redundant writes so the banner's
// aria-live=polite region doesn't re-announce identical text during
// playback or unrelated DOM churn.
if (this.bannerAuthors.textContent !== bannerText) {
this.bannerAuthors.textContent = bannerText;
}
const tbl = document.getElementById('otheruserstable');
if (!tbl || tbl.textContent === text) return;
tbl.innerHTML = '';
const tr = document.createElement('tr');
const td = document.createElement('td');
Expand Down
1 change: 1 addition & 0 deletions src/templates/pad.html
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@
<span class="history-banner-label" data-l10n-id="pad.historyMode.banner">Viewing history</span>
<span class="history-banner-rev" id="history-banner-rev"></span>
<span class="history-banner-date" id="history-banner-date"></span>
<span class="history-banner-authors" id="history-banner-authors"></span>
<button type="button" id="history-banner-return" class="btn btn-primary"
data-l10n-id="pad.historyMode.return">Return to live</button>
</div>
Expand Down
110 changes: 110 additions & 0 deletions src/tests/frontend-new/specs/timeslider_banner_authors.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import {expect, Page, test} from "@playwright/test";
import {
clearPadContent,
goToNewPad,
setUserName,
toggleUserList,
writeToPad,
} from "../helper/padHelper";

// The classic timeslider page showed an "Authors: ..." line right under the
// slider. Since in-pad history mode (#7659/#7710) the inner slider bar is
// collapsed and the only mirror lives in the closed users popup, so the
// authors of the viewed revision became invisible (ether/etherpad#8593).
// The history banner must surface them again — including when the inner
// timeslider updates without a slider callback (a collaborator editing
// while the history slider is parked).
test.describe('history banner authors', function () {
test.describe.configure({mode: 'serial'});
test.use({locale: 'en-US'});

test.beforeEach(async ({context}) => {
await context.clearCookies();
});

const enterHistoryMode = async (page: Page) => {
await page.click('.buttonicon-history');
await page.waitForSelector('#history-controls:not([hidden])', {state: 'visible'});
await page.waitForSelector('#history-frame');
};

const goToRevision = async (page: Page, rev: number) => {
await page.locator('#history-slider-input').evaluate((el, value) => {
(el as HTMLInputElement).value = String(value);
el.dispatchEvent(new Event('input', {bubbles: true}));
}, rev);
await expect(page.locator('#history-banner-rev')).toHaveText(`Version ${rev}`, {timeout: 15000});
};

const sliderMax = async (page: Page) => await page.locator('#history-slider-input').evaluate(
(el) => Number((el as HTMLInputElement).max));

test('banner shows the authors of the viewed revision', async function ({page}) {
await goToNewPad(page);
await clearPadContent(page);

await toggleUserList(page);
await setUserName(page, 'Alice');
await toggleUserList(page);
await writeToPad(page, 'Hello from Alice');

await enterHistoryMode(page);
// max >= 2 proves the write landed (rev 1 = cleared default, rev 2 = Alice's text).
await expect.poll(async () => await sliderMax(page), {timeout: 15000}).toBeGreaterThanOrEqual(2);
const maxRev = await sliderMax(page);

await goToRevision(page, maxRev);
await expect(page.locator('#history-banner-authors')).toContainText('Alice');

// Leaving history mode must clear the banner authors.
await page.click('#history-banner-return');
await expect(page.locator('#history-banner-authors')).toHaveText('');
});

test('banner follows async updates to the embedded slider authors list', async function ({page}) {
await goToNewPad(page);
await clearPadContent(page);

await toggleUserList(page);
await setUserName(page, 'Alice');
await toggleUserList(page);
await writeToPad(page, 'Hello from Alice');

await enterHistoryMode(page);
await expect.poll(async () => await sliderMax(page), {timeout: 15000}).toBeGreaterThanOrEqual(2);
await expect(page.locator('#history-banner-authors')).toContainText('Alice');

// The embedded timeslider's authors DOM also changes outside slider
// callbacks (html10n translating the label, broadcast.ts setAuthors on
// live NEW_AUTHORDATA-style refreshes). The outer banner must follow —
// it may not wait for the next scrub.
const frame = page.frames().find((f) => f.url().includes('/timeslider'))!;
await frame.evaluate(() => {
const list = document.getElementById('authorsList')!;
const span = document.createElement('span');
span.className = 'author';
span.textContent = 'Bob';
list.appendChild(span);
});
await expect(page.locator('#history-banner-authors')).toContainText('Bob', {timeout: 10000});
});

test('banner stays readable at mobile width', async function ({page}) {
await page.setViewportSize({width: 390, height: 667});
await goToNewPad(page);

await page.click('.buttonicon-history');
await page.waitForSelector('#history-controls:not([hidden])', {state: 'visible'});
await page.waitForSelector('#history-frame');

// The banner must not push the page into horizontal scroll.
const overflow = await page.evaluate(
() => document.documentElement.scrollWidth - document.documentElement.clientWidth);
expect(overflow).toBeLessThanOrEqual(0);
// The authors segment must keep a readable width instead of being
// squeezed to a sliver between the date and the return button.
const authorsWidth = await page.locator('#history-banner-authors').evaluate(
(el) => el.getBoundingClientRect().width);
expect(authorsWidth).toBeGreaterThanOrEqual(150);
});
});