uiwjs / react-codemirror

CodeMirror 6 component for React. @codemirror https://uiwjs.github.io/react-codemirror/
https://uiwjs.github.io/react-codemirror/
MIT License
1.52k stars 126 forks source link

@supunkavinda There is no such problem in the example. #529

Open 58bcbedf47bd91439c opened 1 year ago

58bcbedf47bd91439c commented 1 year ago
          @supunkavinda There is no such problem in the example.

https://codesandbox.io/embed/react-codemirror-example-codemirror-6-slvju?fontsize=14&hidenavigation=1&theme=dark

Originally posted by @jaywcjlove in https://github.com/uiwjs/react-codemirror/issues/261#issuecomment-1040119334

58bcbedf47bd91439c commented 1 year ago
import React, { useState } from "react";
import CodeMirror from "@uiw/react-codemirror";
import { javascript } from "@codemirror/lang-javascript";

export default function App() {
  const [code, setCode] = useState('')
  const onChange = React.useCallback((value, viewUpdate) => {
    console.log("value:", value);
  }, []);
  setTimeout(() => {
    setCode('123')
  }, 5000)
  return (
    <div>
      <CodeMirror
        value={code}
        height="200px"
        theme="dark"
        extensions={[javascript({ jsx: true })]}
        onChange={onChange}
      />
      <CodeMirror
        value="console.log('hello world!');"
        height="200px"
        extensions={[javascript({ jsx: true })]}
        onChange={(value, viewUpdate) => {
          console.log("value:", value);
        }}
      />
    </div>
  );
}

Assuming setTimeout is the initialization interface calling interface, obtain the code of the remote interface

jaywcjlove commented 1 year ago

@58bcbedf47bd91439c What's wrong with the example

58bcbedf47bd91439c commented 1 year ago

@58bcbedf47bd91439c What's wrong with the example

Hello, for the first time entering, ctrl+z will clear all content

jaywcjlove commented 1 year ago

@58bcbedf47bd91439c This is the system shortcut key "undo previous step" operation. You can disable this shortcut

58bcbedf47bd91439c commented 1 year ago

@58bcbedf47bd91439c This is the system shortcut key "undo previous step" operation. You can disable this shortcut

How to disable it? I couldn't find this setting

jaywcjlove commented 1 year ago

@58bcbedf47bd91439c https://codesandbox.io/embed/react-codemirror-example-codemirror-6-https-github-com-uiwjs-react-codemirror-issues-529-srgk4x?fontsize=14&hidenavigation=1&theme=dark

<CodeMirror
  value="console.log('hello world!');"
  height="200px"
  theme="dark"
  basicSetup={{
+    history: false
  }}
  extensions={[javascript({ jsx: true })]}
  onChange={onChange}
/>