keymaps.ts 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. // Disable toggleTabFocusMode as it conflicts with ” on a Swedish keyboard layout
  22. 'Shift-Alt-m',
  23. ])
  24. const filteredDefaultKeymap = defaultKeymap.filter(
  25. // We only filter on keys, so if the keybinding doesn't have a key,
  26. // allow it
  27. item => {
  28. if (item.key && ignoredDefaultKeybindings.has(item.key)) {
  29. return false
  30. }
  31. if (item.mac && ignoredDefaultMacKeybindings.has(item.mac)) {
  32. return false
  33. }
  34. return true
  35. }
  36. )
  37. export const keymaps = keymap.of([
  38. // The default CodeMirror keymap, with a few key bindings filtered out.
  39. ...filteredDefaultKeymap,
  40. // Key bindings for undo/redo/undoSelection/redoSelection
  41. ...historyKeymap,
  42. // Key bindings for “open lint panel” and “next diagnostic”
  43. ...lintKeymap,
  44. // Key bindings for folding actions
  45. ...foldingKeymap,
  46. // Key bindings for scrolling the viewport
  47. ...scrollOneLineKeymap,
  48. ])