This is an automated email from the ASF dual-hosted git repository.

robin0716 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/answer-plugins.git


The following commit(s) were added to refs/heads/main by this push:
     new 223636c  fix(editor-stacks/onChange-plugin): update import types and 
enhance content retrieval logic
223636c is described below

commit 223636cdb48036b03657888575c02fbaf1c73411
Author: robin <[email protected]>
AuthorDate: Thu Dec 25 17:36:05 2025 +0800

    fix(editor-stacks/onChange-plugin): update import types and enhance content 
retrieval logic
---
 editor-stacks/onChange-plugin.ts | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/editor-stacks/onChange-plugin.ts b/editor-stacks/onChange-plugin.ts
index 5c7d62d..56df9cd 100644
--- a/editor-stacks/onChange-plugin.ts
+++ b/editor-stacks/onChange-plugin.ts
@@ -18,7 +18,7 @@
  */
 
 import { Plugin } from "prosemirror-state";
-import type { EditorPlugin } from "@stackoverflow/stacks-editor";
+import type { EditorPlugin, StacksEditor } from "@stackoverflow/stacks-editor";
 
 /**
  * Creates a StacksEditor plugin that listens to content changes.
@@ -27,10 +27,12 @@ import type { EditorPlugin } from 
"@stackoverflow/stacks-editor";
  *
  * Works in both RichText and Markdown modes automatically.
  *
+ * @param getEditor Function that returns the StacksEditor instance
  * @param onUpdate Callback function that receives the updated editor content
  * @returns A StacksEditor EditorPlugin
  */
 export const createOnChangePlugin = (
+  getEditor: () => StacksEditor | null,
   onUpdate: (content: string) => void
 ): EditorPlugin => {
   return () => {
@@ -39,9 +41,14 @@ export const createOnChangePlugin = (
     const proseMirrorPlugin: any = new Plugin({
       view() {
         return {
-          update(view) {
+          update() {
             try {
-              const content = view.state.doc.textContent;
+              // Get the editor instance to access serialized markdown content
+              const editor = getEditor();
+              if (!editor) return;
+
+              // Use editor.content to get properly serialized markdown
+              const content = editor.content;
 
               // Only trigger callback if content actually changed
               if (content !== lastContent) {

Reply via email to