Skip to content

Commit b7b4269

Browse files
committed
[search addon] Adjust patch 5c6025a
Issue codemirror#4050
1 parent 5c6025a commit b7b4269

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

addon/search/search.js

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -57,26 +57,13 @@
5757
return cm.getSearchCursor(query, pos, queryCaseInsensitive(query));
5858
}
5959

60-
function persistentDialog(cm, text, deflt, f) {
61-
cm.openDialog(text, f, {
60+
function persistentDialog(cm, text, deflt, onEnter, onKeyDown) {
61+
cm.openDialog(text, onEnter, {
6262
value: deflt,
6363
selectValueOnOpen: true,
6464
closeOnEnter: false,
6565
onClose: function() { clearSearch(cm); },
66-
onKeyDown: function(ev, query) {
67-
var cmd = CodeMirror.keyMap['default'][CodeMirror.keyName(ev)];
68-
if (cmd) {
69-
var nextSearchCmds = ['findNext', 'findPrev'];
70-
var searchCmds = ['find', 'findPersistent'];
71-
if (nextSearchCmds.indexOf(cmd) !== -1) {
72-
startSearch(cm, getSearchState(cm), query);
73-
CodeMirror.commands[cmd](cm);
74-
CodeMirror.e_stop(ev);
75-
} else if (searchCmds.indexOf(cmd) !== -1) {
76-
f(query, ev);
77-
}
78-
}
79-
}
66+
onKeyDown: onKeyDown
8067
});
8168
}
8269

@@ -132,7 +119,7 @@
132119
var q = cm.getSelection() || state.lastQuery;
133120
if (persistent && cm.openDialog) {
134121
var hiding = null
135-
persistentDialog(cm, queryDialog, q, function(query, event) {
122+
var searchNext = function(query, event) {
136123
CodeMirror.e_stop(event);
137124
if (!query) return;
138125
if (query != state.queryText) {
@@ -147,6 +134,17 @@
147134
dialog.getBoundingClientRect().bottom - 4 > cm.cursorCoords(to, "window").top)
148135
(hiding = dialog).style.opacity = .4
149136
})
137+
};
138+
persistentDialog(cm, queryDialog, q, searchNext, function(event, query) {
139+
var cmd = CodeMirror.keyMap[cm.getOption("keyMap")][CodeMirror.keyName(event)];
140+
if (cmd == "findNext" || cmd == "findPrev") {
141+
CodeMirror.e_stop(event);
142+
startSearch(cm, getSearchState(cm), query);
143+
cm.execCommand(cmd);
144+
} else if (cmd == "find" || cmd == "findPersistent") {
145+
CodeMirror.e_stop(event);
146+
searchNext(query, event);
147+
}
150148
});
151149
} else {
152150
dialog(cm, queryDialog, "Search for:", q, function(query) {

0 commit comments

Comments
 (0)