Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to move the cursor to the end of the line in ACE Editor?

Inside my Javascript file I have the following lines of code:

editor.focus(); // To focus the ace editor
var n = editor.getSession().getValue().split("\n").length - 2;
editor.gotoLine(n); 

This focuses the ACE editor, moves to the last line, and goes up two lines. When it goes up those two lines it also moves the cursor to the front of that line. Simulating someone pressing the Home key.

Q: How do I move the cursor to the end of the line? Or simulate the End Key?

like image 755
programking Avatar asked Dec 23 '14 17:12

programking


People also ask

How do you move the cursor to the end of a line?

To move to the end of the current line, use [Ctrl [E]. To move the cursor forward one word on the current line, use [Alt] [F]; to move the cursor backwards one word on the current line, use [Alt] [B]. How do you move backward in bash?

How do you move the cursor forward and back in Linux?

Ctrl+B or Left Arrow – moves the cursor back one character at a time. Ctrl+F or Right Arrow – moves the cursor forward one character at a time. How do you move the cursor to the end of the line in terminal?

How do I jump to the last point of an edit?

You can follow the question or vote as helpful, but you cannot reply to this thread. Ctrl+End to go to the end of a document. Ctrl+Home to go the start of a document. In 2003 and prior, and 2010 you can also use Shft+F5 to jump to the last point of edit, even after a shutdown.

Are keyboard shortcuts universal across text editors?

One of the skills you can develop to increase productivity is your ability to navigate around a text editor using keyboard shortcuts instead of a mouse. However not all shortcuts are equally useful nor are they all universal across text editors.


2 Answers

gotoline takes two arguments one for row and one for column

var row = editor.session.getLength() - 1
var column = editor.session.getLine(row).length // or simply Infinity
editor.gotoLine(row + 1, column)

Note that gotoLine scrolls selection into view with an animation, If you do not want that you can use

editor.selection.moveTo(row, column)

instead.

To simulate the end key exactly the way it is handled when the user presses end use

editor.execCommand("gotolineend")
like image 141
a user Avatar answered Nov 15 '22 15:11

a user


Straight from API:

The method

You want to use the method navigateLineEnd(). So in your case:

editor.focus(); // To focus the ace editor
var n = editor.getSession().getValue().split("\n").length - 2;
editor.gotoLine(n); 
editor.navigateLineEnd() // Navigate to end of line
like image 26
programking Avatar answered Nov 15 '22 16:11

programking