Files
orca/config/patches/xterm-src/@xterm__addon-serialize@0.15.0-beta.300.src.patch
Neil e84042572c Upgrade xterm to 6.1.0-beta.303 and generate addon patches
* Upgrade xterm to 6.1.0-beta.303 and generate the addon patches

Takes the current xterm beta line: xterm 287 -> 303, addon-webgl 286 -> 299,
addon-serialize 287 -> 300, headless 302, the remaining addons -> 300, and the
same set on mobile. All four packages stamp upstream commit d3e32b3.

The reasons are upstream #6042/#6043/#6055 (a shared glyph atlas no longer
garbles sibling panes on a page merge, clear, or sampler-budget overflow) and
Note that core 303 is not image-addon-only over 302: it carries the buffer perf
work, including the new BufferLineStringCache.

addon-webgl and addon-serialize move into the patch generator
--------------------------------------------------------------
Both were hand-edited minified bundles, which is what the Known Gaps section of
docs/reference/xterm-patch-regeneration.md described. Both reproduce byte for
byte from the pinned commit, so they are now manifest entries generated from a
source patch like @xterm/xterm already was. Their sourcemaps now move with their
bundles; before this they shipped maps whose offsets did not match the code
beside them.

The webgl patch shrinks from a 1.06 MB hand-edited bundle to a 6.6 KB source
patch, because upstream took the invalidation half Orca had backported. What is
left is only what upstream still lacks: the fragment-shader else branch for a
v_texpage past the sampler budget, the clearTexture guard that no-ops once a
merged page holds index 0, spending the merge retry budget before beginFrame
latches the version it saw, and Orca's font-weight probe.

The serialize source patch is byte-for-byte the same fixes as before; upstream
changed nothing in that addon between 287 and 300.

Generator fixes, each of which failed silently
----------------------------------------------
- `--relative` was appended after the `--` separator in CHECKOUT_DIFF_FLAGS, so
  git read it as a pathspec and kept repo-root-relative paths, dropping every
  source hunk from an addon's patch.
- `git apply` run from a package subdirectory still resolves patch paths from
  the repo root, skips every hunk and exits 0. It now runs from the root with
  `--directory=<packageDir>`, and a source patch that leaves the checkout
  unchanged is a hard failure rather than an empty patch.
- An addon's own `tsgo -p .` has empty files/include and only project
  references, so it emits nothing and the addon webpack then fails on a missing
  ./out/. The root build now runs first.
- versionStampFile is optional; publish.js stamps an addon's package.json, which
  overlayBuildOutput never patches.
- On a version bump the lockfile has no entry under the new key yet, so --write
  reports the gap instead of aborting mid-run. --check still fails on it.

Adding the two addons pushed the generator and the Electron packaging contract
test over max-lines, so the patch-text helpers move to xterm-patch-text.mjs
(pure text: no checkout, no build) and the vendored-xterm assertions move out of
the packaging contract into xterm-webgl-runtime-contract.test.mjs.

Tests
-----
Four tests asserted upstream bugs that are now fixed, not Orca behaviour:

- xterm-user-scrolling-contract pinned headless and core by version string.
  Upstream bumps each package only when its own output changes, so headless 302
  and core 303 are the same source. It now asserts they share a commit.
- Five CSI 3 J assertions expected a reader stranded at the top after an erase.
  Upstream #6081 clears isUserScrolling there, so the erase releases them to the
  bottom instead. Orca's pin still lands them correctly, because its parser
  handler observes the erase before xterm's own handler runs.
- The IME transaction test hard-coded the xterm version; it now reads the
  installed package, since the point is that bundle, map and version agree.
- The Electron runtime contract asserted Orca's old clearModelGeneration. Shared
  atlas invalidation is upstream's now, so it asserts pageLayoutVersion on the
  resolved dependency, plus the Orca-only hunks on the patch.

Verified: 66,008 unit tests, mobile's 3,863, the four WebGL atlas e2e specs, and
`regenerate-xterm-patches.mjs --check` in sync on all three packages.

Left alone deliberately: resetAllTerminalWebglAtlases still fans out globally
even though clearTexture now self-heals siblings, and upstream #6068
(WebglAddon.dispose leaks the GL context) is still open.

* Drop the two unused WebGL atlas fan-out exports

resetAllTerminalWebglAtlases and presentAllTerminalPanesWithoutAtlasClear have
no callers, and had none at cadfc55102 either — the last call site went in
#6949, which routed reveal recovery through
resetAndRefreshAllTerminalWebglAtlases instead. Only a comment in
pane-manager.ts still named the first one; it now points at the live entry
point. scheduleRevealPresent leaves the registry's structural type with them,
though the manager method stays: terminal-visibility-resume.ts calls it
directly.

This is dead-code removal, not a consequence of the xterm bump. The live
recovery path is unchanged.

resetAndRefreshAllTerminalWebglAtlases stays, and so does the reveal-time
escalation in pane-reveal-repaint.ts. Upstream 299 does make a pane-local
clearTexture bump pageLayoutVersion so siblings rebuild on their next frame,
which is the bug the escalation was written for, but I could not demonstrate
that removing it is safe: with the escalation removed,
floating-workspace-shared-glyph-atlas.spec.ts still passed headful, and it also
passed with upstream's mechanism deliberately disabled (pageLayoutVersion
pinned to 0 in the installed bundle, verified present in the built renderer).
A guard that passes with the fix disabled cannot license removing the
workaround, so the escalation stays until that spec can reproduce the garbling.

Verified: pane-manager and terminal-pane suites (4,713 tests), typecheck, the
headful shared-atlas spec, and the three headless WebGL specs.

* Give the shared glyph atlas spec a trigger that can fail

floating-workspace-shared-glyph-atlas.spec.ts guards the corruption where one
terminal wiping the module-global atlas leaves sibling terminals drawing from
stale texture coordinates. Both of its tests drive that through a floating
panel reveal, and Orca's reveal paths escalate to a registry-wide atlas reset
that repaints every pane — so the recovery under test heals the damage before
the assertion runs, and the tests pass whether or not xterm propagates the
invalidation at all.

The new test clears the shared atlas straight through the floating manager with
the panel closed, so nothing else repaints the workspace terminal, then repaints
it with terminal.refresh(). That is the load-bearing detail: _updateModel skips
cells whose content is unchanged, so the refresh reuses vertices baked against
the pages that were just wiped, which is exactly the state the fix has to
recover from.

Verified as a discriminator rather than assumed. Pinning ITextureAtlas's
pageLayoutVersion getter to 0 in the installed bundle, which disables the
per-renderer invalidation upstream added in addon-webgl 0.20.0-beta.299, and
confirming that reached the built renderer:

  fix intact:   siblingClearIntact=true   1 passed
  fix disabled: siblingClearIntact=false  1 failed

The failure renders the workspace terminal completely blank — stale coordinates
into a wiped atlas sample nothing. The two reveal tests pass unchanged in both
configurations, which is the gap this closes.

* Compare shared-atlas screenshots with tolerance instead of byte equality

Byte equality fails on sub-pixel antialiasing noise that leaves every glyph
legible, so the headful spec flaked under xterm 303. Reuse the existing
compareTerminalScreenshots helper: real stale-model corruption blanks the
terminal at ~3% of pixels, twice the helper's 1.5% threshold, so the looser
oracle keeps its teeth. Log the ratio so failures are diagnosable.

* fix(xterm): cancel empty deferred IME compositions

* test(xterm): strengthen runtime patch contracts
2026-08-30 15:14:49 -07:00

213 lines
9.5 KiB
Diff

diff --git a/src/SerializeAddon.ts b/src/SerializeAddon.ts
index e1728feb219c362dfa2ecb602ff99f830d520757..957da98c8b30835cc2d114b4b66b228b01fdff0a 100644
--- a/src/SerializeAddon.ts
+++ b/src/SerializeAddon.ts
@@ -12,6 +12,36 @@ import { IAttributeData } from 'common/buffer/Types';
import { DEFAULT_ANSI_COLORS } from 'browser/Types';
import { UnderlineStyle } from 'common/buffer/Constants';
+type OscLinkData = { id?: string; uri: string };
+type OscLinkedCell = { extended?: { urlId?: number } };
+type TerminalWithOscLinks = Terminal & {
+ _core?: {
+ _inputHandler?: { _curAttrData?: IAttributeData & OscLinkedCell };
+ _oscLinkService?: { getLinkData: (linkId: number) => OscLinkData | undefined };
+ };
+};
+
+function getOscLinkId(cell: IBufferCell | IAttributeData): number {
+ return (cell as typeof cell & OscLinkedCell).extended?.urlId ?? 0;
+}
+
+function getOscLinkOpenSequence(terminal: Terminal, linkId: number): string {
+ if (!linkId) {
+ return '';
+ }
+ const data = (terminal as TerminalWithOscLinks)._core?._oscLinkService?.getLinkData(linkId);
+ if (!data) {
+ return '';
+ }
+ const params = data.id === undefined ? '' : `id=${data.id}`;
+ return `\u001b]8;${params};${data.uri}\u001b\\`;
+}
+
+function getActiveOscLinkSequence(terminal: Terminal): string {
+ const attrs = (terminal as TerminalWithOscLinks)._core?._inputHandler?._curAttrData;
+ return attrs ? getOscLinkOpenSequence(terminal, getOscLinkId(attrs)) : '';
+}
+
function constrain(value: number, low: number, high: number): number {
return Math.max(low, Math.min(value, high));
}
@@ -148,12 +178,14 @@ class StringSerializeHandler extends BaseSerializeHandler {
// this is a null cell for reference for checking whether background is empty or not
private _backgroundCell: IBufferCell = this._buffer.getNullCell();
+ private _defaultCell: IBufferCell = this._buffer.getNullCell();
private _firstRow: number = 0;
private _lastCursorRow: number = 0;
private _lastCursorCol: number = 0;
private _lastContentCursorRow: number = 0;
private _lastContentCursorCol: number = 0;
+ private _activeOscLinkId: number = 0;
constructor(
buffer: IBuffer,
@@ -214,7 +246,7 @@ class StringSerializeHandler extends BaseSerializeHandler {
if (
// you must output character to cause overflow, control sequence can't do this
nextRowFirstChar.getChars() &&
- isNextRowFirstCharDoubleWidth ? this._nullCellCount <= 1 : this._nullCellCount <= 0
+ (isNextRowFirstCharDoubleWidth ? this._nullCellCount <= 1 : this._nullCellCount <= 0)
) {
if (
// the last character can't be null,
@@ -251,9 +283,14 @@ class StringSerializeHandler extends BaseSerializeHandler {
if (this._nullCellCount > 0) {
// do these because we filled the last several null slot, which we shouldn't
rowSeparator += '\u001b[A';
- rowSeparator += `\u001b[${currentLine.length - this._nullCellCount}C`;
+ const contentCellCount = currentLine.length - this._nullCellCount;
+ if (contentCellCount > 0) {
+ rowSeparator += `\u001b[${contentCellCount}C`;
+ }
rowSeparator += `\u001b[${this._nullCellCount}X`;
- rowSeparator += `\u001b[${currentLine.length - this._nullCellCount}D`;
+ if (contentCellCount > 0) {
+ rowSeparator += `\u001b[${contentCellCount}D`;
+ }
rowSeparator += '\u001b[B';
}
@@ -310,7 +347,20 @@ class StringSerializeHandler extends BaseSerializeHandler {
}
if (flagsChanged) {
if (cell.isInverse() !== oldCell.isInverse()) { sgrSeq.push(cell.isInverse() ? 7 : 27); }
- if (cell.isBold() !== oldCell.isBold()) { sgrSeq.push(cell.isBold() ? 1 : 22); }
+ // PATCH(orca): bold (1) and dim (2) share the single reset param 22, so
+ // they must be diffed as one intensity group with the clearing 22 emitted
+ // BEFORE any re-set. Upstream's independent per-flag diff could emit
+ // "1;22" (bold set, then wiped by dim's clear — \x1b[2mA\x1b[22m\x1b[1mB
+ // loses B's bold on round-trip) or a bare "22" that drops a still-set
+ // bold/dim, garbling Orca's hidden-terminal snapshot restores.
+ const boldChanged = cell.isBold() !== oldCell.isBold();
+ const dimChanged = cell.isDim() !== oldCell.isDim();
+ if (boldChanged || dimChanged) {
+ const clearsIntensity = (boldChanged && !cell.isBold()) || (dimChanged && !cell.isDim());
+ if (clearsIntensity) { sgrSeq.push(22); }
+ if (cell.isBold() && (boldChanged || clearsIntensity)) { sgrSeq.push(1); }
+ if (cell.isDim() && (dimChanged || clearsIntensity)) { sgrSeq.push(2); }
+ }
if (!equalUnderline(cell, oldCell)) {
const style = cell.getUnderlineStyle();
if (style === UnderlineStyle.NONE) {
@@ -337,7 +387,7 @@ class StringSerializeHandler extends BaseSerializeHandler {
if (cell.isBlink() !== oldCell.isBlink()) { sgrSeq.push(cell.isBlink() ? 5 : 25); }
if (cell.isInvisible() !== oldCell.isInvisible()) { sgrSeq.push(cell.isInvisible() ? 8 : 28); }
if (cell.isItalic() !== oldCell.isItalic()) { sgrSeq.push(cell.isItalic() ? 3 : 23); }
- if (cell.isDim() !== oldCell.isDim()) { sgrSeq.push(cell.isDim() ? 2 : 22); }
+ // PATCH(orca): dim handled in the intensity group above.
if (cell.isStrikethrough() !== oldCell.isStrikethrough()) { sgrSeq.push(cell.isStrikethrough() ? 9 : 29); }
}
}
@@ -346,6 +396,20 @@ class StringSerializeHandler extends BaseSerializeHandler {
return sgrSeq;
}
+ private _setOscLink(linkId: number): string {
+ if (linkId === this._activeOscLinkId) {
+ return '';
+ }
+ let sequence = this._activeOscLinkId ? '\u001b]8;;\u001b\\' : '';
+ this._activeOscLinkId = 0;
+ const openSequence = getOscLinkOpenSequence(this._terminal, linkId);
+ if (openSequence) {
+ this._activeOscLinkId = linkId;
+ sequence += openSequence;
+ }
+ return sequence;
+ }
+
protected _nextCell(cell: IBufferCell, oldCell: IBufferCell, row: number, col: number): void {
// a width 0 cell don't need to be count because it is just a placeholder after a CJK character;
const isPlaceHolderCell = cell.getWidth() === 0;
@@ -356,12 +420,21 @@ class StringSerializeHandler extends BaseSerializeHandler {
// this cell don't have content
const isEmptyCell = cell.getChars() === '';
+ const nextLine = isEmptyCell && cell.isInverse() ? this._buffer.getLine(row + 1) : undefined;
+ const nextRowFirstCell = nextLine?.getCell(0, this._nextRowFirstChar);
+ // A pending wide glyph recreates its own final-column padding during replay.
+ const isWideWrapPadding = col === this._terminal.cols - 1 &&
+ nextLine?.isWrapped &&
+ (nextRowFirstCell?.getWidth() ?? 0) > 1 &&
+ !!nextRowFirstCell && attributesEquals(cell, nextRowFirstCell);
+ // Cursor movement cannot reproduce an inverse cell's visible background.
+ const materializeEmptyCell = isEmptyCell && !!cell.isInverse() && !isWideWrapPadding;
const sgrSeq = this._diffStyle(cell, this._cursorStyle);
- // the empty cell style is only assumed to be changed when background changed, because
- // foreground is always 0.
- const styleChanged = isEmptyCell ? !equalBg(this._cursorStyle, cell) : sgrSeq.length > 0;
+ const styleChanged = isEmptyCell
+ ? materializeEmptyCell ? sgrSeq.length > 0 : !equalBg(this._cursorStyle, cell)
+ : sgrSeq.length > 0;
/**
* handles style change
@@ -395,7 +468,7 @@ class StringSerializeHandler extends BaseSerializeHandler {
/**
* handles actual content
*/
- if (isEmptyCell) {
+ if (isEmptyCell && !materializeEmptyCell) {
this._nullCellCount += cell.getWidth();
} else {
if (this._nullCellCount > 0) {
@@ -411,7 +484,22 @@ class StringSerializeHandler extends BaseSerializeHandler {
this._nullCellCount = 0;
}
- this._currentRow += cell.getChars();
+ // PATCH(orca): styling alone leaves restored OSC 8 links looking live but unclickable.
+ this._currentRow += this._setOscLink(getOscLinkId(cell));
+
+ if (materializeEmptyCell) {
+ const hasDecoration = !!cell.isUnderline() || !!cell.isStrikethrough() || !!cell.isOverline();
+ if (hasDecoration) {
+ this._currentRow += '\u001b[24;29;55m';
+ }
+ this._currentRow += ' '.repeat(cell.getWidth());
+ if (hasDecoration) {
+ const restoreSgrSeq = this._diffStyle(cell, this._defaultCell);
+ this._currentRow += `\u001b[0m\u001b[${restoreSgrSeq.join(';')}m`;
+ }
+ } else {
+ this._currentRow += cell.getChars();
+ }
// update cursor
this._lastContentCursorRow = this._lastCursorRow = row;
@@ -439,6 +527,9 @@ class StringSerializeHandler extends BaseSerializeHandler {
}
}
+ // Each buffer is self-contained so links cannot leak into a following buffer.
+ content += this._setOscLink(0);
+
// restore the cursor
if (!excludeFinalCursorPosition) {
const realCursorRow = this._buffer.baseY + this._buffer.cursorY;
@@ -616,6 +707,9 @@ export class SerializeAddon implements ITerminalAddon, ISerializeApi {
content += this._serializeScrollRegion(this._terminal);
}
+ // Restore the source terminal's live OSC pen only after all buffers are complete.
+ content += getActiveOscLinkSequence(this._terminal);
+
return content;
}