Merge pull request #22 from CodinGame/provide-class-name-to-tweak-display

Allow adding custom element class names
dependabot/npm_and_yarn/terser-4.8.1
Alec LaLonde 2 years ago committed by GitHub
commit cdefbb151f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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,11 @@ export interface IRemoteCursorManagerOptions {
* it was last moved.
*/
tooltipDuration?: number;
/**
* An additional class name for the tooltip element, to tweak the default style
*/
tooltipClassName?: string;
}
/**
@ -116,10 +126,12 @@ export class RemoteCursorManager {
const cursorWidget = new RemoteCursorWidget(
this._options.editor,
widgetId,
this._options.className,
color,
label,
this._options.tooltips,
tooltipDurationMs,
this._options.tooltipClassName,
() => this.removeCursor(id));
this._cursorWidgets.set(id, cursorWidget);

@ -51,10 +51,12 @@ export class RemoteCursorWidget implements editor.IContentWidget, IDisposable {
constructor(codeEditor: editor.ICodeEditor,
widgetId: string,
className: string | undefined,
color: string,
label: string,
tooltipEnabled: boolean,
tooltipDuration: number,
tooltipClassName: string | undefined,
onDisposed: OnDisposed) {
this._editor = codeEditor;
this._tooltipDuration = tooltipDuration;
@ -64,14 +66,14 @@ 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._domNode.appendChild(this._tooltipNode);
@ -243,3 +245,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