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

CodeMirrorMerge gets unfocused on value change #566

Open
denbalogh opened this issue Sep 15, 2023 · 6 comments
Open

CodeMirrorMerge gets unfocused on value change #566

denbalogh opened this issue Sep 15, 2023 · 6 comments

Comments

@denbalogh
Copy link

When I use CodeMirrorMerge with onChange prop in the CodeMirrorMerge.Original component, the editor gets unfocused every time I change the value.

It is happening since the 4.21.2 update.

@denbalogh denbalogh changed the title CodeMirroMerge gets unfocused on value change CodeMirrorMerge gets unfocused on value change Sep 15, 2023
@denbalogh
Copy link
Author

Here's the issue in codesandbox https://codesandbox.io/s/bold-estrela-rzqwck?file=/src/App.js

@denbalogh
Copy link
Author

@jaywcjlove I updated to latest release and now it won't even render the editor. Codesandbox

@jaywcjlove
Copy link
Member

/**
* Default is `false`. If true, the editor will be destroyed and re-rendered every time the editor is updated.
*/
destroyRerender?: boolean;

@denbalogh I'm trying to fix it by adding a destroyRerender prop to turn off re-rendering the component on every update.

view.current?.a.dispatch({
changes: { from: 0, to: originalDoc.length, insert: original.doc || '' },
// effects: StateEffect.reconfigure.of([
// ...(originalExtension?.extension || []),
// ...getDefaultExtensions({ ...originalExtension?.option, theme }),
// ])
});

During the update, all extensions will be lost. If you add dispatch({ effects }), an @codemirror/merge internal error will be triggered.

So I thought of a compromise method and regenerated it after updating, which caused the onChange problem.

if (destroyRerender) {
view.current?.destroy();
view.current = new MergeView({
a: {
...original,
extensions: [
...(originalExtension?.extension || []),
...getDefaultExtensions({ ...originalExtension?.option, theme }),
],
},
b: {
...modified,
extensions: [
...(modifiedExtension?.extension || []),
...getDefaultExtensions({ ...modifiedExtension?.option, theme }),
],
},
parent: editor.current!,
...opts,
});
}

@denbalogh
Copy link
Author

@jaywcjlove Is that a difficult problem to solve, will it take long? Sorry to be a bother, but we count on this functionality in our project.

@jaywcjlove
Copy link
Member

@denbalogh
Copy link
Author

@jaywcjlove yes, seems like it is. Thank you, very appreciated 🙏

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