【发布时间】:2015-01-21 04:52:16
【问题描述】:
我在 Bootstrap 3 模式中嵌入了一个 Ace 编辑器。在显示模态之前,我在编辑器中设置了这样的值:
var editor = ace.edit(aceEditorId);
editor.session.setValue(val, -1); // set value at document start
editor.session.selection.clearSelection();
我还有一个用于调整编辑器大小的模式的“显示”事件处理程序:
$(editSnippetSelector).on("shown.bs.modal", function () {
var editorId = getSnippetEditorId();
var snippetEditor = ace.edit(editorId);
snippetEditor.resize();
当我专注于 Firefox 中的编辑器时,所有的编辑器文本都会被选中。我无法移动光标或通过单击删除选择。我只能通过按退格键或其他键(例如字母或回车键)擦除文本。
这在 Chrome 或 IE 中不会发生。
作为实验,我也添加了这段代码,但无济于事:
codeEditor.on("focus", function () {
codeEditor.getSession().setValue(codeEditor.getSession().getValue());
codeEditor.clearSelection();
});
我还应该去哪里看?有没有其他人看到过类似的行为?
更新:
我注意到ace.js 中有一个onSelect 函数在无限循环中被调用。上线2061:https://github.com/ajaxorg/ace-builds/blob/master/src-noconflict/ace.js#L2061
这里是函数的代码:
var onSelect = function(e) {
if (copied) {
copied = false;
} else if (isAllSelected(text)) {
host.selectAll();
resetSelection();
} else if (inputHandler) {
resetSelection(host.selection.isEmpty());
}
};
浏览 Firefox 调试器中的代码显示,对 isAllSelected(text) 的调用返回 true,因此再次引发了选择事件。
【问题讨论】:
标签: firefox ace-editor