Skip to content
Merged
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
Empty file removed BitFun@0.1.1
Empty file.
Empty file removed bitfun-mobile-web@0.1.1
Empty file.
Empty file removed node
Empty file.
43 changes: 43 additions & 0 deletions src/web-ui/src/tools/terminal/components/Terminal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@ import './Terminal.scss';

const log = createLogger('Terminal');

type TerminalCoreWithMeasurement = XTerm & {
_core?: {
_charSizeService?: {
measure?: () => void;
};
_renderService?: {
handleDevicePixelRatioChange?: () => void;
};
};
};

/**
* Clear xterm texture atlas when supported.
* Used to force redraws and avoid WebGL cache artifacts.
Expand All @@ -31,6 +42,12 @@ function clearTextureAtlas(terminal: XTerm): void {
}
}

function remeasureTerminal(terminal: XTerm): void {
const rawTerminal = terminal as TerminalCoreWithMeasurement;
rawTerminal._core?._charSizeService?.measure?.();
rawTerminal._core?._renderService?.handleDevicePixelRatioChange?.();
}

/**
* Scroll to bottom when the cursor is below the viewport.
*/
Expand Down Expand Up @@ -460,6 +477,31 @@ const Terminal = forwardRef<TerminalRef, TerminalProps>(({
}
});

let fontLoadCancelled = false;
if (typeof document !== 'undefined' && 'fonts' in document) {
const fontSet = document.fonts as FontFaceSet;
if (fontSet.status !== 'loaded') {
void fontSet.ready.then(() => {
if (fontLoadCancelled || !terminalRef.current) {
return;
}

requestAnimationFrame(() => {
if (!terminalRef.current) return;

remeasureTerminal(terminalRef.current);
fit(true);

requestAnimationFrame(() => {
if (!terminalRef.current) return;
forceRefresh(terminalRef.current);
scrollToBottomIfNeeded(terminalRef.current);
});
});
});
}
}

const dataDisposable = terminal.onData((data) => {
onData?.(data);
});
Expand Down Expand Up @@ -548,6 +590,7 @@ const Terminal = forwardRef<TerminalRef, TerminalProps>(({
titleDisposable.dispose();
resizeObserver.disconnect();
intersectionObserver.disconnect();
fontLoadCancelled = true;
resizeDebouncer.dispose();
webglAddonRef.current?.dispose();
terminal.dispose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,13 @@ export class TerminalResizeDebouncer {

if (immediate || bufferLength < START_DEBOUNCING_THRESHOLD) {
this.clearPendingJobs();
this.executeResize(cols, rows, true);
if (this.isNewApi) {
const opts = this.options as ResizeDebounceOptions;
opts.onXtermResize(cols, rows);
this.scheduleBackendResize(cols, rows);
} else {
this.executeResize(cols, rows, true);
}
return;
}

Expand Down
Empty file removed tsc
Empty file.
Loading