From 91bdec1bb7cf038b9fda2488ff6e38c8fa21a85c Mon Sep 17 00:00:00 2001 From: Samuel Olivier Date: Thu, 19 May 2022 17:01:09 +0200 Subject: [PATCH 1/2] add additional elements class names --- src/ts/RemoteCursorManager.ts | 12 ++++++++++++ src/ts/RemoteCursorWidget.ts | 10 ++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/ts/RemoteCursorManager.ts b/src/ts/RemoteCursorManager.ts index 94c9dac..e9ff489 100644 --- a/src/ts/RemoteCursorManager.ts +++ b/src/ts/RemoteCursorManager.ts @@ -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); diff --git a/src/ts/RemoteCursorWidget.ts b/src/ts/RemoteCursorWidget.ts index 12eb600..3f99381 100644 --- a/src/ts/RemoteCursorWidget.ts +++ b/src/ts/RemoteCursorWidget.ts @@ -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(' ') +} \ No newline at end of file From e37ce9b99caf643bbb2c755822180113badc8681 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Mangeonjean?= Date: Thu, 15 Sep 2022 10:28:11 +0200 Subject: [PATCH 2/2] fix: prevent XSS in tooltip label --- src/ts/RemoteCursorWidget.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ts/RemoteCursorWidget.ts b/src/ts/RemoteCursorWidget.ts index 3f99381..8ad38d8 100644 --- a/src/ts/RemoteCursorWidget.ts +++ b/src/ts/RemoteCursorWidget.ts @@ -75,7 +75,7 @@ export class RemoteCursorWidget implements editor.IContentWidget, IDisposable { this._tooltipNode = document.createElement("div"); 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