Eyk Rehbein
Eyk Rehbein

Reputation: 3868

Is it possible to update the value inside the Ace Editor without changing the position of the cursor?

I want to do something like a background worker. It should automatically update some code (at a different place than the cursor is) without moving the cursor to the last changed word. Is this possible with editor.session.replace or .insert?

Upvotes: 1

Views: 1307

Answers (1)

Harsha pps
Harsha pps

Reputation: 2208

One way of doing this is, Store the present cursor position, Insert the data and set the cursor position to the initial point.

//Get the Current Positon
var currentPosition = editor.selection.getCursor();

//Insert data into the editor
editor.setValue(data);
editor.clearSelection();

//Set the cursor to the Initial Point
editor.gotoLine(currentPosition.row, currentPosition.column);

Upvotes: 1

Related Questions