Change hideUnderline to hideDecorations
Also track cursor style
This commit is contained in:
+17
-13
@@ -10,6 +10,7 @@ import { IBufferService } from 'common/services/Services';
|
|||||||
import { EventEmitter, IEvent } from 'common/EventEmitter';
|
import { EventEmitter, IEvent } from 'common/EventEmitter';
|
||||||
|
|
||||||
interface ILinkState {
|
interface ILinkState {
|
||||||
|
hideDecorations: boolean;
|
||||||
isHovered: boolean;
|
isHovered: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -176,19 +177,22 @@ export class Linkifier2 implements ILinkifier2 {
|
|||||||
// Trigger hover if the we have a link at the position
|
// Trigger hover if the we have a link at the position
|
||||||
if (this._linkAtPosition(link, position)) {
|
if (this._linkAtPosition(link, position)) {
|
||||||
this._currentLink = link;
|
this._currentLink = link;
|
||||||
this._currentLinkState = { isHovered: true };
|
this._currentLinkState = {
|
||||||
|
hideDecorations: link.hideDecorations || false,
|
||||||
|
isHovered: true
|
||||||
|
};
|
||||||
this._linkHover(this._element, link, this._lastMouseEvent);
|
this._linkHover(this._element, link, this._lastMouseEvent);
|
||||||
|
|
||||||
// Add listener for tracking hideUnderline changes
|
// Add listener for tracking hideDecorations changes
|
||||||
let hideUnderlineValue = link.hideUnderline || false;
|
|
||||||
Object.defineProperties(link, {
|
Object.defineProperties(link, {
|
||||||
hideUnderline: {
|
hideDecorations: {
|
||||||
get: () => hideUnderlineValue,
|
get: () => this._currentLinkState?.hideDecorations,
|
||||||
set: v => {
|
set: v => {
|
||||||
if (hideUnderlineValue !== v) {
|
if (this._currentLinkState && this._currentLinkState.hideDecorations !== v) {
|
||||||
hideUnderlineValue = v;
|
this._currentLinkState.hideDecorations = v;
|
||||||
if (this._currentLinkState?.isHovered) {
|
if (this._currentLinkState?.isHovered) {
|
||||||
this._fireUnderlineEvent(link, !v);
|
this._fireUnderlineEvent(link, !v);
|
||||||
|
this._element?.classList.toggle('xterm-cursor-pointer', !v);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -205,13 +209,13 @@ export class Linkifier2 implements ILinkifier2 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected _linkHover(element: HTMLElement, link: ILink, event: MouseEvent): void {
|
protected _linkHover(element: HTMLElement, link: ILink, event: MouseEvent): void {
|
||||||
if (!link.hideUnderline) {
|
if (!link.hideDecorations) {
|
||||||
this._fireUnderlineEvent(link, true);
|
this._fireUnderlineEvent(link, true);
|
||||||
|
element.classList.add('xterm-cursor-pointer');
|
||||||
}
|
}
|
||||||
if (this._currentLinkState) {
|
if (this._currentLinkState) {
|
||||||
this._currentLinkState.isHovered = true;
|
this._currentLinkState.isHovered = true;
|
||||||
}
|
}
|
||||||
element.classList.add('xterm-cursor-pointer');
|
|
||||||
|
|
||||||
if (link.hover) {
|
if (link.hover) {
|
||||||
link.hover(event, link.text);
|
link.hover(event, link.text);
|
||||||
@@ -221,19 +225,19 @@ export class Linkifier2 implements ILinkifier2 {
|
|||||||
private _fireUnderlineEvent(link: ILink, showEvent: boolean): void {
|
private _fireUnderlineEvent(link: ILink, showEvent: boolean): void {
|
||||||
const range = link.range;
|
const range = link.range;
|
||||||
const scrollOffset = this._bufferService.buffer.ydisp;
|
const scrollOffset = this._bufferService.buffer.ydisp;
|
||||||
const event = this._createLinkHoverEvent(range.start.x - 1, range.start.y - scrollOffset - 1, range.end.x, range.end.y - scrollOffset - 1, undefined);
|
const event = this._createLinkUnderlineEvent(range.start.x - 1, range.start.y - scrollOffset - 1, range.end.x, range.end.y - scrollOffset - 1, undefined);
|
||||||
const emitter = showEvent ? this._onShowLinkUnderline : this._onHideLinkUnderline;
|
const emitter = showEvent ? this._onShowLinkUnderline : this._onHideLinkUnderline;
|
||||||
emitter.fire(event);
|
emitter.fire(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected _linkLeave(element: HTMLElement, link: ILink, event: MouseEvent): void {
|
protected _linkLeave(element: HTMLElement, link: ILink, event: MouseEvent): void {
|
||||||
if (!link.hideUnderline) {
|
if (!link.hideDecorations) {
|
||||||
this._fireUnderlineEvent(link, false);
|
this._fireUnderlineEvent(link, false);
|
||||||
|
element.classList.remove('xterm-cursor-pointer');
|
||||||
}
|
}
|
||||||
if (this._currentLinkState) {
|
if (this._currentLinkState) {
|
||||||
this._currentLinkState.isHovered = false;
|
this._currentLinkState.isHovered = false;
|
||||||
}
|
}
|
||||||
element.classList.remove('xterm-cursor-pointer');
|
|
||||||
|
|
||||||
if (link.leave) {
|
if (link.leave) {
|
||||||
link.leave(event, link.text);
|
link.leave(event, link.text);
|
||||||
@@ -273,7 +277,7 @@ export class Linkifier2 implements ILinkifier2 {
|
|||||||
return { x: coords[0], y: coords[1] + this._bufferService.buffer.ydisp };
|
return { x: coords[0], y: coords[1] + this._bufferService.buffer.ydisp };
|
||||||
}
|
}
|
||||||
|
|
||||||
private _createLinkHoverEvent(x1: number, y1: number, x2: number, y2: number, fg: number | undefined): ILinkifierEvent {
|
private _createLinkUnderlineEvent(x1: number, y1: number, x2: number, y2: number, fg: number | undefined): ILinkifierEvent {
|
||||||
return { x1, y1, x2, y2, cols: this._bufferService.cols, fg };
|
return { x1, y1, x2, y2, cols: this._bufferService.cols, fg };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+1
-1
@@ -172,7 +172,7 @@ interface ILinkProvider {
|
|||||||
interface ILink {
|
interface ILink {
|
||||||
range: IBufferRange;
|
range: IBufferRange;
|
||||||
text: string;
|
text: string;
|
||||||
hideUnderline?: boolean;
|
hideDecorations?: boolean;
|
||||||
activate(event: MouseEvent, text: string): void;
|
activate(event: MouseEvent, text: string): void;
|
||||||
hover?(event: MouseEvent, text: string): void;
|
hover?(event: MouseEvent, text: string): void;
|
||||||
leave?(event: MouseEvent, text: string): void;
|
leave?(event: MouseEvent, text: string): void;
|
||||||
|
|||||||
Vendored
+3
-3
@@ -1121,10 +1121,10 @@ declare module 'xterm' {
|
|||||||
text: string;
|
text: string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether to hide the underline, this property is tracked and changes after the link is
|
* Whether to hide the underline and cursor styles, this property is tracked and changes made
|
||||||
* provided will trigger changes.
|
* after the link is provided will trigger changes.
|
||||||
*/
|
*/
|
||||||
hideUnderline?: boolean;
|
hideDecorations?: boolean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calls when the link is activated.
|
* Calls when the link is activated.
|
||||||
|
|||||||
Reference in New Issue
Block a user