From f44392a4aef135dc694cf255dfe3dbb67a59334a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Mangeonjean?= Date: Fri, 23 Aug 2024 16:11:11 +0200 Subject: [PATCH] cleanup: remove placeholder feature as it's now a monaco-editor builtin --- README.md | 1 - src/tools.ts | 65 ---------------------------------------------------- 2 files changed, 66 deletions(-) diff --git a/README.md b/README.md index 7c29b38..30d304b 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,6 @@ Monaco editor wrapper uses and configures [monaco-vscode-api](https://www.npmjs.com/package/@codingame/monaco-vscode-api) for you It also includes some tools allowing to add some missing features to monaco-editor: -- placeholder - `preventAlwaysConsumeTouchEvent`, mobile feature corresponding to the `alwaysConsumeMouseWheel` monaco-editor option - `collapseCodeSections` allows to create and collapse a code section between 2 tokens - `registerTextDecorationProvider` allows to compute decorations on all existing editors diff --git a/src/tools.ts b/src/tools.ts index ade32fc..a3f29a2 100644 --- a/src/tools.ts +++ b/src/tools.ts @@ -439,71 +439,6 @@ export function preventAlwaysConsumeTouchEvent (editor: monaco.editor.ICodeEdito }) } -// https://github.com/microsoft/monaco-editor/issues/568 -class PlaceholderContentWidget implements monaco.editor.IContentWidget { - private static readonly ID = 'editor.widget.placeholderHint' - - private domNode: HTMLElement | undefined - - constructor ( - private readonly editor: monaco.editor.ICodeEditor, - private readonly placeholder: string - ) {} - - getId (): string { - return PlaceholderContentWidget.ID - } - - getDomNode (): HTMLElement { - if (this.domNode == null) { - this.domNode = document.createElement('pre') - this.domNode.style.width = 'max-content' - this.domNode.textContent = this.placeholder - this.domNode.style.pointerEvents = 'none' - this.domNode.style.color = '#aaa' - this.domNode.style.margin = '0' - - this.editor.applyFontInfo(this.domNode) - } - - return this.domNode - } - - getPosition (): monaco.editor.IContentWidgetPosition | null { - return { - position: { lineNumber: 1, column: 1 }, - preference: [monaco.editor.ContentWidgetPositionPreference.EXACT] - } - } -} - -export function addPlaceholder ( - editor: monaco.editor.ICodeEditor, - placeholder: string -): monaco.IDisposable { - const disposableStore = new DisposableStore() - - const widget = new PlaceholderContentWidget(editor, placeholder) - - function onDidChangeModelContent (): void { - if (editor.getValue() === '') { - editor.addContentWidget(widget) - } else { - editor.removeContentWidget(widget) - } - } - - onDidChangeModelContent() - disposableStore.add(editor.onDidChangeModelContent(onDidChangeModelContent)) - disposableStore.add(editor.onDidChangeModel(onDidChangeModelContent)) - disposableStore.add({ - dispose () { - editor.removeContentWidget(widget) - } - }) - return disposableStore -} - export function mapClipboard ( editor: monaco.editor.ICodeEditor, {