Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Command navigation highlight #145245

Merged
merged 4 commits into from
Mar 16, 2022
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
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 @@ -421,3 +421,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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as some people mentioned in the UX sync, perhaps this should intentionally be different from the focus border so people aren't expecting the focus behavior?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could instead go with the gray that's used for the go to implementations decoration

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This got me to realize it only showed focus border because of my theme:

      "editor.symbolHighlightBackground": "#0000",
      "editor.symbolHighlightBorder": "#399ef4",

Here's what it looks like on Dark+ without that:

image

Will try that and maybe add theme keys for it too

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, but an issue there is the background has to be drawn on top for us, so it would obscure the text...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that looks good to me. couldn't you set the transparency?

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