Skip to content

createEditorReadonly sets EditorView.editable.of(false) #29

@sparecycles

Description

@sparecycles

First of all, thanks for this library!

I just had a small hiccup using createEditorReadonly along with

import { search, searchKeymap } from "@codemirror/search";

createExtension(() => [search(), keymap.of(searchKeymap)]);

Where the search would not show up in my "read-only" views.

The docs for state.EditorState^readOnly call out

Not to be confused with EditorView.editable, which controls whether the editor's DOM is set to be editable (and thus focusable).

So, for me, the fix was to replace my use of createEditorReadonly with codemirror's EditorState.readOnly which allows focus and allows command-F to bring up the search panel.

createExtension(() => props.readonly ? EditorState.readOnly.of(true) : undefined);

I'm kind of thinking that createEditorReadonly should be deprecated and users should be encouraged to do the following instead?

createExtension(() => props.readonly ? EditorState.editable.of(false) : undefined);

( Unless there's some edge case in the behavior I'm not aware of that createEditorReadonly is solving. )

TL;DR

  • createEditorReadonly sets editable=false, which is confusing/mislabled because "read only" and "not editable" are two different concepts for codemirror.
  • createEditorReadonly seems to be an unnecessary entrypoint into the library, replaceable with a note in the documentation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions