Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REPL: the "undo" keyboard shortcut may replace all the content in a file with content from another tab #456

Open
li6in9muyou opened this issue Apr 4, 2023 · 0 comments

Comments

@li6in9muyou
Copy link

reproduce

  1. go to https://svelte.dev/repl/6207fed523fa45038e285262cacee9e9
  2. you are at App.svelte initially and neither of the two tabs has star sign in it
  3. change to the a.js tab, which has "important stuff" in it
  4. press the keyboard shortcut for "undo" e.g. ctrl+z on windows

actual behaviour

Important stuff in a.js is gone, replaced by content of App.svelte. The "redo" shortcut will restore important stuff.

expected behaviour

The "undo" keyboard shortcut does nothing at step 4.

possible fix

Add entries to intercept the "undo" and "redo" commands in codemirror editor options, see below.

const opts = {
lineNumbers,
lineWrapping: true,
indentWithTabs: true,
indentUnit: 2,
tabSize: 2,
value: '',
mode: modes[mode] || {
name: mode
},
readOnly: readonly,
autoCloseBrackets: true,
autoCloseTags: true,
extraKeys: CodeMirror.normalizeKeyMap({
Enter: 'newlineAndIndentContinueMarkdownList',
'Ctrl-/': 'toggleComment',
'Cmd-/': 'toggleComment',
'Ctrl-Q': function (cm) {
cm.foldCode(cm.getCursor());
},
'Cmd-Q': function (cm) {
cm.foldCode(cm.getCursor());
},
// allow escaping the CodeMirror with Esc Tab
'Esc Tab': false
}),
foldGutter: true,
gutters: ['CodeMirror-linenumbers', 'CodeMirror-foldgutter'],
theme
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant