From 38713d59b9b13a22e378d423e9a4e6050c5dddbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Mangeonjean?= Date: Wed, 18 May 2022 15:10:45 +0200 Subject: [PATCH] Add showTooltipOnHover option --- src/ts/RemoteCursorManager.ts | 8 +++++++- src/ts/RemoteCursorWidget.ts | 11 +++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/ts/RemoteCursorManager.ts b/src/ts/RemoteCursorManager.ts index 13e2cb5..3d10649 100644 --- a/src/ts/RemoteCursorManager.ts +++ b/src/ts/RemoteCursorManager.ts @@ -24,7 +24,7 @@ export interface IRemoteCursorManagerOptions { editor: monaco.editor.ICodeEditor; /** - * Determines if tooltips will be shown when the cursor is moved. + * Determines if tooltips will be shown when the cursor is moved or hovered. */ tooltips?: boolean; @@ -33,6 +33,11 @@ export interface IRemoteCursorManagerOptions { * it was last moved. */ tooltipDuration?: number; + + /** + * Show the tooltip when the cursor is hovered + */ + showTooltipOnHover?: boolean; } /** @@ -120,6 +125,7 @@ export class RemoteCursorManager { label, this._options.tooltips, tooltipDurationMs, + this._options.showTooltipOnHover, () => this.removeCursor(id)); this._cursorWidgets.set(id, cursorWidget); diff --git a/src/ts/RemoteCursorWidget.ts b/src/ts/RemoteCursorWidget.ts index d5a2897..1b5685f 100644 --- a/src/ts/RemoteCursorWidget.ts +++ b/src/ts/RemoteCursorWidget.ts @@ -55,6 +55,7 @@ export class RemoteCursorWidget implements editor.IContentWidget, IDisposable { label: string, tooltipEnabled: boolean, tooltipDuration: number, + showTooltipOnHover: boolean, onDisposed: OnDisposed) { this._editor = codeEditor; this._tooltipDuration = tooltipDuration; @@ -81,6 +82,16 @@ export class RemoteCursorWidget implements editor.IContentWidget, IDisposable { this._scrollListener = this._editor.onDidScrollChange(() => { this._updateTooltipPosition(); }); + + if (showTooltipOnHover) { + this._domNode.style.pointerEvents = 'auto'; + this._domNode.addEventListener('mouseover', () => { + this._setTooltipVisible(true); + }) + this._domNode.addEventListener('mouseout', () => { + this._setTooltipVisible(false); + }) + } } else { this._tooltipNode = null; this._scrollListener = null;