-
-
Notifications
You must be signed in to change notification settings - Fork 135
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
Merge view - jumping onChange #681
Comments
@natocTo upgrade import React, { useState } from 'react';
import CodeMirrorMerge from 'react-codemirror-merge';
const Original = CodeMirrorMerge.Original;
const Modified = CodeMirrorMerge.Modified;
let doc = `one
two
three
four
five`;
export default function App() {
const [value, setValue] = useState(doc);
const [valueModified, setValueModified] = useState(doc);
return (
<div>
<CodeMirrorMerge destroyRerender={false}>
<Original
onChange={(val) => {
console.log('~~:1', val);
setValue(val);
}}
value={value}
/>
<Modified
onChange={(val) => {
console.log('~~:2', val);
setValueModified(val);
}}
value={valueModified}
/>
</CodeMirrorMerge>
<div style={{ display: 'flex', marginTop: 10 }}>
<pre style={{ flex: 1 }}>{value} </pre>
<pre style={{ backgroundColor: '#fff', flex: 1 }}>{valueModified} </pre>
</div>
</div>
);
} |
@jaywcjlove Thank you for the update! |
@cjayyy After the react-codemirror/merge/src/Internal.tsx Lines 67 to 90 in e79b1f3
If your extensions are asynchronous, add them to the editor. react-codemirror/www/src/pages/examples/Example681.tsx Lines 49 to 53 in e26ca15
Implementing extensions updates inside the editor causes errors, and I haven't found a solution for this. It may require support from the CodeMirror team, and you can seek answers from their community. react-codemirror/merge/src/Internal.tsx Lines 99 to 102 in e26ca15
|
Not using any async extensions. Even if I use only minimal setup like below, <CodeMirrorMerge destroyRerender={false}>
<CodeMirrorMerge.Original
value="first"
extensions={[EditorView.editable.of(false), EditorState.readOnly.of(true)]}
/>
<CodeMirrorMerge.Modified value="second" />
</CodeMirrorMerge> |
@cjayyy My example test didn't have any issues -> https://uiwjs.github.io/react-codemirror/#/examples/681 react-codemirror/www/src/pages/examples/Example681.tsx Lines 59 to 66 in e26ca15
|
Oh I overlooked you published version 4.23.2 - with that it works! (4.23.1. didn't work for me). |
Thank you. It looks like the original issue with lines jumping is fixed now. We are still struggling with another (probably) unrelated issue though;
Could please point me into the right direction? 🙏 |
@jaywcjlove it looks like after update to v4.23.1 (and newer) the onChange is actually not called at all. Check this sandbox - https://codesandbox.io/p/sandbox/gracious-chandrasekhar-zqmsy9?file=%2Fsrc%2FApp.js it should show alert when updating a value. But it is not called. |
@natocTo I suggest using the approach in the example below to handle the onChange event. <Modified
onChange={(val) => {
console.log('~~:2', val);
setValueModified(val);
}}
value={valueModified}
/> |
Hi @jaywcjlove I did not realize the sandbox may change after I send a link, I used onChange originally. Please check sandbox again. There is onChange but it is never called. https://codesandbox.io/p/sandbox/gracious-chandrasekhar-zqmsy9?file=%2Fsrc%2FApp.js%3A1%2C1-39%2C1 |
@natocTo https://codesandbox.io/p/sandbox/nostalgic-leakey-3frkm2?workspaceId=dca383b2-9fa2-4898-b548-3527e348e0e1 2024-11-01.15.33.03.2024-11-01.15.33.19.mp4import React, { useState } from "react";
import CodeMirrorMerge from "react-codemirror-merge";
import { EditorView } from "codemirror";
import { EditorState } from "@codemirror/state";
const Original = CodeMirrorMerge.Original;
const Modified = CodeMirrorMerge.Modified;
let doc = `one
two
three
four
five`;
export default function App() {
const [value, setValue] = useState(doc);
const [valueModified, setValueModified] = useState(doc);
return (
<div>
<CodeMirrorMerge destroyRerender={false}>
<Original
extensions={[
EditorView.editable.of(false),
EditorState.readOnly.of(true),
]}
onChange={(val) => {
console.log("~~:1", val);
setValue(val);
}}
value={value}
/>
<Modified
extensions={[
EditorView.editable.of(true),
EditorState.readOnly.of(false),
]}
onChange={(val) => {
console.log("~~:2", val);
setValueModified(val);
}}
value={valueModified}
/>
</CodeMirrorMerge>
<div style={{ display: "flex", marginTop: 10 }}>
<pre style={{ flex: 1 }}>{value} </pre>
<pre style={{ backgroundColor: "#fff", flex: 1 }}>{valueModified} </pre>
</div>
</div>
);
} |
@jaywcjlove thank you! Can you elaborate more why it is working for you? It is because of It looks like it is false by default https://github.com/uiwjs/react-codemirror/blob/v4.23.6/merge/src/index.tsx#L12 |
react-codemirror/merge/src/Internal.tsx Lines 118 to 159 in 8b091c3
@natocTo |
@jaywcjlove I'm having the same issue as @natocTo on |
react-codemirror/merge/src/Internal.tsx Lines 99 to 102 in ab89f28
@kyleqian This is a temporary workaround for when the extension update fails. |
Hello,
we are trying to implement merge view into our app and we came across this behaviour.
There is a simple sandbox: https://codesandbox.io/p/sandbox/competent-tom-8zpsy7
Please try to enter severals new lines (for example 50) into second editor (I just keep presed enter for while). When it hits certain point the view "jump" up over active cursor. And anytime you enter another char there (on some latest lines usually), it behave same (jump a little bit up). So it is really hard to write something there.
Did I miss some setting I have to use? Thank you very much for any help.
The text was updated successfully, but these errors were encountered: