mirror of
https://github.com/convergencelabs/monaco-collab-ext.git
synced 2024-10-27 20:34:17 +00:00
Merge pull request #22 from CodinGame/provide-class-name-to-tweak-display
Allow adding custom element class names
This commit is contained in:
commit
cdefbb151f
@ -23,6 +23,11 @@ export interface IRemoteCursorManagerOptions {
|
|||||||
*/
|
*/
|
||||||
editor: monaco.editor.ICodeEditor;
|
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.
|
* Determines if tooltips will be shown when the cursor is moved.
|
||||||
*/
|
*/
|
||||||
@ -33,6 +38,11 @@ export interface IRemoteCursorManagerOptions {
|
|||||||
* it was last moved.
|
* it was last moved.
|
||||||
*/
|
*/
|
||||||
tooltipDuration?: number;
|
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(
|
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.tooltipClassName,
|
||||||
() => this.removeCursor(id));
|
() => this.removeCursor(id));
|
||||||
this._cursorWidgets.set(id, cursorWidget);
|
this._cursorWidgets.set(id, cursorWidget);
|
||||||
|
|
||||||
|
@ -51,10 +51,12 @@ 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,
|
||||||
|
tooltipClassName: string | undefined,
|
||||||
onDisposed: OnDisposed) {
|
onDisposed: OnDisposed) {
|
||||||
this._editor = codeEditor;
|
this._editor = codeEditor;
|
||||||
this._tooltipDuration = tooltipDuration;
|
this._tooltipDuration = tooltipDuration;
|
||||||
@ -64,14 +66,14 @@ 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.innerHTML = label;
|
||||||
this._domNode.appendChild(this._tooltipNode);
|
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…
Reference in New Issue
Block a user