I want to set the location of cursor to line 3, but no method found.
Assuming you have atleast 3 lines in your editor you can tell the editor to go to a line no
editor.goToLine(3);
@hihl does @Vijayk93 's comment solve your issue?
Okay, but is there a way to do that via this React component?
@MarkH817 By React Component what do you mean exactly?Editor instance is provided by the ace editor.So moving between lines is a job of the editor rather than ReactAce Component instance.I hope this answered your question
The code snippet in the FAQ explaining this solution isn't really simple nor complete. It was at least confusing to me since I've never used "refs" in React before.
The below snippet was essentially all that was needed to do this.
someMethod (lineNumber) {
this.refs.aceEditor.editor.gotoLine(lineNumber)
}
render () {
// ...
return (<AceEditor ref='aceEditor' />)
}
@MarkH817 'refs' in React are references to the component instance.React basically will let u add a scope instance using refs so that u can use the members of the component(instance) so to say.In the snippet you added Ace editor is gonna let u use the editor object using the refs 'aceEditor' which is passed as the ref prop.As I mentioned before playing around with current editor session is the job of the editor itself rather than overloading your 'AceEditor' parent component by attaching a ref
@MarkH817 I would appreciate any help to make the docs more clear for this. Feel free to open a PR to make it more clear.
so what happens when such line does not yet exist?? is there a way to move to the next line??
Most helpful comment
The code snippet in the FAQ explaining this solution isn't really simple nor complete. It was at least confusing to me since I've never used "refs" in React before.
The below snippet was essentially all that was needed to do this.