Skip to content

Commit

Permalink
[search addon] Adjust patch 5c6025a
Browse files Browse the repository at this point in the history
  • Loading branch information
marijnh committed Jun 7, 2016
1 parent 5c6025a commit b7b4269
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions addon/search/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
}

Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down

0 comments on commit b7b4269

Please sign in to comment.