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 achieve editorDidMount functionality #675

Open
IntelligaiaVivek opened this issue Jul 22, 2024 · 3 comments
Open

How to achieve editorDidMount functionality #675

IntelligaiaVivek opened this issue Jul 22, 2024 · 3 comments

Comments

@IntelligaiaVivek
Copy link

IntelligaiaVivek commented Jul 22, 2024

@jaywcjlove
When the CodeMirror editor is mounted (i.e., initialized). It takes an _editorReference parameter like in codemirror2
same i need this here in @uiw/code-mirror , so it can perform custom initialization tasks when the editor is mounted, and also ensure that the editor is properly configured

<codemirror
editorDidMount={editorDidMount}
/>

so i can use this _editorReferenece state
const editorDidMount = (_editorReferenece: Editor) => {
}
and this _editorReferenece give like this
image
Appreciate your response

@jaywcjlove
Copy link
Member

/** The first time the editor executes the event. */
onCreateEditor?(view: EditorView, state: EditorState): void;

@IntelligaiaVivek I think you can use editorDidMount instead of componentDidMount.

@IntelligaiaVivek
Copy link
Author

@jaywcjlove Thanks will check for this and i also need to maintain the undo redo state for the editor can you show which option to add for that. Appreciate for your response

@jaywcjlove
Copy link
Member

The history feature can be enabled via a prop, and it is enabled by default. If you need to manage the history yourself, you should use history and disable the default history. @IntelligaiaVivek

import { history, redo, undo, historyKeymap } from "@codemirror/commands";

<CodeMirror
  extensions={[history(config: { joinToEvent:() => { /*....*/}  })]}
  basicSetup={{
    history: false,
  }}
/>

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