2025-05-10 19:10:30 +03:00
|
|
|
import { defaultKeymap } from "@codemirror/commands";
|
2025-05-10 19:15:38 +03:00
|
|
|
import { EditorView, keymap, lineNumbers, type EditorViewConfig } from "@codemirror/view";
|
2025-05-10 19:10:30 +03:00
|
|
|
|
|
|
|
export default class CodeMirror extends EditorView {
|
|
|
|
constructor(config: EditorViewConfig) {
|
|
|
|
super({
|
|
|
|
...config,
|
|
|
|
extensions: [
|
2025-05-10 19:15:38 +03:00
|
|
|
keymap.of(defaultKeymap),
|
|
|
|
lineNumbers()
|
2025-05-10 19:10:30 +03:00
|
|
|
]
|
|
|
|
});
|
|
|
|
}
|
2025-05-10 19:22:57 +03:00
|
|
|
|
|
|
|
setText(content: string) {
|
|
|
|
this.dispatch({
|
|
|
|
changes: {
|
|
|
|
from: 0,
|
|
|
|
to: this.state.doc.length,
|
|
|
|
insert: content || "",
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2025-05-10 19:10:30 +03:00
|
|
|
}
|