mirror of
https://github.com/convergencelabs/monaco-collab-ext.git
synced 2024-10-27 20:34:17 +00:00
Compare commits
9 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
d13b0ec4d5 | ||
|
6edfb6253d | ||
|
03f782bda8 | ||
|
e37ce9b99c | ||
|
cdefbb151f | ||
|
91bdec1bb7 | ||
|
38713d59b9 | ||
|
a3b0b8a57c | ||
|
4c03bc00eb |
@ -23,6 +23,11 @@ export interface IRemoteCursorManagerOptions {
|
||||
*/
|
||||
editor: monaco.editor.ICodeEditor;
|
||||
|
||||
/**
|
||||
* An additional class name for the cursor element, to tweak the default style
|
||||
*/
|
||||
className?: string;
|
||||
|
||||
/**
|
||||
* Determines if tooltips will be shown when the cursor is moved.
|
||||
*/
|
||||
@ -33,6 +38,16 @@ export interface IRemoteCursorManagerOptions {
|
||||
* it was last moved.
|
||||
*/
|
||||
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
|
||||
*/
|
||||
tooltipClassName?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -47,7 +62,7 @@ export class RemoteCursorManager {
|
||||
* The default values for optional parameters.
|
||||
* @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.
|
||||
@ -116,10 +131,13 @@ export class RemoteCursorManager {
|
||||
const cursorWidget = new RemoteCursorWidget(
|
||||
this._options.editor,
|
||||
widgetId,
|
||||
this._options.className,
|
||||
color,
|
||||
label,
|
||||
this._options.tooltips,
|
||||
tooltipDurationMs,
|
||||
this._options.showTooltipOnHover,
|
||||
this._options.tooltipClassName,
|
||||
() => this.removeCursor(id));
|
||||
this._cursorWidgets.set(id, cursorWidget);
|
||||
|
||||
|
@ -51,10 +51,13 @@ export class RemoteCursorWidget implements editor.IContentWidget, IDisposable {
|
||||
|
||||
constructor(codeEditor: editor.ICodeEditor,
|
||||
widgetId: string,
|
||||
className: string | undefined,
|
||||
color: string,
|
||||
label: string,
|
||||
tooltipEnabled: boolean,
|
||||
tooltipDuration: number,
|
||||
showTooltipOnHover: boolean,
|
||||
tooltipClassName: string | undefined,
|
||||
onDisposed: OnDisposed) {
|
||||
this._editor = codeEditor;
|
||||
this._tooltipDuration = tooltipDuration;
|
||||
@ -64,16 +67,16 @@ export class RemoteCursorWidget implements editor.IContentWidget, IDisposable {
|
||||
// Create the main node for the cursor element.
|
||||
const {lineHeight} = getConfiguration(this._editor);
|
||||
this._domNode = document.createElement("div");
|
||||
this._domNode.className = "monaco-remote-cursor";
|
||||
this._domNode.className = classNames('monaco-remote-cursor', className)
|
||||
this._domNode.style.background = color;
|
||||
this._domNode.style.height = `${lineHeight}px`;
|
||||
|
||||
// Create the tooltip element if the tooltip is enabled.
|
||||
if (tooltipEnabled) {
|
||||
this._tooltipNode = document.createElement("div");
|
||||
this._tooltipNode.className = "monaco-remote-cursor-tooltip";
|
||||
this._tooltipNode.className = classNames('monaco-remote-cursor-tooltip', tooltipClassName)
|
||||
this._tooltipNode.style.background = color;
|
||||
this._tooltipNode.innerHTML = label;
|
||||
this._tooltipNode.innerText = label;
|
||||
this._domNode.appendChild(this._tooltipNode);
|
||||
|
||||
// we only need to listen to scroll positions to update the
|
||||
@ -81,6 +84,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;
|
||||
@ -171,17 +184,10 @@ export class RemoteCursorWidget implements editor.IContentWidget, IDisposable {
|
||||
}
|
||||
|
||||
private _showTooltip(): void {
|
||||
this._updateTooltipPosition();
|
||||
|
||||
if (this._hideTimer !== null) {
|
||||
clearTimeout(this._hideTimer);
|
||||
} else {
|
||||
this._setTooltipVisible(true);
|
||||
}
|
||||
this._setTooltipVisible(true);
|
||||
|
||||
this._hideTimer = setTimeout(() => {
|
||||
this._setTooltipVisible(false);
|
||||
this._hideTimer = null;
|
||||
}, this._tooltipDuration);
|
||||
}
|
||||
|
||||
@ -197,7 +203,12 @@ export class RemoteCursorWidget implements editor.IContentWidget, IDisposable {
|
||||
}
|
||||
|
||||
private _setTooltipVisible(visible: boolean): void {
|
||||
if (this._hideTimer !== null) {
|
||||
clearTimeout(this._hideTimer);
|
||||
this._hideTimer = null;
|
||||
}
|
||||
if (visible) {
|
||||
this._updateTooltipPosition();
|
||||
this._tooltipNode.style.opacity = "1.0";
|
||||
} else {
|
||||
this._tooltipNode.style.opacity = "0";
|
||||
@ -243,3 +254,7 @@ export class RemoteCursorWidget implements editor.IContentWidget, IDisposable {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function classNames(...names: (string|undefined|null)[]) {
|
||||
return names.filter(className => className != null && className.length > 0).join(' ')
|
||||
}
|
Loading…
Reference in New Issue
Block a user