Merge branch 'master' into show-tooltip-on-hover

pull/21/head
Alec LaLonde 2 years ago committed by GitHub
commit 6edfb6253d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -24,7 +24,12 @@ export interface IRemoteCursorManagerOptions {
editor: monaco.editor.ICodeEditor; editor: monaco.editor.ICodeEditor;
/** /**
* Determines if tooltips will be shown when the cursor is moved or hovered. * 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.
*/ */
tooltips?: boolean; tooltips?: boolean;
@ -38,6 +43,11 @@ export interface IRemoteCursorManagerOptions {
* Show the tooltip when the cursor is hovered * Show the tooltip when the cursor is hovered
*/ */
showTooltipOnHover?: boolean; showTooltipOnHover?: boolean;
/**
* An additional class name for the tooltip element, to tweak the default style
*/
tooltipClassName?: string;
} }
/** /**
@ -121,11 +131,13 @@ export class RemoteCursorManager {
const cursorWidget = new RemoteCursorWidget( const cursorWidget = new RemoteCursorWidget(
this._options.editor, this._options.editor,
widgetId, widgetId,
this._options.className,
color, color,
label, label,
this._options.tooltips, this._options.tooltips,
tooltipDurationMs, tooltipDurationMs,
this._options.showTooltipOnHover, this._options.showTooltipOnHover,
this._options.tooltipClassName,
() => this.removeCursor(id)); () => this.removeCursor(id));
this._cursorWidgets.set(id, cursorWidget); this._cursorWidgets.set(id, cursorWidget);

@ -51,11 +51,13 @@ export class RemoteCursorWidget implements editor.IContentWidget, IDisposable {
constructor(codeEditor: editor.ICodeEditor, constructor(codeEditor: editor.ICodeEditor,
widgetId: string, widgetId: string,
className: string | undefined,
color: string, color: string,
label: string, label: string,
tooltipEnabled: boolean, tooltipEnabled: boolean,
tooltipDuration: number, tooltipDuration: number,
showTooltipOnHover: boolean, showTooltipOnHover: boolean,
tooltipClassName: string | undefined,
onDisposed: OnDisposed) { onDisposed: OnDisposed) {
this._editor = codeEditor; this._editor = codeEditor;
this._tooltipDuration = tooltipDuration; this._tooltipDuration = tooltipDuration;
@ -65,16 +67,16 @@ export class RemoteCursorWidget implements editor.IContentWidget, IDisposable {
// Create the main node for the cursor element. // Create the main node for the cursor element.
const {lineHeight} = getConfiguration(this._editor); const {lineHeight} = getConfiguration(this._editor);
this._domNode = document.createElement("div"); 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.background = color;
this._domNode.style.height = `${lineHeight}px`; this._domNode.style.height = `${lineHeight}px`;
// Create the tooltip element if the tooltip is enabled. // Create the tooltip element if the tooltip is enabled.
if (tooltipEnabled) { if (tooltipEnabled) {
this._tooltipNode = document.createElement("div"); 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.style.background = color;
this._tooltipNode.innerHTML = label; this._tooltipNode.innerText = label;
this._domNode.appendChild(this._tooltipNode); this._domNode.appendChild(this._tooltipNode);
// we only need to listen to scroll positions to update the // we only need to listen to scroll positions to update the
@ -252,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…
Cancel
Save