mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-30 12:24:16 -05:00
7f37ba737c
* Update Copybara options in preparation for open-sourcing the source editor * Move files * Update paths * Remove source-editor module and checks for its existence * Explicitly mention CM6 license in files that contain code adapted from CM6 GitOrigin-RevId: 89b7cc2b409db01ad103198ccbd1b126ab56349b
39 lines
936 B
TypeScript
39 lines
936 B
TypeScript
import { ViewPlugin } from '@codemirror/view'
|
|
import { EditorSelection } from '@codemirror/state'
|
|
|
|
export const symbolPalette = () => {
|
|
return ViewPlugin.define(view => {
|
|
const listener = (event: Event) => {
|
|
const symbol = (event as CustomEvent<{ command: string }>).detail
|
|
|
|
view.focus()
|
|
|
|
const spec = view.state.changeByRange(range => {
|
|
const changeSet = view.state.changes([
|
|
{
|
|
from: range.from,
|
|
to: range.to,
|
|
insert: symbol.command,
|
|
},
|
|
])
|
|
|
|
return {
|
|
range: EditorSelection.cursor(changeSet.mapPos(range.to, 1)),
|
|
changes: changeSet,
|
|
}
|
|
})
|
|
|
|
view.dispatch(spec, {
|
|
scrollIntoView: true,
|
|
})
|
|
}
|
|
|
|
window.addEventListener('editor:insert-symbol', listener)
|
|
|
|
return {
|
|
destroy() {
|
|
window.removeEventListener('editor:insert-symbol', listener)
|
|
},
|
|
}
|
|
})
|
|
}
|