Compare commits

...
Author SHA1 Message Date
Daniel ImmsandCursor fd6a339bcb fix(browser): place imports before module const in TimeBasedDebouncer
RENDER_DEBOUNCE_THRESHOLD_MS was declared above the import, which
breaks ES module conventions and can confuse tooling. Move the import
to the top of the module after the license header.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-01 15:28:12 +00:00
Daniel ImmsandCursor a2552053f5 fix(browser): clear idle blink timer when handle is 0
_clearIdleTimer() used truthiness on _idleTimeout, so a setTimeout
handle of 0 would not be cleared. Compare against undefined, consistent
with RenderDebouncer rAF handling.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-01 15:28:12 +00:00
Daniel ImmsandCursor f3783729aa fix(browser): treat rAF id 0 as scheduled in RenderDebouncer
dispose(), addRefreshCallback(), and refresh() used truthiness on
_animationFrame, so a requestAnimationFrame handle of 0 would not be
cancelled or deduplicated. Compare against undefined instead, matching
other timer checks in the browser layer.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-01 15:28:12 +00:00
Daniel ImmsandCursor a97b77af3f fix(browser): cancel trailing debounce timeout on immediate refresh
TimeBasedDebouncer can schedule a trailing setTimeout when refresh
requests are throttled. If the debounce window later elapses and an
immediate refresh runs, that pending timeout was left armed and could
fire afterward, causing a duplicate _innerRefresh (e.g. extra live
region updates for screen readers).

Clear any pending timeout and reset _additionalRefreshRequested before
running the immediate refresh path.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-01 15:28:11 +00:00
Daniel ImmsandCursor 275d6d8a80 fix(browser): reset TimeBasedDebouncer state on dispose
dispose() cleared the pending timeout but left _refreshTimeoutID and
_additionalRefreshRequested set. After dispose, a stale timeout id or
trailing-refresh flag could confuse a new instance or tests. Match
RenderDebouncer by clearing the timeout id and reset the trailing flag.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-01 15:27:58 +00:00
Daniel ImmsandCursor 8679eba407 refactor(browser): remove unreachable coords guard in getCoords
getCoordsRelativeToElement always returns a two-element tuple, so the
array is always truthy and if (!coords) could never run. hasValidCharSize
already handles the only early-exit path before coordinates are computed.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-01 15:27:58 +00:00
Daniel ImmsandCursor 3960db39a9 fix(browser): parenthesize document fallback for CoreBrowserService
Nullish coalescing binds tighter than the conditional operator, so the
previous expression was parsed as (this._document ?? windowDefined) ?
window.document : null. When this._document was set (e.g. parent
ownerDocument or documentOverride), the ternary still returned
window.document instead of the configured document.

CoreBrowserService.mainDocument is used by AccessibilityManager, viewport
styles, and decoration renderers; CharSizeService already received
this._document directly. Add parentheses so the fallback applies only when
_document is nullish.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-01 15:27:58 +00:00
Daniel ImmsandCursor ff8a0d9c99 fix(browser): use startY in horizontalDirection row helper call
horizontalDirection called moveToRequestedRow with targetX as the first
argument, but that parameter is the starting row (startY). resetStartingRow
and moveToRequestedCol already pass startY correctly; only this copy-paste
mistake passed a column index where a row was expected.

That could miscompute wrapped-row offsets and emit the wrong horizontal
arrow key sequence when building selection/cursor movement strings.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-01 15:27:58 +00:00
6 changed files with 16 additions and 13 deletions
+1 -1
View File
@@ -505,7 +505,7 @@ export class CoreBrowserTerminal extends CoreTerminal implements ITerminal {
this.textarea,
parent.ownerDocument.defaultView ?? window,
// Force unsafe null in node.js environment for tests
this._document ?? (typeof window !== 'undefined') ? window.document : null as any
this._document ?? ((typeof window !== 'undefined') ? window.document : null as any)
));
this._instantiationService.setService(ICoreBrowserService, this._coreBrowserService);
+3 -3
View File
@@ -23,7 +23,7 @@ export class RenderDebouncer implements IRenderDebouncerWithCallback {
}
public dispose(): void {
if (this._animationFrame) {
if (this._animationFrame !== undefined) {
this._coreBrowserService.window.cancelAnimationFrame(this._animationFrame);
this._animationFrame = undefined;
}
@@ -31,7 +31,7 @@ export class RenderDebouncer implements IRenderDebouncerWithCallback {
public addRefreshCallback(callback: FrameRequestCallback): number {
this._refreshCallbacks.push(callback);
if (!this._animationFrame) {
if (this._animationFrame === undefined) {
this._animationFrame = this._coreBrowserService.window.requestAnimationFrame(() => this._innerRefresh());
}
return this._animationFrame;
@@ -46,7 +46,7 @@ export class RenderDebouncer implements IRenderDebouncerWithCallback {
this._rowStart = this._rowStart !== undefined ? Math.min(this._rowStart, rowStart) : rowStart;
this._rowEnd = this._rowEnd !== undefined ? Math.max(this._rowEnd, rowEnd) : rowEnd;
if (this._animationFrame) {
if (this._animationFrame !== undefined) {
return;
}
+10 -3
View File
@@ -3,10 +3,10 @@
* @license MIT
*/
const RENDER_DEBOUNCE_THRESHOLD_MS = 1000; // 1 Second
import { IRenderDebouncer } from './Types';
const RENDER_DEBOUNCE_THRESHOLD_MS = 1000; // 1 Second
/**
* Debounces calls to update screen readers to update at most once configurable interval of time.
*/
@@ -31,7 +31,9 @@ export class TimeBasedDebouncer implements IRenderDebouncer {
public dispose(): void {
if (this._refreshTimeoutID) {
clearTimeout(this._refreshTimeoutID);
this._refreshTimeoutID = undefined;
}
this._additionalRefreshRequested = false;
}
public refresh(rowStart: number | undefined, rowEnd: number | undefined, rowCount: number): void {
@@ -47,7 +49,12 @@ export class TimeBasedDebouncer implements IRenderDebouncer {
// enough time to pass before refreshing again.
const refreshRequestTime: number = performance.now();
if (refreshRequestTime - this._lastRefreshMs >= this._debounceThresholdMS) {
// Enough time has lapsed since the last refresh; refresh immediately
// Enough time has elapsed since the last refresh; refresh immediately
if (this._refreshTimeoutID !== undefined) {
clearTimeout(this._refreshTimeoutID);
this._refreshTimeoutID = undefined;
this._additionalRefreshRequested = false;
}
this._lastRefreshMs = refreshRequestTime;
this._innerRefresh();
} else if (!this._additionalRefreshRequested) {
-4
View File
@@ -37,10 +37,6 @@ export function getCoords(window: Pick<Window, 'getComputedStyle'>, event: Pick<
}
const coords = getCoordsRelativeToElement(window, event, element);
if (!coords) {
return undefined;
}
coords[0] = Math.ceil((coords[0] + (isSelection ? cssCellWidth / 2 : 0)) / cssCellWidth);
coords[1] = Math.ceil(coords[1] / cssCellHeight);
+1 -1
View File
@@ -156,7 +156,7 @@ function wrappedRowsForRow(currentRow: number, bufferService: IBufferService): n
*/
function horizontalDirection(startX: number, startY: number, targetX: number, targetY: number, bufferService: IBufferService, applicationCursor: boolean): Direction {
let startRow;
if (moveToRequestedRow(targetX, targetY, bufferService, applicationCursor).length > 0) {
if (moveToRequestedRow(startY, targetY, bufferService, applicationCursor).length > 0) {
startRow = targetY - wrappedRowsForRow(targetY, bufferService);
} else {
startRow = startY;
+1 -1
View File
@@ -694,7 +694,7 @@ class CursorBlinkStateManager {
}
private _clearIdleTimer(): void {
if (this._idleTimeout) {
if (this._idleTimeout !== undefined) {
this._coreBrowserService.window.clearTimeout(this._idleTimeout);
this._idleTimeout = undefined;
}