scniro / react-codemirror2

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

When I type in the middle, the cursor go to the end of line #170

Closed souuu closed 4 years ago

souuu commented 4 years ago

Hello, Does anyone have this problem ? When I type in the middle of the code, the cursor go to the end of line and start typing in the end.

<CodeMirror
        value={value}
        options={{
          mode: 'javascript',
          lineNumbers: true
        }}
        onChange={(editor, data, value) => {
          onChange(value)
        }}
      />

déc -16-2019 13-37-10 Does anyone know how to fix this ? Thank you,

souuu commented 4 years ago

The solution is that I have to use the controlled mode and onBeforeChange

      <CodeMirror
        value={value}
        options={{
          mode: 'javascript',
          lineNumbers: true
        }}
        onBeforeChange={(editor, data, value) => {
          onChange(value)
        }}
      />