问题描述
当光标位置更改时,我想始终选择当前行。然后,通过按键删除该行并将其附加到div标签。我知道如何添加键盘命令。但是我不明白如何在 onCursorChange()
上做些什么,它似乎与 Editor.on( change,function(Object e))
。而且我也找不到如何删除所选行。这里提到了 onCursorChange()
,但并未真正描述如何使用它:
I want to always select the current line, when cursor position changes. And then remove that line with a keypress and append it to a div tag. I know how to add keybord commands. But i don't understand how to do something onCursorChange()
, it seems to be different from Editor.on("change", function(Object e))
. and also i don't find how remove the selected line. onCursorChange()
is mentioned here but not really described how to use it: 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 ---
}
});
更新14.06.2015 :
我现在解决了onCursorChange()事件。仅通过定义以下键盘操作即可:
UPDATE 14.06.2015:I solved it now without onCursorChange() event. Only by defining this keyboard action:
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();
}
});
推荐答案
我认为编辑器中存在错误。onCursorChange ();
我使用了editor.on( changeSelection,function(){做什么});
对我有用,祝您好运。
I think there is a bug on the editor.onCursorChange();I used editor.on("changeSelection",function(){do whatever});it work for me, good luck.
这篇关于Ace编辑器API:如何在onCursorChange中选择当前行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!