Editor: focus the minidialog when switching find/replace

Previously, when a search minidialog was displayed and we pressed a hotkey to switch to another kind of minidialog (search -> replace, etc), the focus wasn't correctly preserved
This commit is contained in:
tophf 2015-10-29 21:20:05 +03:00
parent 7ca69e61da
commit 3837ef5f62

15
edit.js
View File

@ -608,6 +608,7 @@ function setupGlobalSearch() {
originalOpenDialog.call(cm, template.innerHTML, callback.bind(cb), opt);
};
setTimeout(function() { cm.openDialog = originalOpenDialog; }, 0);
refocusMinidialog(cm);
}
function focusClosestCM(activeCM) {
@ -794,6 +795,7 @@ function setupGlobalSearch() {
function jumpToLine(cm) {
var cur = cm.getCursor();
refocusMinidialog(cm);
cm.openDialog(template.jumpToLine.innerHTML, function(str) {
var m = str.match(/^\s*(\d+)(?:\s*:\s*(\d+))?\s*$/);
if (m) {
@ -802,6 +804,19 @@ function jumpToLine(cm) {
}, {value: cur.line+1});
}
function refocusMinidialog(cm) {
var section = getSectionForCodeMirror(cm);
if (!section.querySelector(".CodeMirror-dialog")) {
return;
}
// close the currently opened minidialog
cm.focus();
// make sure to focus the input in newly opened minidialog
setTimeout(function() {
section.querySelector(".CodeMirror-dialog").focus();
}, 0);
}
function nextPrevEditor(cm, direction) {
cm = editors[(editors.indexOf(cm) + direction + editors.length) % editors.length];
makeSectionVisible(cm);