Skip to content

Commit 4741173

Browse files
committed
refactor: add state ref for code-editor
1 parent 951c3b0 commit 4741173

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

projects/code-editor/code-editor.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,11 @@ export class CodeEditor implements OnChanges, OnInit, OnDestroy, ControlValueAcc
145145
*/
146146
view!: EditorView;
147147

148+
/**
149+
* The new state created by [EditorState](https://codemirror.net/docs/ref/#state.EditorState)
150+
*/
151+
state!: EditorState;
152+
148153
private _updateListener = EditorView.updateListener.of(vu => {
149154
if (vu.docChanged && !vu.transactions.some(tr => tr.annotation(External))) {
150155
const value = vu.state.doc.toString();
@@ -224,10 +229,14 @@ export class CodeEditor implements OnChanges, OnInit, OnDestroy, ControlValueAcc
224229
}
225230

226231
ngOnInit(): void {
232+
this.state = EditorState.create({
233+
doc: this.value,
234+
extensions: this._getAllExtensions(),
235+
});
227236
this.view = new EditorView({
228237
root: this.root,
229238
parent: this._elementRef.nativeElement,
230-
state: EditorState.create({ doc: this.value, extensions: this._getAllExtensions() }),
239+
state: this.state,
231240
});
232241

233242
if (this.autoFocus) {

0 commit comments

Comments
 (0)