1
1
import * as CodeMirror from "codemirror" ;
2
2
import { Compartment , EditorState } from "@codemirror/state" ;
3
- import { EditorView } from "@codemirror/view" ;
3
+ import { EditorView , placeholder } from "@codemirror/view" ;
4
4
import { indentWithTab } from "@codemirror/commands" ;
5
5
import { StreamLanguage } from '@codemirror/language' ;
6
6
import { javascript } from "@codemirror/lang-javascript" ;
@@ -183,6 +183,7 @@ const lineWrapping = new Compartment();
183
183
const lineNumber = new Compartment ( ) ;
184
184
const foldGutterComp = new Compartment ( ) ;
185
185
const searchKeymapComp = new Compartment ( ) ;
186
+ const placeholderComp = new Compartment ( ) ;
186
187
187
188
const editorView = new CodeMirror . EditorView ( {
188
189
doc : "" ,
@@ -209,6 +210,7 @@ const editorView = new CodeMirror.EditorView({
209
210
...completionKeymap ,
210
211
indentWithTab ,
211
212
] ) ,
213
+ placeholderComp . of ( [ ] ) ,
212
214
searchKeymapComp . of ( [ ] ) ,
213
215
foldGutterComp . of ( [ ] ) ,
214
216
readOnly . of ( [ ] ) ,
@@ -266,6 +268,12 @@ function setListener(fn) {
266
268
} ) ;
267
269
}
268
270
271
+ function setPlaceholder ( value ) {
272
+ editorView . dispatch ( {
273
+ effects : placeholderComp . reconfigure ( value ? [ placeholder ( value ) ] : [ ] ) ,
274
+ } ) ;
275
+ }
276
+
269
277
function setReadOnly ( value ) {
270
278
editorView . dispatch ( {
271
279
effects : readOnly . reconfigure ( value ? EditorState . readOnly . of ( true ) : [ ] ) ,
@@ -307,6 +315,7 @@ function setBlur() {
307
315
export {
308
316
setLanguage ,
309
317
getSupportedLanguages ,
318
+ setPlaceholder ,
310
319
setContent ,
311
320
getContent ,
312
321
setListener ,
0 commit comments