繁体   English   中英

如何将注意力集中在ace编辑器上?

[英]How to set focus on the ace editor?

我在jquery选项卡界面中使用ajax.org中的ace编辑器组件。 每个选项卡都包含一个单独的ace编辑器。 每当我切换到新选项卡时,其中的编辑器将无法获得焦点。

我可以通过绑定到jquery UI的“tabsshow”事件来检测何时选择了选项卡。 如果我的编辑器div的id是第一个选项卡的editor-tab-0,那么有没有人知道如何将焦点设置到其中的编辑器,依此类推......?

请帮助一下吗?

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

集中精力到最后:

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

感谢@ a-user

很好的解决方案,但我想要到最后一行的末尾而不是最后一行的开头。

//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);

这是我的代码的摘录,它将焦点放在jQuery UI选项卡中的Ace编辑会话上:

    $('#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();
            }

我在Ace编辑器中使用JQuery,我发现以下代码对我来说非常好用。 PS:我的代码编辑器窗口在Iframe中:

$('#modelFrame').mouseover(function() {
    try {
        $(this).get(0).contentWindow.editor.focus();
    } catch (doNothing) {
        ;;
    }
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM