Ace Editor get current selected line number and text

白昼怎懂夜的黑 提交于 2019-12-05 00:11:52

问题


I'm currently using Ace Editor, but I couldn't find anything in the docs along the lines of retrieving the current selected line number and its text.

Any ideas?


回答1:


You can do this:

selectionRange = editor.getSelectionRange();

startLine = selectionRange.start.row;
endLine = selectionRange.end.row;

content = editor.session.getTextRange(selectionRange);



回答2:


First, define "selected line". Selection in ace may be set across multiple lines. If you mean "no selection is set, current line is line where cursor blinks:"

var currline = editor.getSelectionRange().start.row;
var wholelinetxt = editor.session.getLine(currline);

If you need exact selected text, see @parchment answer, I was about wrote the same, but it's not needed now.



来源:https://stackoverflow.com/questions/24906120/ace-editor-get-current-selected-line-number-and-text

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!