File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1818 */
1919
2020import { Plugin } from "prosemirror-state" ;
21- import type { EditorPlugin } from "@stackoverflow/stacks-editor" ;
21+ import type { EditorPlugin , StacksEditor } from "@stackoverflow/stacks-editor" ;
2222
2323/**
2424 * Creates a StacksEditor plugin that listens to content changes.
@@ -27,10 +27,12 @@ import type { EditorPlugin } from "@stackoverflow/stacks-editor";
2727 *
2828 * Works in both RichText and Markdown modes automatically.
2929 *
30+ * @param getEditor Function that returns the StacksEditor instance
3031 * @param onUpdate Callback function that receives the updated editor content
3132 * @returns A StacksEditor EditorPlugin
3233 */
3334export const createOnChangePlugin = (
35+ getEditor : ( ) => StacksEditor | null ,
3436 onUpdate : ( content : string ) => void
3537) : EditorPlugin => {
3638 return ( ) => {
@@ -39,9 +41,14 @@ export const createOnChangePlugin = (
3941 const proseMirrorPlugin : any = new Plugin ( {
4042 view ( ) {
4143 return {
42- update ( view ) {
44+ update ( ) {
4345 try {
44- const content = view . state . doc . textContent ;
46+ // Get the editor instance to access serialized markdown content
47+ const editor = getEditor ( ) ;
48+ if ( ! editor ) return ;
49+
50+ // Use editor.content to get properly serialized markdown
51+ const content = editor . content ;
4552
4653 // Only trigger callback if content actually changed
4754 if ( content !== lastContent ) {
You can’t perform that action at this time.
0 commit comments