javascriptinputplaceholdercodemirrorcodemirror-6

Create placeholder when input is empty in CodeMirror 6


Anyone know how create placeholder when input is empty in CodeMirror 6, i search docs but nothing special about this basic function like it

I search something but i found only to version 5 not 6


Solution

  • import { EditorView, placeholder } from '@codemirror/view'
    import { EditorState } from "@codemirror/state"
    
    const startState = EditorState.create({
      doc: 'Hello World',
      extensions: [placeholder('placeholder text')]
    })
    
    const view = new EditorView({
      state: startState,
      parent: document.body
    })