Ace Editor API:如何选择当前行onCursorChange?

时间:2015-05-26 10:24:24

标签: javascript ace-editor

当光标位置发生变化时,我想始终选择当前行。然后使用按键删除该行并将其附加到div标记。我知道如何添加keybord命令。但我不明白如何做某事onCursorChange(),它似乎与Editor.on("change", function(Object e))不同。而且我也没有找到如何删除选定的行。这里提到onCursorChange()但未真正描述如何使用它:http://ace.c9.io/#nav=api&api=editor

    // ACE Editor Setup
    var editor = ace.edit("editor");
    editor.setTheme("ace/theme/crimson_editor");
    editor.getSession().setMode("ace/mode/html");
    editor.setValue("textline1\n textline2\n textline3");
 // editor.on('onCursorChange', function() { editor.selection.selectLine(); });  // does not work
 // editor.onCursorChange(editor.selection.selectLine()); // or this - does also not work

    editor.commands.addCommand({
           name: 'myCommand',
           bindKey: {win: 'Ctrl-J',  mac: 'Command-J'},
           exec: function(editor) {
           --- DO REMOVE THE SELECTED CONTENT --- 
           }
        });

更新2015年6月14日: 我现在解决了它没有onCursorChange()事件。只有定义此键盘操作:

   editor.commands.addCommand({
       name: 'myCommand',
        bindKey: {win: 'Ctrl-Y',  mac: 'Command-Y'},
        exec: function(editor) {
            editor.selection.selectLine();
            myElem = editor.session.getTextRange(editor.getSelectionRange());
            $('#my_output_area').append(myElem);
            editor.removeLines();
       }
    });

2 个答案:

答案 0 :(得分:0)

我认为editor.onCursorChange()有一个错误; 我使用了editor.on(“changeSelection”,function(){do whatever}); 它对我有用,祝你好运。

答案 1 :(得分:0)

要选择当前行,请使用scrollToLine

editor.selection.selectLine();
相关问题