11 lines
323 B
TypeScript
11 lines
323 B
TypeScript
import { ViewPlugin, ViewUpdate } from '@codemirror/view'
|
|
|
|
export const textObserverPlugin = (callback: (text: string) => void) =>
|
|
ViewPlugin.define(() => ({
|
|
update(update: ViewUpdate) {
|
|
if (update.docChanged) {
|
|
callback(update.state.doc.toString())
|
|
}
|
|
},
|
|
}))
|