Skip to content

Commit 1270941

Browse files
committed
disable undo if in VScode mode
1 parent f8d41a1 commit 1270941

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

src/web/js/beforePyret.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,7 @@ $(function() {
197197
console.log("Using keymap: ", CodeMirror.keyMap.default, "macDefault: ", CodeMirror.keyMap.macDefault, "mac: ", mac);
198198
const modifier = mac ? "Cmd" : "Ctrl";
199199

200-
var cmOptions = {
201-
extraKeys: CodeMirror.normalizeKeyMap({
200+
const extraKeys = {
202201
"Shift-Enter": function(cm) { runFun(cm.getValue()); },
203202
"Shift-Ctrl-Enter": function(cm) { runFun(cm.getValue()); },
204203
"Tab": "indentAuto",
@@ -211,7 +210,21 @@ $(function() {
211210
"Ctrl-Right": "goForwardToken",
212211
[`${modifier}-F`]: "findPersistent",
213212
[`${modifier}-/`]: "toggleComment",
214-
}),
213+
};
214+
if(window.PYRET_IN_VSCODE) {
215+
// Disable undo and redo in vscode, since they mess with the host editor's undo/redo stack
216+
// Oddly, it doesn't seem to work to add these to extraKeys; I have to
217+
// override them in the default keymap
218+
CodeMirror.keyMap.default[`${modifier}-Z`] = false;
219+
CodeMirror.keyMap.default[`Shift-${modifier}-Z`] = false;
220+
CodeMirror.keyMap.default[`${modifier}-Y`] = false;
221+
// Ctrl-U is Undo within a range
222+
CodeMirror.keyMap.default[`${modifier}-U`] = false;
223+
}
224+
225+
var cmOptions = {
226+
keyMap: 'default',
227+
extraKeys: CodeMirror.normalizeKeyMap(extraKeys),
215228
indentUnit: 2,
216229
tabSize: 2,
217230
viewportMargin: Infinity,
@@ -1469,6 +1482,7 @@ $(function() {
14691482
let initialState = params["get"]["initialState"];
14701483

14711484
window.PYRET_IS_EMBEDDED = false;
1485+
window.PYRET_IN_VSCODE = false;
14721486
if (typeof acquireVsCodeApi === "function") {
14731487
window.MESSAGES = makeEvents({
14741488
CPO: CPO,
@@ -1477,6 +1491,7 @@ $(function() {
14771491
initialState
14781492
});
14791493
window.PYRET_IS_EMBEDDED = true;
1494+
window.PYRET_IN_VSCODE = true;
14801495
}
14811496
else if((window.parent && (window.parent !== window))) {
14821497
window.MESSAGES = makeEvents({ CPO: CPO, sendPort: window.parent, receivePort: window, initialState });

0 commit comments

Comments
 (0)