Skip to content

Commit d94941f

Browse files
authored
Merge pull request microsoft#210790 from microsoft/tyriar/210107
Show terminal command guide when hovering side
2 parents 717c9df + 82763e6 commit d94941f

File tree

2 files changed

+21
-17
lines changed

2 files changed

+21
-17
lines changed

src/vs/workbench/contrib/terminal/browser/media/terminal.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,7 @@
486486
border-color: var(--vscode-notebook-inactiveFocusedCellBorder);
487487
box-sizing: border-box;
488488
transform: translateX(3px);
489+
pointer-events: none;
489490
}
490491
.terminal-command-guide.top {
491492
border-top-left-radius: 1px;

src/vs/workbench/contrib/terminalContrib/highlight/browser/terminal.highlight.contribution.ts

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,25 +30,28 @@ class TerminalHighlightContribution extends Disposable implements ITerminalContr
3030

3131
xtermOpen(xterm: IXtermTerminal & { raw: RawXtermTerminal }): void {
3232
const screenElement = xterm.raw.element!.querySelector('.xterm-screen')!;
33-
this._register(addDisposableListener(screenElement, 'mousemove', (e: MouseEvent) => {
34-
if ((e.target as any).tagName !== 'CANVAS') {
35-
return;
36-
}
37-
const rect = xterm.raw.element?.getBoundingClientRect();
38-
if (!rect) {
39-
return;
40-
}
41-
const mouseCursorY = Math.floor(e.offsetY / (rect.height / xterm.raw.rows));
42-
const command = this._instance.capabilities.get(TerminalCapability.CommandDetection)?.getCommandForLine(xterm.raw.buffer.active.viewportY + mouseCursorY);
43-
if (command && 'getOutput' in command) {
44-
xterm.markTracker.showCommandGuide(command);
45-
} else {
46-
xterm.markTracker.showCommandGuide(undefined);
47-
}
48-
}));
49-
this._register(addDisposableListener(screenElement, 'mouseout', () => xterm.markTracker.showCommandGuide(undefined)));
33+
this._register(addDisposableListener(screenElement, 'mousemove', (e: MouseEvent) => this._tryShowHighlight(screenElement, xterm, e)));
34+
35+
const viewportElement = xterm.raw.element!.querySelector('.xterm-viewport')!;
36+
this._register(addDisposableListener(viewportElement, 'mousemove', (e: MouseEvent) => this._tryShowHighlight(screenElement, xterm, e)));
37+
38+
this._register(addDisposableListener(xterm.raw.element!, 'mouseout', () => xterm.markTracker.showCommandGuide(undefined)));
5039
this._register(xterm.raw.onData(() => xterm.markTracker.showCommandGuide(undefined)));
5140
}
41+
42+
private _tryShowHighlight(element: Element, xterm: IXtermTerminal & { raw: RawXtermTerminal }, e: MouseEvent) {
43+
const rect = element.getBoundingClientRect();
44+
if (!rect) {
45+
return;
46+
}
47+
const mouseCursorY = Math.floor(e.offsetY / (rect.height / xterm.raw.rows));
48+
const command = this._instance.capabilities.get(TerminalCapability.CommandDetection)?.getCommandForLine(xterm.raw.buffer.active.viewportY + mouseCursorY);
49+
if (command && 'getOutput' in command) {
50+
xterm.markTracker.showCommandGuide(command);
51+
} else {
52+
xterm.markTracker.showCommandGuide(undefined);
53+
}
54+
}
5255
}
5356

5457
registerTerminalContribution(TerminalHighlightContribution.ID, TerminalHighlightContribution, false);

0 commit comments

Comments
 (0)