2023-04-13 04:21:25 -04:00
|
|
|
import {
|
|
|
|
EditorView,
|
|
|
|
rectangularSelection,
|
|
|
|
tooltips,
|
|
|
|
crosshairCursor,
|
|
|
|
dropCursor,
|
|
|
|
highlightActiveLineGutter,
|
|
|
|
} from '@codemirror/view'
|
|
|
|
import { EditorState, Extension } from '@codemirror/state'
|
2023-08-17 06:01:10 -04:00
|
|
|
import { foldGutter, indentOnInput, indentUnit } from '@codemirror/language'
|
2023-05-16 08:16:14 -04:00
|
|
|
import { history } from '@codemirror/commands'
|
2023-04-13 04:21:25 -04:00
|
|
|
import { language } from './language'
|
|
|
|
import { lineWrappingIndentation } from './line-wrapping-indentation'
|
|
|
|
import { theme } from './theme'
|
|
|
|
import { realtime } from './realtime'
|
|
|
|
import { cursorPosition } from './cursor-position'
|
|
|
|
import { scrollPosition } from './scroll-position'
|
|
|
|
import { annotations } from './annotations'
|
|
|
|
import { cursorHighlights } from './cursor-highlights'
|
|
|
|
import { autoComplete } from './auto-complete'
|
|
|
|
import { editable } from './editable'
|
|
|
|
import { autoPair } from './auto-pair'
|
|
|
|
import { phrases } from './phrases'
|
|
|
|
import { spelling } from './spelling'
|
|
|
|
import { symbolPalette } from './symbol-palette'
|
|
|
|
import { trackChanges } from './track-changes'
|
|
|
|
import { search } from './search'
|
|
|
|
import { filterCharacters } from './filter-characters'
|
|
|
|
import { keybindings } from './keybindings'
|
|
|
|
import { bracketMatching, bracketSelection } from './bracket-matching'
|
|
|
|
import { verticalOverflow } from './vertical-overflow'
|
|
|
|
import { thirdPartyExtensions } from './third-party-extensions'
|
|
|
|
import { lineNumbers } from './line-numbers'
|
|
|
|
import { highlightActiveLine } from './highlight-active-line'
|
|
|
|
import importOverleafModules from '../../../../macros/import-overleaf-module.macro'
|
2023-04-20 05:58:22 -04:00
|
|
|
import { emptyLineFiller } from './empty-line-filler'
|
2023-04-13 04:21:25 -04:00
|
|
|
import { goToLinePanel } from './go-to-line'
|
|
|
|
import { drawSelection } from './draw-selection'
|
2023-06-08 04:35:51 -04:00
|
|
|
import { visual } from './visual/visual'
|
2023-04-13 04:21:25 -04:00
|
|
|
import { inlineBackground } from './inline-background'
|
|
|
|
import { indentationMarkers } from './indentation-markers'
|
2023-04-14 04:54:09 -04:00
|
|
|
import { codemirrorDevTools } from '../languages/latex/codemirror-dev-tools'
|
2023-05-16 08:16:14 -04:00
|
|
|
import { keymaps } from './keymaps'
|
|
|
|
import { shortcuts } from './shortcuts'
|
2023-05-19 04:29:48 -04:00
|
|
|
import { effectListeners } from './effect-listeners'
|
2023-06-08 04:35:51 -04:00
|
|
|
import { highlightSpecialChars } from './highlight-special-chars'
|
2023-06-30 05:46:46 -04:00
|
|
|
import { toolbarPanel } from './toolbar/toolbar-panel'
|
2023-06-19 10:08:13 -04:00
|
|
|
import { geometryChangeEvent } from './geometry-change-event'
|
2024-01-12 05:09:29 -05:00
|
|
|
import { docName } from '@/features/source-editor/extensions/doc-name'
|
2023-04-14 04:58:19 -04:00
|
|
|
|
2023-04-13 04:21:25 -04:00
|
|
|
const moduleExtensions: Array<() => Extension> = importOverleafModules(
|
|
|
|
'sourceEditorExtensions'
|
|
|
|
).map((item: { import: { extension: Extension } }) => item.import.extension)
|
|
|
|
|
|
|
|
export const createExtensions = (options: Record<string, any>): Extension[] => [
|
|
|
|
lineNumbers(),
|
2023-06-08 04:35:51 -04:00
|
|
|
highlightSpecialChars(options.visual.visual),
|
|
|
|
// The built-in extension that manages the history stack,
|
|
|
|
// configured to increase the maximum delay between adjacent grouped edits
|
2023-04-13 04:21:25 -04:00
|
|
|
history({ newGroupDelay: 250 }),
|
2023-06-08 04:35:51 -04:00
|
|
|
// The built-in extension that displays buttons for folding code in a gutter element,
|
|
|
|
// configured with custom openText and closeText symbols.
|
2023-04-13 04:21:25 -04:00
|
|
|
foldGutter({
|
|
|
|
openText: '▾',
|
|
|
|
closedText: '▸',
|
|
|
|
}),
|
|
|
|
drawSelection(),
|
2023-06-08 04:35:51 -04:00
|
|
|
// A built-in facet that is set to true to allow multiple selections.
|
|
|
|
// This makes the editor more like a code editor than Google Docs or Microsoft Word,
|
|
|
|
// which only have single selections.
|
2023-04-13 04:21:25 -04:00
|
|
|
EditorState.allowMultipleSelections.of(true),
|
2023-06-08 04:35:51 -04:00
|
|
|
// A built-in extension that enables soft line wrapping.
|
2023-04-13 04:21:25 -04:00
|
|
|
EditorView.lineWrapping,
|
2023-06-08 04:35:51 -04:00
|
|
|
// A built-in extension that re-indents input if the language defines an indentOnInput field in its language data.
|
2023-04-13 04:21:25 -04:00
|
|
|
indentOnInput(),
|
|
|
|
lineWrappingIndentation(options.visual.visual),
|
|
|
|
indentationMarkers(options.visual.visual),
|
|
|
|
bracketMatching(),
|
|
|
|
bracketSelection(),
|
2023-06-08 04:35:51 -04:00
|
|
|
// A built-in extension that enables rectangular selections, created by dragging a new selection while holding down Alt.
|
2023-04-13 04:21:25 -04:00
|
|
|
rectangularSelection(),
|
2023-06-08 04:35:51 -04:00
|
|
|
// A built-in extension that turns the pointer into a crosshair while Alt is pressed.
|
2023-04-13 04:21:25 -04:00
|
|
|
crosshairCursor(),
|
2023-06-08 04:35:51 -04:00
|
|
|
// A built-in extension that shows where dragged content will be dropped.
|
2023-04-13 04:21:25 -04:00
|
|
|
dropCursor(),
|
2023-06-08 04:35:51 -04:00
|
|
|
// A built-in extension that is used for configuring tooltip behaviour,
|
|
|
|
// configured so that the tooltip parent is the document body,
|
|
|
|
// to avoid cutting off tooltips which overflow the editor.
|
2023-04-13 04:21:25 -04:00
|
|
|
tooltips({
|
|
|
|
parent: document.body,
|
|
|
|
}),
|
2023-05-16 08:16:14 -04:00
|
|
|
keymaps,
|
2023-04-13 04:21:25 -04:00
|
|
|
goToLinePanel(),
|
|
|
|
filterCharacters(),
|
|
|
|
|
2023-06-08 04:35:51 -04:00
|
|
|
// NOTE: `autoComplete` needs to be before `keybindings` so that arrow key handling
|
2023-04-13 04:21:25 -04:00
|
|
|
// in the autocomplete pop-up takes precedence over Vim/Emacs key bindings
|
|
|
|
autoComplete(options.settings),
|
|
|
|
|
2023-06-08 04:35:51 -04:00
|
|
|
// NOTE: `keybindings` needs to be before `language` so that Vim/Emacs bindings take
|
2023-04-13 04:21:25 -04:00
|
|
|
// precedence over language-specific keyboard shortcuts
|
|
|
|
keybindings(),
|
|
|
|
|
2024-01-12 05:09:29 -05:00
|
|
|
docName(options.docName),
|
|
|
|
|
2023-06-08 04:35:51 -04:00
|
|
|
// NOTE: `annotations` needs to be before `language`
|
|
|
|
annotations(),
|
2024-01-12 05:09:29 -05:00
|
|
|
language(options.docName, options.metadata, options.settings),
|
2023-08-17 06:01:10 -04:00
|
|
|
indentUnit.of(' '), // 4 spaces
|
2023-04-13 04:21:25 -04:00
|
|
|
theme(options.theme),
|
|
|
|
realtime(options.currentDoc, options.handleError),
|
|
|
|
cursorPosition(options.currentDoc),
|
|
|
|
scrollPosition(options.currentDoc),
|
|
|
|
cursorHighlights(),
|
|
|
|
autoPair(options.settings),
|
|
|
|
editable(),
|
|
|
|
search(),
|
|
|
|
phrases(options.phrases),
|
|
|
|
spelling(options.spelling),
|
2023-05-16 08:16:14 -04:00
|
|
|
shortcuts,
|
2023-04-13 04:21:25 -04:00
|
|
|
symbolPalette(),
|
2023-06-08 04:35:51 -04:00
|
|
|
// NOTE: `emptyLineFiller` needs to be before `trackChanges`,
|
|
|
|
// so the decorations are added in the correct order.
|
|
|
|
emptyLineFiller(),
|
2023-04-13 04:21:25 -04:00
|
|
|
trackChanges(options.currentDoc, options.changeManager),
|
2024-01-12 05:09:29 -05:00
|
|
|
visual(options.visual),
|
2023-10-03 10:11:56 -04:00
|
|
|
toolbarPanel(),
|
2023-04-13 04:21:25 -04:00
|
|
|
verticalOverflow(),
|
|
|
|
highlightActiveLine(options.visual.visual),
|
2023-06-08 04:35:51 -04:00
|
|
|
// The built-in extension that highlights the active line in the gutter.
|
2023-04-13 04:21:25 -04:00
|
|
|
highlightActiveLineGutter(),
|
|
|
|
inlineBackground(options.visual.visual),
|
2023-04-14 04:54:09 -04:00
|
|
|
codemirrorDevTools(),
|
2024-02-01 04:47:14 -05:00
|
|
|
// Send exceptions to Sentry
|
|
|
|
EditorView.exceptionSink.of(options.handleException),
|
2023-06-08 04:35:51 -04:00
|
|
|
// CodeMirror extensions provided by modules
|
2023-04-13 04:21:25 -04:00
|
|
|
moduleExtensions.map(extension => extension()),
|
|
|
|
thirdPartyExtensions(),
|
2023-05-19 04:29:48 -04:00
|
|
|
effectListeners(),
|
2023-11-28 06:23:55 -05:00
|
|
|
geometryChangeEvent(),
|
2023-04-13 04:21:25 -04:00
|
|
|
]
|