keymaps.ts 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. // The default CodeMirror keymap, with a few key bindings filtered out.
  37. ...filteredDefaultKeymap,
  38. // Key bindings for undo/redo/undoSelection/redoSelection
  39. ...historyKeymap,
  40. // Key bindings for “open lint panel” and “next diagnostic”
  41. ...lintKeymap,
  42. // Key bindings for folding actions
  43. ...foldingKeymap,
  44. // Key bindings for scrolling the viewport
  45. ...scrollOneLineKeymap,
  46. ])