scniro / react-codemirror2

Codemirror integrated components for React
MIT License
1.65k stars 192 forks source link

Is there any example how to get setCursor & scrollTo to work? #48

Closed sipp11 closed 6 years ago

sipp11 commented 6 years ago

I have tried setting props to cursor & scroll but it doesn't seem to get <CodeMirror /> to move at all.

import { Controlled as CodeMirror } from 'react-codemirror2';

<CodeMirror
        className="content"
        value={this.state.fullText}
        options={options}
        cursor={cursor}
        scroll={this.state.scroll}
        onBeforeChange={(editor, data, value) => {
          this.setState({ fullText: value });
        }}
        onChange={this.updateCode.bind(this)}
        onCursor={this.updateCursor.bind(this)}
        onScroll={this.handleOnScroll.bind(this)}
 />

Every event initiated by my cursor can be captured, but when I change cursor or scroll programmatically, nothing changes.

I would be appreciated if you could guide me what I'm missing.

sipp11 commented 6 years ago

Oh I think I could get it work now. #40 has all this information.

editor.scrollTo(0, 40);
editor.setCursor({ line: 10, ch: 0 });

This works great. 👍