mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
59b3b9b933
[cm6] Prevent the editor being focused when read-only GitOrigin-RevId: 7de9f2df2421b57b3315d59d640f7c8b46caf178
24 lines
545 B
TypeScript
24 lines
545 B
TypeScript
import { Compartment, EditorState, TransactionSpec } from '@codemirror/state'
|
|
import { EditorView } from '@codemirror/view'
|
|
|
|
const readOnlyConf = new Compartment()
|
|
|
|
export const editable = () => {
|
|
return [
|
|
readOnlyConf.of([
|
|
EditorState.readOnly.of(true),
|
|
EditorView.editable.of(false),
|
|
]),
|
|
]
|
|
}
|
|
|
|
export const setEditable = (value = true): TransactionSpec => {
|
|
return {
|
|
effects: [
|
|
readOnlyConf.reconfigure([
|
|
EditorState.readOnly.of(!value),
|
|
EditorView.editable.of(value),
|
|
]),
|
|
],
|
|
}
|
|
}
|