Skip to content

feat(editor): add button to insert new blocks at document end#254

Merged
horacioh merged 1 commit intomainfrom
terra-toucan
Feb 27, 2026
Merged

feat(editor): add button to insert new blocks at document end#254
horacioh merged 1 commit intomainfrom
terra-toucan

Conversation

@horacioh
Copy link
Collaborator

Summary

Adds a new "Add Block at End" button to the editor UI, enabling users to quickly insert new content blocks at the end of a document without needing to scroll or position their cursor manually.

Key Changes

  • New Component: AddBlockAtEndButton - A floating button that intelligently manages block insertion at the document end

    • If the last block has content, creates a new empty block after it
    • If the last block is already empty, reuses it by moving cursor there
    • Cleans up leftover "/" blocks from dismissed slash menus before proceeding
    • Automatically opens the slash menu for block type selection
  • Editor Integration: Integrated the button into HyperMediaEditorView component

    • Positioned below the main editor content
    • Hidden in comment/read-only mode
  • Layout Adjustments:

    • Updated draft.tsx to use bottom padding (pb-60) instead of margin for better spacing
    • Applied same padding fix to resource-page-common.tsx
  • Test Coverage: Added comprehensive test suite (addBlockAtEnd.test.ts) covering:

    • Block detection in single and multi-block documents
    • Insertion logic with content vs. empty blocks
    • Leftover "/" block cleanup and reuse
    • Nested block handling

Implementation Details

The button uses ProseMirror's editor state to:

  1. Locate the last block in the document
  2. Check if it contains content
  3. Detect and remove leftover "/" blocks from previous interactions
  4. Insert new blocks or reuse empty ones
  5. Trigger the slash menu for block type selection

Add AddBlockAtEndButton component that enables users to quickly create new blocks at the end of the document with the slash menu pre-activated. The button includes intelligent handling of edge cases:
- Cleans up leftover "/" blocks from dismissed slash menus
- Reuses empty trailing blocks instead of creating duplicates
- Inserts "/" to trigger slash menu with inline decoration

Updates document content areas with bottom padding (pb-60) to provide space for the floating button and improve UX.

Includes comprehensive test suite validating block detection, insertion, and edge case handling at the ProseMirror level.
@horacioh horacioh merged commit 1da4a69 into main Feb 27, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant