keymaps.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { keymap } from '@codemirror/view'
  2. import { defaultKeymap, historyKeymap } from '@codemirror/commands'
  3. import { lintKeymap } from '@codemirror/lint'
  4. import { scrollOneLineKeymap } from './scroll-one-line'
  5. import { foldingKeymap } from './folding-keymap'
  6. const ignoredDefaultKeybindings = new Set([
  7. // NOTE: disable "Mod-Enter" as it's used for "Compile"
  8. 'Mod-Enter',
  9. // Disable Alt+Arrow as we have special behaviour on Windows / Linux
  10. 'Alt-ArrowLeft',
  11. 'Alt-ArrowRight',
  12. // This keybinding causes issues on some keyboard layouts where \ is entered
  13. // using AltGr. Windows treats Ctrl-Alt as AltGr, so trying to insert a \
  14. // with Ctrl-Alt would trigger this keybinding, rather than inserting a \
  15. 'Mod-Alt-\\',
  16. ])
  17. const ignoredDefaultMacKeybindings = new Set([
  18. // We replace these with our custom visual-line versions
  19. 'Mod-Backspace',
  20. 'Mod-Delete',
  21. ])
  22. const filteredDefaultKeymap = defaultKeymap.filter(
  23. // We only filter on keys, so if the keybinding doesn't have a key,
  24. // allow it
  25. item => {
  26. if (item.key && ignoredDefaultKeybindings.has(item.key)) {
  27. return false
  28. }
  29. if (item.mac && ignoredDefaultMacKeybindings.has(item.mac)) {
  30. return false
  31. }
  32. return true
  33. }
  34. )
  35. export const keymaps = keymap.of([
  36. ...filteredDefaultKeymap,
  37. ...historyKeymap,
  38. ...lintKeymap,
  39. ...foldingKeymap,
  40. ...scrollOneLineKeymap,
  41. ])