Skip to content

Commit

Permalink
Remove window usage from link terminalContrib
Browse files Browse the repository at this point in the history
Fixes #195804
  • Loading branch information
Tyriar committed Nov 16, 2023
1 parent c855616 commit a1c3d38
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { Emitter, Event } from 'vs/base/common/event';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { TerminalLinkType } from 'vs/workbench/contrib/terminalContrib/links/browser/links';
import { IHoverAction } from 'vs/workbench/services/hover/browser/hover';
import { $window } from 'vs/base/browser/window';

export class TerminalLink extends DisposableStore implements ILink {
decorations: ILinkDecorations;
Expand Down Expand Up @@ -62,14 +61,16 @@ export class TerminalLink extends DisposableStore implements ILink {
}

hover(event: MouseEvent, text: string): void {
const w = dom.getWindow(event);
const d = w.document;
// Listen for modifier before handing it off to the hover to handle so it gets disposed correctly
this._hoverListeners = new DisposableStore();
this._hoverListeners.add(dom.addDisposableListener($window.document, 'keydown', e => {
this._hoverListeners.add(dom.addDisposableListener(d, 'keydown', e => {
if (!e.repeat && this._isModifierDown(e)) {
this._enableDecorations();
}
}));
this._hoverListeners.add(dom.addDisposableListener($window.document, 'keyup', e => {
this._hoverListeners.add(dom.addDisposableListener(d, 'keyup', e => {
if (!e.repeat && !this._isModifierDown(e)) {
this._disableDecorations();
}
Expand Down Expand Up @@ -102,7 +103,7 @@ export class TerminalLink extends DisposableStore implements ILink {
}

const origin = { x: event.pageX, y: event.pageY };
this._hoverListeners.add(dom.addDisposableListener($window.document, dom.EventType.MOUSE_MOVE, e => {
this._hoverListeners.add(dom.addDisposableListener(d, dom.EventType.MOUSE_MOVE, e => {
// Update decorations
if (this._isModifierDown(e)) {
this._enableDecorations();
Expand All @@ -111,7 +112,7 @@ export class TerminalLink extends DisposableStore implements ILink {
}

// Reset the scheduler if the mouse moves too much
if (Math.abs(e.pageX - origin.x) > $window.devicePixelRatio * 2 || Math.abs(e.pageY - origin.y) > $window.devicePixelRatio * 2) {
if (Math.abs(e.pageX - origin.x) > w.devicePixelRatio * 2 || Math.abs(e.pageY - origin.y) > w.devicePixelRatio * 2) {
origin.x = e.pageX;
origin.y = e.pageY;
this._tooltipScheduler?.schedule();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { isWindows, OperatingSystem, OS } from 'vs/base/common/platform';
import { IFileService } from 'vs/platform/files/common/files';
import { IPath, posix, win32 } from 'vs/base/common/path';
import { ITerminalBackend } from 'vs/platform/terminal/common/terminal';
import { $window } from 'vs/base/browser/window';
import { getActiveWindow } from 'vs/base/browser/dom';

export class TerminalLinkResolver implements ITerminalLinkResolver {
declare _serviceBrand: undefined;
Expand Down Expand Up @@ -170,9 +170,9 @@ class LinkCache {
set(link: string | URI, value: ResolvedLink) {
// Reset cached link TTL on any set
if (this._cacheTilTimeout) {
$window.clearTimeout(this._cacheTilTimeout);
getActiveWindow().clearTimeout(this._cacheTilTimeout);
}
this._cacheTilTimeout = $window.setTimeout(() => this._cache.clear(), LinkCacheConstants.TTL);
this._cacheTilTimeout = getActiveWindow().setTimeout(() => this._cache.clear(), LinkCacheConstants.TTL);
this._cache.set(this._getKey(link), value);
}

Expand Down

0 comments on commit a1c3d38

Please sign in to comment.