How to set focus on the ace editor?

后端 未结 5 524
轻奢々
轻奢々 2021-02-03 18:54

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 wo

相关标签:
5条回答
  • 2021-02-03 19:35

    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) {
            ;;
        }
    });
    
    0 讨论(0)
  • 2021-02-03 19:41

    To focus to the end:

    editor.focus();
    editor.navigateFileEnd();
    

    Thanks to @a-user

    0 讨论(0)
  • 2021-02-03 19:42

    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 EditSession
                            var session = env.split.setSession(doc);
                            session.name = tabName;
                            env.editor.focus();
                }
    
    0 讨论(0)
  • 2021-02-03 19:52
    editor.focus(); //To focus the ace editor
    var n = editor.getSession().getValue().split("\n").length; // To count total no. of lines
    editor.gotoLine(n); //Go to end of document
    
    0 讨论(0)
  • 2021-02-03 19:54

    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);
    
    0 讨论(0)
提交回复
热议问题