index.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import { lineNumbers, highlightActiveLineGutter, highlightSpecialChars, drawSelection, dropCursor, rectangularSelection, crosshairCursor, highlightActiveLine, keymap } from '@codemirror/view';
  2. export { EditorView } from '@codemirror/view';
  3. import { EditorState } from '@codemirror/state';
  4. import { foldGutter, indentOnInput, syntaxHighlighting, defaultHighlightStyle, bracketMatching, foldKeymap } from '@codemirror/language';
  5. import { history, defaultKeymap, historyKeymap } from '@codemirror/commands';
  6. import { highlightSelectionMatches, searchKeymap } from '@codemirror/search';
  7. import { closeBrackets, autocompletion, closeBracketsKeymap, completionKeymap } from '@codemirror/autocomplete';
  8. import { lintKeymap } from '@codemirror/lint';
  9. // (The superfluous function calls around the list of extensions work
  10. // around current limitations in tree-shaking software.)
  11. /**
  12. This is an extension value that just pulls together a number of
  13. extensions that you might want in a basic editor. It is meant as a
  14. convenient helper to quickly set up CodeMirror without installing
  15. and importing a lot of separate packages.
  16. Specifically, it includes...
  17. - [the default command bindings](https://codemirror.net/6/docs/ref/#commands.defaultKeymap)
  18. - [line numbers](https://codemirror.net/6/docs/ref/#view.lineNumbers)
  19. - [special character highlighting](https://codemirror.net/6/docs/ref/#view.highlightSpecialChars)
  20. - [the undo history](https://codemirror.net/6/docs/ref/#commands.history)
  21. - [a fold gutter](https://codemirror.net/6/docs/ref/#language.foldGutter)
  22. - [custom selection drawing](https://codemirror.net/6/docs/ref/#view.drawSelection)
  23. - [drop cursor](https://codemirror.net/6/docs/ref/#view.dropCursor)
  24. - [multiple selections](https://codemirror.net/6/docs/ref/#state.EditorState^allowMultipleSelections)
  25. - [reindentation on input](https://codemirror.net/6/docs/ref/#language.indentOnInput)
  26. - [the default highlight style](https://codemirror.net/6/docs/ref/#language.defaultHighlightStyle) (as fallback)
  27. - [bracket matching](https://codemirror.net/6/docs/ref/#language.bracketMatching)
  28. - [bracket closing](https://codemirror.net/6/docs/ref/#autocomplete.closeBrackets)
  29. - [autocompletion](https://codemirror.net/6/docs/ref/#autocomplete.autocompletion)
  30. - [rectangular selection](https://codemirror.net/6/docs/ref/#view.rectangularSelection) and [crosshair cursor](https://codemirror.net/6/docs/ref/#view.crosshairCursor)
  31. - [active line highlighting](https://codemirror.net/6/docs/ref/#view.highlightActiveLine)
  32. - [active line gutter highlighting](https://codemirror.net/6/docs/ref/#view.highlightActiveLineGutter)
  33. - [selection match highlighting](https://codemirror.net/6/docs/ref/#search.highlightSelectionMatches)
  34. - [search](https://codemirror.net/6/docs/ref/#search.searchKeymap)
  35. - [linting](https://codemirror.net/6/docs/ref/#lint.lintKeymap)
  36. (You'll probably want to add some language package to your setup
  37. too.)
  38. This extension does not allow customization. The idea is that,
  39. once you decide you want to configure your editor more precisely,
  40. you take this package's source (which is just a bunch of imports
  41. and an array literal), copy it into your own code, and adjust it
  42. as desired.
  43. */
  44. const basicSetup = /*@__PURE__*/(() => [
  45. lineNumbers(),
  46. highlightActiveLineGutter(),
  47. highlightSpecialChars(),
  48. history(),
  49. foldGutter(),
  50. drawSelection(),
  51. dropCursor(),
  52. EditorState.allowMultipleSelections.of(true),
  53. indentOnInput(),
  54. syntaxHighlighting(defaultHighlightStyle, { fallback: true }),
  55. bracketMatching(),
  56. closeBrackets(),
  57. autocompletion(),
  58. rectangularSelection(),
  59. crosshairCursor(),
  60. highlightActiveLine(),
  61. highlightSelectionMatches(),
  62. keymap.of([
  63. ...closeBracketsKeymap,
  64. ...defaultKeymap,
  65. ...searchKeymap,
  66. ...historyKeymap,
  67. ...foldKeymap,
  68. ...completionKeymap,
  69. ...lintKeymap
  70. ])
  71. ])();
  72. /**
  73. A minimal set of extensions to create a functional editor. Only
  74. includes [the default keymap](https://codemirror.net/6/docs/ref/#commands.defaultKeymap), [undo
  75. history](https://codemirror.net/6/docs/ref/#commands.history), [special character
  76. highlighting](https://codemirror.net/6/docs/ref/#view.highlightSpecialChars), [custom selection
  77. drawing](https://codemirror.net/6/docs/ref/#view.drawSelection), and [default highlight
  78. style](https://codemirror.net/6/docs/ref/#language.defaultHighlightStyle).
  79. */
  80. const minimalSetup = /*@__PURE__*/(() => [
  81. highlightSpecialChars(),
  82. history(),
  83. drawSelection(),
  84. syntaxHighlighting(defaultHighlightStyle, { fallback: true }),
  85. keymap.of([
  86. ...defaultKeymap,
  87. ...historyKeymap,
  88. ])
  89. ])();
  90. export { basicSetup, minimalSetup };