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?
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?
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?
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.
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.
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")
Straight from API:
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With