mirror of
https://github.com/convergencelabs/monaco-collab-ext.git
synced 2024-10-27 20:34:17 +00:00
Merge pull request #21 from CGNonofr/show-tooltip-on-hover
Show tooltip on cursor hover
This commit is contained in:
commit
d13b0ec4d5
@ -39,6 +39,11 @@ export interface IRemoteCursorManagerOptions {
|
|||||||
*/
|
*/
|
||||||
tooltipDuration?: number;
|
tooltipDuration?: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show the tooltip when the cursor is hovered
|
||||||
|
*/
|
||||||
|
showTooltipOnHover?: boolean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An additional class name for the tooltip element, to tweak the default style
|
* An additional class name for the tooltip element, to tweak the default style
|
||||||
*/
|
*/
|
||||||
@ -57,7 +62,7 @@ export class RemoteCursorManager {
|
|||||||
* The default values for optional parameters.
|
* The default values for optional parameters.
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
private static readonly DEFAULT_OPTIONS = {tooltips: true, tooltipDuration: 1};
|
private static readonly DEFAULT_OPTIONS: Partial<IRemoteCursorManagerOptions> = {tooltips: true, tooltipDuration: 1, showTooltipOnHover: false};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A counter that generates unique ids for the cursor widgets.
|
* A counter that generates unique ids for the cursor widgets.
|
||||||
@ -131,6 +136,7 @@ export class RemoteCursorManager {
|
|||||||
label,
|
label,
|
||||||
this._options.tooltips,
|
this._options.tooltips,
|
||||||
tooltipDurationMs,
|
tooltipDurationMs,
|
||||||
|
this._options.showTooltipOnHover,
|
||||||
this._options.tooltipClassName,
|
this._options.tooltipClassName,
|
||||||
() => this.removeCursor(id));
|
() => this.removeCursor(id));
|
||||||
this._cursorWidgets.set(id, cursorWidget);
|
this._cursorWidgets.set(id, cursorWidget);
|
||||||
|
@ -56,6 +56,7 @@ export class RemoteCursorWidget implements editor.IContentWidget, IDisposable {
|
|||||||
label: string,
|
label: string,
|
||||||
tooltipEnabled: boolean,
|
tooltipEnabled: boolean,
|
||||||
tooltipDuration: number,
|
tooltipDuration: number,
|
||||||
|
showTooltipOnHover: boolean,
|
||||||
tooltipClassName: string | undefined,
|
tooltipClassName: string | undefined,
|
||||||
onDisposed: OnDisposed) {
|
onDisposed: OnDisposed) {
|
||||||
this._editor = codeEditor;
|
this._editor = codeEditor;
|
||||||
@ -83,6 +84,16 @@ export class RemoteCursorWidget implements editor.IContentWidget, IDisposable {
|
|||||||
this._scrollListener = this._editor.onDidScrollChange(() => {
|
this._scrollListener = this._editor.onDidScrollChange(() => {
|
||||||
this._updateTooltipPosition();
|
this._updateTooltipPosition();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (showTooltipOnHover) {
|
||||||
|
this._domNode.style.pointerEvents = 'auto';
|
||||||
|
this._domNode.addEventListener('mouseover', () => {
|
||||||
|
this._setTooltipVisible(true);
|
||||||
|
})
|
||||||
|
this._domNode.addEventListener('mouseout', () => {
|
||||||
|
this._setTooltipVisible(false);
|
||||||
|
})
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
this._tooltipNode = null;
|
this._tooltipNode = null;
|
||||||
this._scrollListener = null;
|
this._scrollListener = null;
|
||||||
@ -173,17 +184,10 @@ export class RemoteCursorWidget implements editor.IContentWidget, IDisposable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private _showTooltip(): void {
|
private _showTooltip(): void {
|
||||||
this._updateTooltipPosition();
|
this._setTooltipVisible(true);
|
||||||
|
|
||||||
if (this._hideTimer !== null) {
|
|
||||||
clearTimeout(this._hideTimer);
|
|
||||||
} else {
|
|
||||||
this._setTooltipVisible(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
this._hideTimer = setTimeout(() => {
|
this._hideTimer = setTimeout(() => {
|
||||||
this._setTooltipVisible(false);
|
this._setTooltipVisible(false);
|
||||||
this._hideTimer = null;
|
|
||||||
}, this._tooltipDuration);
|
}, this._tooltipDuration);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -199,7 +203,12 @@ export class RemoteCursorWidget implements editor.IContentWidget, IDisposable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private _setTooltipVisible(visible: boolean): void {
|
private _setTooltipVisible(visible: boolean): void {
|
||||||
|
if (this._hideTimer !== null) {
|
||||||
|
clearTimeout(this._hideTimer);
|
||||||
|
this._hideTimer = null;
|
||||||
|
}
|
||||||
if (visible) {
|
if (visible) {
|
||||||
|
this._updateTooltipPosition();
|
||||||
this._tooltipNode.style.opacity = "1.0";
|
this._tooltipNode.style.opacity = "1.0";
|
||||||
} else {
|
} else {
|
||||||
this._tooltipNode.style.opacity = "0";
|
this._tooltipNode.style.opacity = "0";
|
||||||
|
Loading…
Reference in New Issue
Block a user