question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature: Readonly editor with state updates & listeners

See original GitHub issue

I have a usecase where:

  1. I don’t want the editor to be editable by the user
  2. I want the capability to receive editor updates and subscribe to commands like click, drag, etc.

So far, I haven’t been able to find a clean solution that achieves both. Setting the editor to readonly in the initialConfig ‘freezes’ the editor thereby achieving (1) but not (2). It would be nice to have an editor that is non-editable but can still hooked up to the in-built listeners. For react, having a prop that can override isReadOnly in the LexicalContentEditable seems to be one way to achieve this.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
yudoricommented, Jun 6, 2022

@pguduguntla The solution I went with is to leave the global lexical editor readonly state as false and instead use a custom ‘readonly’ contenteditable in the text plugin.

Custom ReadOnlyContentEditable.ts

import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
import React, { useCallback } from 'react';

export type Props = {
    id?: string,
};

export default function ReadOnlyContentEditable(props: Props): JSX.Element {
    const [editor] = useLexicalComposerContext();
    const ref = useCallback(
        (rootElement: null | HTMLElement) => {
            editor.setRootElement(rootElement);
        },
        [editor]
    );

    return (
        <div
            contentEditable={false}
            id={props.id}
            ref={ref}
        />
    );
}

Usage in LexicalPlainTextPlugin

<LexicalPlainTextPlugin
  contentEditable={<ReadOnlyContentEditable />}
  ...
/>
1reaction
pguduguntlacommented, Jun 6, 2022

@yudori Oh sweet! That works for my use case, thanks so much man!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is there a way to set editor to readOnly when you can only ...
updateListener. An editorView object is created with new EditorView, passing a state with EditorState.create. Then the editorView.dom is ...
Read more >
Configuration - Editor.js
After you create a new EditorJS object, it will contain isReady property. It is a Promise object that will be resolved when the...
Read more >
Configure read-only routing for an Always On availability group
Automatically route all read-only traffic to a secondary replica using ... Create or Configure an Availability Group Listener (SQL Server).
Read more >
Class Editor (CKEDITOR.editor) - CKEditor 4 API docs
editor #status ... Indicates editor initialization status. The following statuses are available: unloaded: The initial state — the editor instance was initialized, ...
Read more >
VS Code API | Visual Studio Code Extension API
The function is sometimes also called command handler. Commands can be added to the editor using the registerCommand and registerTextEditorCommand functions.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found