How To Set Focus On The Ace Editor?
I am using the ace editor component from ajax.org inside a jquery tab interface. Each tab will contain a separate ace editor. Whenever I switch to a new tab, the editor in it won't
Solution 1:
editor.focus(); //To focus the ace editorvar n = editor.getSession().getValue().split("\n").length; // To count total no. of lines
editor.gotoLine(n); //Go to end of document
Solution 2:
To focus to the end:
editor.focus();
editor.navigateFileEnd();
Thanks to @a-user
Solution 3:
Nice solution, but I wanted to go to the end of the last line not the beginning of the last line.
//To focus the ace editor
editor.focus();
session = editor.getSession();
//Get the number of lines
count = session.getLength();
//Go to end of the last line
editor.gotoLine(count, session.getLine(count-1).length);
Solution 4:
Here's an excerpt from my code that sets the focus on an Ace edit session in a jQuery UI tab:
$('#tabs_div').tabs(
{
select : function(event, ui) {
var tabName = ui.panel.id;
var doc = docs.get(tabName); // look up the EditSessionvar session = env.split.setSession(doc);
session.name = tabName;
env.editor.focus();
}
Solution 5:
I use JQuery with the Ace Editor, and I found the following code worked really nicely for me. PS: My Code Editor Window is in an Iframe:
$('#modelFrame').mouseover(function() {
try {
$(this).get(0).contentWindow.editor.focus();
} catch (doNothing) {
;;
}
});
Post a Comment for "How To Set Focus On The Ace Editor?"