]> BookStack Code Mirror - bookstack/blob - resources/js/code/simple-editor-interface.js
Deps: Updated composer/npm packages, fixed test namespace
[bookstack] / resources / js / code / simple-editor-interface.js
1 import {updateViewLanguage} from './views';
2
3 export class SimpleEditorInterface {
4
5     /**
6      * @param {EditorView} editorView
7      */
8     constructor(editorView) {
9         this.ev = editorView;
10     }
11
12     /**
13      * Get the contents of an editor instance.
14      * @return {string}
15      */
16     getContent() {
17         return this.ev.state.doc.toString();
18     }
19
20     /**
21      * Set the contents of an editor instance.
22      * @param content
23      */
24     setContent(content) {
25         const {doc} = this.ev.state;
26         this.ev.dispatch({
27             changes: {from: 0, to: doc.length, insert: content},
28         });
29     }
30
31     /**
32      * Return focus to the editor instance.
33      */
34     focus() {
35         this.ev.focus();
36     }
37
38     /**
39      * Set the language mode of the editor instance.
40      * @param {String} mode
41      * @param {String} content
42      */
43     setMode(mode, content = '') {
44         updateViewLanguage(this.ev, mode, content);
45     }
46
47 }
Morty Proxy This is a proxified and sanitized view of the page, visit original site.