Merge pull request #159 from tophf/track-active-codebox
Editor: sticky .CodeMirror-active class for code boxes
This commit is contained in:
commit
fceda3f27d
25
edit.js
25
edit.js
|
@ -310,8 +310,16 @@ function setupCodeMirror(textarea, index) {
|
||||||
cm.on("blur", function(cm) {
|
cm.on("blur", function(cm) {
|
||||||
editors.lastActive = cm;
|
editors.lastActive = cm;
|
||||||
hotkeyRerouter.setState(true);
|
hotkeyRerouter.setState(true);
|
||||||
|
setTimeout(function() {
|
||||||
|
var cm = editors.lastActive;
|
||||||
|
var childFocused = cm.display.wrapper.contains(document.activeElement);
|
||||||
|
cm.display.wrapper.classList.toggle("CodeMirror-active", childFocused);
|
||||||
|
}, 0);
|
||||||
|
});
|
||||||
|
cm.on("focus", function() {
|
||||||
|
hotkeyRerouter.setState(false);
|
||||||
|
cm.display.wrapper.classList.add("CodeMirror-active");
|
||||||
});
|
});
|
||||||
cm.on("focus", hotkeyRerouter.setState.bind(null, false));
|
|
||||||
|
|
||||||
var resizeGrip = cm.display.wrapper.appendChild(document.createElement("div"));
|
var resizeGrip = cm.display.wrapper.appendChild(document.createElement("div"));
|
||||||
resizeGrip.className = "resize-grip";
|
resizeGrip.className = "resize-grip";
|
||||||
|
@ -600,6 +608,7 @@ function setupGlobalSearch() {
|
||||||
originalOpenDialog.call(cm, template.innerHTML, callback.bind(cb), opt);
|
originalOpenDialog.call(cm, template.innerHTML, callback.bind(cb), opt);
|
||||||
};
|
};
|
||||||
setTimeout(function() { cm.openDialog = originalOpenDialog; }, 0);
|
setTimeout(function() { cm.openDialog = originalOpenDialog; }, 0);
|
||||||
|
refocusMinidialog(cm);
|
||||||
}
|
}
|
||||||
|
|
||||||
function focusClosestCM(activeCM) {
|
function focusClosestCM(activeCM) {
|
||||||
|
@ -786,6 +795,7 @@ function setupGlobalSearch() {
|
||||||
|
|
||||||
function jumpToLine(cm) {
|
function jumpToLine(cm) {
|
||||||
var cur = cm.getCursor();
|
var cur = cm.getCursor();
|
||||||
|
refocusMinidialog(cm);
|
||||||
cm.openDialog(template.jumpToLine.innerHTML, function(str) {
|
cm.openDialog(template.jumpToLine.innerHTML, function(str) {
|
||||||
var m = str.match(/^\s*(\d+)(?:\s*:\s*(\d+))?\s*$/);
|
var m = str.match(/^\s*(\d+)(?:\s*:\s*(\d+))?\s*$/);
|
||||||
if (m) {
|
if (m) {
|
||||||
|
@ -794,6 +804,19 @@ function jumpToLine(cm) {
|
||||||
}, {value: cur.line+1});
|
}, {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) {
|
function nextPrevEditor(cm, direction) {
|
||||||
cm = editors[(editors.indexOf(cm) + direction + editors.length) % editors.length];
|
cm = editors[(editors.indexOf(cm) + direction + editors.length) % editors.length];
|
||||||
makeSectionVisible(cm);
|
makeSectionVisible(cm);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user