Merge pull request #12631 from overleaf/ae-readonly-focus

[cm6] Prevent the editor being focused when read-only

GitOrigin-RevId: 7de9f2df2421b57b3315d59d640f7c8b46caf178
This commit is contained in:
Mathias Jakobsen 2023-04-20 10:59:09 +01:00 committed by Copybot
parent c2292a8567
commit 59b3b9b933

View file

@ -1,13 +1,24 @@
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))]
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))],
effects: [
readOnlyConf.reconfigure([
EditorState.readOnly.of(!value),
EditorView.editable.of(value),
]),
],
}
}