diff --git a/addon/search/search.js b/addon/search/search.js index 0f5d941889..00f53a0e01 100644 --- a/addon/search/search.js +++ b/addon/search/search.js @@ -57,26 +57,13 @@ return cm.getSearchCursor(query, pos, queryCaseInsensitive(query)); } - function persistentDialog(cm, text, deflt, f) { - cm.openDialog(text, f, { + function persistentDialog(cm, text, deflt, onEnter, onKeyDown) { + cm.openDialog(text, onEnter, { value: deflt, selectValueOnOpen: true, closeOnEnter: false, onClose: function() { clearSearch(cm); }, - onKeyDown: function(ev, query) { - var cmd = CodeMirror.keyMap['default'][CodeMirror.keyName(ev)]; - if (cmd) { - var nextSearchCmds = ['findNext', 'findPrev']; - var searchCmds = ['find', 'findPersistent']; - if (nextSearchCmds.indexOf(cmd) !== -1) { - startSearch(cm, getSearchState(cm), query); - CodeMirror.commands[cmd](cm); - CodeMirror.e_stop(ev); - } else if (searchCmds.indexOf(cmd) !== -1) { - f(query, ev); - } - } - } + onKeyDown: onKeyDown }); } @@ -132,7 +119,7 @@ var q = cm.getSelection() || state.lastQuery; if (persistent && cm.openDialog) { var hiding = null - persistentDialog(cm, queryDialog, q, function(query, event) { + var searchNext = function(query, event) { CodeMirror.e_stop(event); if (!query) return; if (query != state.queryText) { @@ -147,6 +134,17 @@ dialog.getBoundingClientRect().bottom - 4 > cm.cursorCoords(to, "window").top) (hiding = dialog).style.opacity = .4 }) + }; + persistentDialog(cm, queryDialog, q, searchNext, function(event, query) { + var cmd = CodeMirror.keyMap[cm.getOption("keyMap")][CodeMirror.keyName(event)]; + if (cmd == "findNext" || cmd == "findPrev") { + CodeMirror.e_stop(event); + startSearch(cm, getSearchState(cm), query); + cm.execCommand(cmd); + } else if (cmd == "find" || cmd == "findPersistent") { + CodeMirror.e_stop(event); + searchNext(query, event); + } }); } else { dialog(cm, queryDialog, "Search for:", q, function(query) {