Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to append data with api #682

Open
lz520520 opened this issue Sep 5, 2024 · 2 comments
Open

how to append data with api #682

lz520520 opened this issue Sep 5, 2024 · 2 comments

Comments

@lz520520
Copy link

lz520520 commented Sep 5, 2024

If the data is updated externally, it is currently done by modifying the value, but this causes the entire content to be re-rendered, I would like to append new data without affecting the original content, how can this be achieved, I checked the documentation and didn't find any way to do this.

@jaywcjlove
Copy link
Member

@lz520520 I have a component(uiwjs/react-markdown-editor/core/src/commands/code.tsx) that might help with your issue. You can refer to the following example for updating the method:

    view.dispatch({
      changes: {
        from: main.from,
        to: main.to,
        insert: `\`\`\`js\n${txt}\n\`\`\``,
      },
      selection: EditorSelection.range(main.from + 3, main.from + 5),
    });

@lz520520
Copy link
Author

Thank you very much, referring to the example you provided I solved the problem, the following is my demo, used to append data at the end of the editor

  const appendText = (text: string) => {
      const view = editorRef.current?.view as EditorView;
      view.dispatch({
          changes: { from: view.state.doc.length, insert:  text},
      });
  };

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants