-
-
Notifications
You must be signed in to change notification settings - Fork 142
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
Request for onChange Event or Value Change Subscription in react-codemirror-merge #502
Comments
@kwonth211 Upgrade import CodeMirrorMerge from 'react-codemirror-merge';
const Original = CodeMirrorMerge.Original;
const Modified = CodeMirrorMerge.Modified;
<CodeMirrorMerge
revertControls="a-to-b"
style={{ height: 300, overflow: 'auto' }}
>
<Original
value={originalCode}
onChange={(value) => {
console.log('value3:', value)
}}
/>
<Modified
value={modifiedCode}
onChange={(value) => {
console.log('value3:', value)
}}
/>
</CodeMirrorMerge> |
Thanks! |
I have followed your instructions and updated to version 4.20.0, and have also implemented the provided interface. However, the onChange events are still not working as expected. Could you please provide further guidance or suggestions on how to resolve this issue? Thank you. |
<CodeMirrorMerge
+ revertControls="a-to-b"
style={{ height: 300, overflow: 'auto' }}
> |
Here is my code. I have followed the provided example and used the code exactly as written, import React, { useEffect } from 'react'
import styled from 'styled-components'
import CodeMirrorMerge from 'react-codemirror-merge'
import { EditorView, ViewUpdate } from '@codemirror/view'
import { EditorState } from '@codemirror/state'
import CodeMirror, { ReactCodeMirrorProps } from '@uiw/react-codemirror'
const Original = CodeMirrorMerge.Original
const Modified = CodeMirrorMerge.Modified
export interface JsonDiffProps {
prevJson: string
nextJson: string
onChangePrevJson?: (value: string) => void
onChangeNextJson?: (value: string) => void
prevJsonProps?: {
readonly?: boolean
height?: string
width?: string
title?: React.ReactNode
}
nextJsonProps?: {
readonly?: boolean
height?: string
width?: string
title?: React.ReactNode
}
}
export const JsonDiff = function JSONDiff({
prevJson,
nextJson,
onChangePrevJson,
onChangeNextJson,
prevJsonProps,
nextJsonProps,
}: JsonDiffProps) {
// console.log(A.EditorState)
return (
<Container>
<CodeMirrorMerge
revertControls="a-to-b"
style={{ height: 300, overflow: 'auto' }}
>
<Original
value={prevJson}
onChange={(value) => {
console.log('value3:', value)
}}
/>
<Modified
value={nextJson}
onChange={(value) => {
console.log('value3:', value)
}}
/>
</CodeMirrorMerge>
</Container>
)
} |
I am still experiencing the same issue with the onChange events not working, even after updating to version 4.20.2. I have tried using the exact example code provided in the documentation, but it didn't resolve the problem. Could it be an issue with my current package versions? Here are my package versions for reference:
Any assistance or guidance would be greatly appreciated. Thank you! |
@kwonth211 Example: https://codesandbox.io/embed/react-codemirror-example-codemirror-6-https-github-com-uiwjs-react-codemirror-issues-502-min95l?fontsize=14&hidenavigation=1&theme=dark 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();
const onChange = React.useCallback((val) => {
console.log("value:", val);
setValue(val);
}, []);
return (
<div>
<CodeMirrorMerge>
<Original value={doc} onChange={onChange} />
<Modified
value={doc.replace(/t/g, "T") + "Six"}
onChange={(val) => {
console.log("value:222:", val);
}}
/>
</CodeMirrorMerge>
<pre>{value}</pre>
</div>
);
} |
It's broken in |
|
I'm currently using react-codemirror-merge and would like to detect onChange events or subscribe to value changes.
Is there a way to achieve this functionality? Any insight or suggestions on how to implement this would be greatly appreciated. Thanks in advance!
The text was updated successfully, but these errors were encountered: