overleaf/services/web/frontend/js/features/source-editor/extensions/doc-name.ts
Alf Eaton 4a7a24b44d Update the CodeMirror language when the current file is renamed (#16342)
GitOrigin-RevId: 8b51df0d1acfeeb8b0323cebf6de78572c8cb95c
2024-01-15 09:04:27 +00:00

24 lines
538 B
TypeScript

import { StateEffect, StateField } from '@codemirror/state'
export const docName = (docName: string) =>
StateField.define<string>({
create() {
return docName
},
update(value, tr) {
for (const effect of tr.effects) {
if (effect.is(setDocNameEffect)) {
value = effect.value
}
}
return value
},
})
export const setDocNameEffect = StateEffect.define<string>()
export const setDocName = (docName: string) => {
return {
effects: setDocNameEffect.of(docName),
}
}