Skip to content

Commit

Permalink
Merge pull request #145245 from microsoft/tyriar/46561
Browse files Browse the repository at this point in the history
Command navigation highlight
  • Loading branch information
Tyriar authored Mar 16, 2022
2 parents 7154a32 + ffae75d commit 7d5f994
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/vs/workbench/contrib/terminal/browser/media/terminal.css
Original file line number Diff line number Diff line change
Expand Up @@ -427,3 +427,9 @@
.terminal-command-decoration.default {
pointer-events: none;
}

.terminal-scroll-highlight {
left: 0;
right: 0;
border: 1px solid #ffffff;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import { coalesce } from 'vs/base/common/arrays';
import { Disposable } from 'vs/base/common/lifecycle';
import { ICommandTracker } from 'vs/workbench/contrib/terminal/browser/terminal';
import { ICommandDetectionCapability, IPartialCommandDetectionCapability, ITerminalCapabilityStore, TerminalCapability } from 'vs/platform/terminal/common/capabilities/capabilities';
import type { Terminal, IMarker, ITerminalAddon } from 'xterm';
import type { Terminal, IMarker, ITerminalAddon, IDecoration } from 'xterm';
import { timeout } from 'vs/base/common/async';
import { IColorTheme, ICssStyleCollector, registerThemingParticipant } from 'vs/platform/theme/common/themeService';
import { focusBorder } from 'vs/platform/theme/common/colorRegistry';

enum Boundary {
Top,
Expand All @@ -24,6 +27,7 @@ export class CommandTrackerAddon extends Disposable implements ICommandTracker,
private _selectionStart: IMarker | Boundary | null = null;
private _isDisposable: boolean = false;
protected _terminal: Terminal | undefined;
private _navigationDecoration: IDecoration | undefined;

private _commandDetection?: ICommandDetectionCapability | IPartialCommandDetectionCapability;

Expand Down Expand Up @@ -155,6 +159,32 @@ export class CommandTrackerAddon extends Disposable implements ICommandTracker,
const line = this._getTargetScrollLine(this._terminal, marker, position);
this._terminal.scrollToLine(line);
}
this._navigationDecoration?.dispose();
const decoration = this._terminal.registerDecoration({
marker,
width: this._terminal.cols
});
this._navigationDecoration = decoration;
if (decoration) {
let isRendered = false;
decoration.onRender(element => {
if (!isRendered) {
// TODO: Remove when https://github.com/xtermjs/xterm.js/issues/3686 is fixed
if (!element.classList.contains('xterm-decoration-overview-ruler')) {
element.classList.add('terminal-scroll-highlight');
}
}
});
decoration.onDispose(() => {
if (decoration === this._navigationDecoration) {
this._navigationDecoration = undefined;
}
});
// Number picked to align with symbol highlight in the editor
timeout(350).then(() => {
decoration.dispose();
});
}
}

private _getTargetScrollLine(terminal: Terminal, marker: IMarker, position: ScrollPosition) {
Expand Down Expand Up @@ -349,3 +379,11 @@ export class CommandTrackerAddon extends Disposable implements ICommandTracker,
return this._getCommandMarkers().length;
}
}

registerThemingParticipant((theme: IColorTheme, collector: ICssStyleCollector) => {
const focusBorderColor = theme.getColor(focusBorder);

if (focusBorderColor) {
collector.addRule(`.terminal-scroll-highlight { border-color: ${focusBorderColor.toString()}; } `);
}
});

0 comments on commit 7d5f994

Please sign in to comment.