scniro / react-codemirror2

Codemirror integrated components for React
MIT License
1.66k stars 193 forks source link

The cursor jump to end of content when edit #114

Closed falltodis closed 5 years ago

falltodis commented 5 years ago

Excuse me I meet a problem that the cursor would jump to end of content when editing. The main code should like

  onChange = (editor, data, value) => {
    console.log({ data, value });
    this.setState({
      value,
    });
  };

  renderCodeMirror = () => {
    const options = {
      mode: 'javascript',
      lineNumbers: true,
      tabSize: '2',
    };

    return (
      <CodeMirror
        value={this.state.value}
        options={options}
        onChange={this.onChange}
      />
    );
  };

It is not work when setting autoCursor = false too.

rolandgnm commented 5 years ago

What's the environment you are running into this issue @falltodis? I'm facing a similar issue on Windows/Chrome/react-codemirror2:v4.3. On OSX it doesn't happen.

scniro commented 5 years ago

@falltodis @rolandgnm try to use onBeforeChange as opposed to onChange per the controlled usage. Let me know if this helps?

falltodis commented 5 years ago

@scniro It works, thanks very much!

scniro commented 5 years ago

@falltodis 👍

Sent with GitHawk