Skip to content

Commit

Permalink
cleanup: remove placeholder feature as it's now a monaco-editor builtin
Browse files Browse the repository at this point in the history
  • Loading branch information
Loïc Mangeonjean committed Aug 23, 2024
1 parent c892818 commit f44392a
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 66 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
65 changes: 0 additions & 65 deletions src/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
{
Expand Down

0 comments on commit f44392a

Please sign in to comment.