Problem

In our editor, the image, its buttons and the drag area are in a non-editable wrapper (contentEditable={false}), so the browser never puts a cursor in them. The caption is inside that wrapper, so it switches editing back on for itself (contentEditable={editor.isEditable}). That makes it a separate editable element, which ProseMirror treats as foreign. So every editing feature has to be added manually. I found issues with:

    Undo and Redo

    Paste inside caption

    Selecting first or last character, because the width of caption is exactly the width of text

    Double and triple clicking the caption

    Other keyboard shortcuts, like bold, italic.

Solution

Make only the image box non-editable, and the caption sit next to it as ordinary editor text. Focus then stays on the editor, so caret, paste, undo, shortcuts, IME, double-click and triple-click all work the way they do in a paragraph.

    Split the image node view. In media-container.tsx, keep the non-editable wrapper around the image box only, and render the caption outside it with no contentEditable attribute.

    Give BlockSelectionWrapper room for a caption. Video, file and embed blocks share it and have no caption, so add an optional caption area outside its non-editable part.

    Make the caption full width, with centred text. Clicking anywhere on the caption line then puts the cursor there. Clicking the image still selects the image.

    Set the keyboard rules for caption. Backspace at the start of a caption selects the image, as Backspace below an image already does. Enter in a caption moves to the next block. Arrow keys go above the image, to the image, to the caption, then below.

    Test with the existing caption tests. The 5 tests in image-caption.e2e.ts cover clicking, typing, Enter, paste and undo. Add tests for a click past the end of the text, double- and triple-click, Cmd+B, and Backspace at the start.

Rabbit holes

Other users of MediaContainer. The comment editor and the read-only viewer render the same component. Check captions in both.

No Goes

This should only change how the editor renders and edits a caption. The saved document (permanent data) stays exactly the same.

Old solution:

Do you like what you are reading? Subscribe to receive updates.

Unsubscribe anytime

Connections0
Image caption improvement proposalImage caption improvement…
Citations 0Children & links 0

Loading child documents…

Connections show where other documents or comments link to this document.

Related documents

Loading connections…