Skip to content

Commit f8d41a1

Browse files
committed
Track last editor focused and refocus when window refocuses
In desktop VScode, focus gets lost when Alt-Tabbing or switching tab views (unlike tabbing around a browser, which remembers) Do some focus-tracking for the various codemirror instances. This is likely not perfect yet, but it's a lot better Addresses jpolitz/pyret-parley-vscode#13
1 parent 17dd4e1 commit f8d41a1

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/web/js/beforePyret.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ $(function() {
152152
animationDiv = null;
153153
}
154154
}
155+
let activeEditor = null;
155156
CPO.makeEditor = function(container, options) {
156157
var initial = "";
157158
if (options.hasOwnProperty("initial")) {
@@ -230,6 +231,9 @@ $(function() {
230231
cmOptions = merge(cmOptions, options.cmOptions || {});
231232

232233
var CM = CodeMirror.fromTextArea(textarea[0], cmOptions);
234+
CM.on("focus", () => {
235+
activeEditor = CM;
236+
});
233237

234238
function firstLineIsNamespace() {
235239
const firstline = CM.getLine(0);
@@ -1417,6 +1421,10 @@ $(function() {
14171421

14181422
});
14191423

1424+
window.addEventListener("focus", (e) => {
1425+
if(activeEditor) { activeEditor.focus(); }
1426+
});
1427+
14201428
function makeEvent() {
14211429
const handlers = [];
14221430
function on(handler) {

0 commit comments

Comments
 (0)