Skip to content

Commit 47699e7

Browse files
committed
Make a global for embed detection. Don't capture mod-S when embedded
This makes it so save events properly propagate out of the webview and to the surrounding context. This is a good thing for VScode
1 parent af5a300 commit 47699e7

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

src/web/js/beforePyret.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1460,15 +1460,18 @@ $(function() {
14601460

14611461
let initialState = params["get"]["initialState"];
14621462

1463+
window.PYRET_IS_EMBEDDED = false;
14631464
if (typeof acquireVsCodeApi === "function") {
14641465
window.MESSAGES = makeEvents({
14651466
CPO: CPO,
14661467
sendPort: acquireVsCodeApi(),
14671468
receivePort: window,
14681469
initialState
14691470
});
1471+
window.PYRET_IS_EMBEDDED = true;
14701472
}
14711473
else if((window.parent && (window.parent !== window))) {
14721474
window.MESSAGES = makeEvents({ CPO: CPO, sendPort: window.parent, receivePort: window, initialState });
1475+
window.PYRET_IS_EMBEDDED = true;
14731476
}
14741477
});

src/web/js/cpo-main.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -666,11 +666,17 @@
666666

667667
// save
668668
// On Mac mod ends up mapping to command+s whereas on Windows and Linux it maps to ctrl+s.
669-
Mousetrap.bindGlobal('mod+s', function(e) {
670-
CPO.save();
671-
e.stopImmediatePropagation();
672-
e.preventDefault();
673-
});
669+
// Saving has a special condition: when embedded we want the Ctrl-S to
670+
// propagate up. We could fire a special “save” event, but for contexts
671+
// like VScode it is nice to have the “real” Cmd-S event fire to get
672+
// good default behavior
673+
if(!PYRET_IS_EMBEDDED) {
674+
Mousetrap.bindGlobal('mod+s', function(e) {
675+
CPO.save();
676+
e.stopImmediatePropagation();
677+
e.preventDefault();
678+
});
679+
}
674680

675681
// resize, Toggle sizing of the editor window between 50% and last resize
676682
Mousetrap.bindGlobal('ctrl+m', function(e){

0 commit comments

Comments
 (0)