mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-11-30 16:39:33 +01:00
fix(web): decide the history notice per replay move and drop unused anchor fields (#814)
- Content-anchored replay travel reveals the notice on an upward move that reaches row 0 and retires it on a downward move back at live output, as a live scroll does. - _captureViewportAnchor returns only viewportY, rowsFromBottom and context; tests read anchor.context.
This commit is contained in:
1 parent
1f9b17e29a
commit
a692f9f193
5 files changed
+38
-22
No files matched your search
@@ -4,7 +4,7 @@ import { chromium, type Browser, type BrowserContext, type Page } from 'playwrig
|
||||
import type { Terminal } from '@xterm/xterm';
|
||||
import { WebServer } from '../src/web/server.js';
|
||||
|
||||
type Anchor = { signature: string[]; offset: number; viewportY: number; rowsFromBottom: number };
|
||||
type Anchor = { context: string[]; viewportY: number; rowsFromBottom: number };
|
||||
type HistoryApp = {
|
||||
terminal: Terminal & {
|
||||
_core?: { _renderService?: { dimensions?: { css?: { cell?: { height: number } } } } };
|
||||
@@ -293,11 +293,13 @@ async function bufferState(page: Page) {
|
||||
(_, i) => buffer.getLine(i)?.translateToString(true).trim() || ''
|
||||
);
|
||||
const anchor = w.repairTest.anchor;
|
||||
// The first non-blank visible row the anchor captured, and where it sat.
|
||||
const anchorRow = anchor ? anchor.context.findIndex((text) => text.trim()) : -1;
|
||||
return {
|
||||
numbers: rows.filter((row) => /^NUMBER-\d+$/.test(row)),
|
||||
markerHits: rows.filter((row) => row.includes(marker)).length,
|
||||
anchorOffset: anchor ? rows.indexOf(anchor.signature[0]) - buffer.viewportY : null,
|
||||
expectedOffset: anchor?.offset,
|
||||
anchorOffset: anchor ? rows.indexOf(anchor.context[anchorRow]) - buffer.viewportY : null,
|
||||
expectedOffset: anchor ? anchorRow : undefined,
|
||||
pulls: w.repairTest.pulls,
|
||||
viewportY: buffer.viewportY,
|
||||
baseY: buffer.baseY,
|
||||
|
||||
@@ -815,6 +815,23 @@ describe('manual full-history recovery while reading (#814)', () => {
|
||||
expect(app._maybeRefetchFullHistory).toHaveBeenCalledOnce();
|
||||
});
|
||||
|
||||
it.each([
|
||||
{ moves: [-10000, 3], revealed: 's1', row: 3 },
|
||||
{ moves: [-10000, 10000], revealed: null, row: 370 },
|
||||
])('decides the notice per replay move like a live scroll: $moves', async ({ moves, revealed, row }) => {
|
||||
const { app, active, liveOutput, reload, pauseReplay } = makeScrollApp();
|
||||
liveOutput();
|
||||
const paused = pauseReplay();
|
||||
const pull = reload();
|
||||
await paused.ready;
|
||||
for (const move of moves) (mixin._maybeLoadMoreHistoryOnScroll as Function).call(app, move);
|
||||
paused.release();
|
||||
await pull;
|
||||
expect(active.viewportY).toBe(row);
|
||||
expect(app._setHistoryNoticeRevealed).toHaveBeenLastCalledWith(revealed);
|
||||
expect(app._maybeRefetchFullHistory).toHaveBeenCalledOnce();
|
||||
});
|
||||
|
||||
it('does not reveal the truncation notice on reload without replay travel', async () => {
|
||||
const { app, liveOutput, reload, pauseReplay } = makeScrollApp();
|
||||
liveOutput();
|
||||
@@ -1056,7 +1073,7 @@ describe('content anchors hold the reader through a history repair', () => {
|
||||
return { app, active, capture, restore };
|
||||
}
|
||||
|
||||
it('keeps a three-row signature at its viewport offset when rows are inserted below the reader', () => {
|
||||
it('keeps the visible context at its viewport offset when rows are inserted below the reader', () => {
|
||||
const rows = Array.from({ length: 30 }, (_, i) => `row ${i}`);
|
||||
rows[5] = '';
|
||||
const { app, capture, restore } = fixture(rows);
|
||||
@@ -1065,7 +1082,7 @@ describe('content anchors hold the reader through a history repair', () => {
|
||||
expect(target).toBe(5);
|
||||
expect(app.terminal.scrollToLine).toHaveBeenCalledWith(5);
|
||||
expect(anchor.viewportY).toBe(5);
|
||||
expect(anchor.offset).toBe(1);
|
||||
expect(anchor.context).toEqual(['', 'row 6', 'row 7']);
|
||||
});
|
||||
|
||||
it('keeps the old viewport when two complete contexts match equally well', () => {
|
||||
@@ -1138,8 +1155,8 @@ describe('content anchors hold the reader through a history repair', () => {
|
||||
const anchor = capture();
|
||||
const next = Array(50_000).fill('other');
|
||||
if (kind === 'first-row-only') {
|
||||
next[25_100] = anchor.signature[0];
|
||||
next[24_800] = anchor.signature[0];
|
||||
next[25_100] = anchor.context[0];
|
||||
next[24_800] = anchor.context[0];
|
||||
}
|
||||
// Even a whole matching viewport outside the budget cannot extend the scan.
|
||||
next.splice(30_000, anchor.context.length, ...anchor.context);
|
||||
|
||||
Reference in new issue
Block a user