Skip to content

fix: implement robust undo/redo history and clear document action#150

Merged
ThisIs-Developer merged 1 commit into
mainfrom
fix/undo-redo-clear-document
Jun 1, 2026
Merged

fix: implement robust undo/redo history and clear document action#150
ThisIs-Developer merged 1 commit into
mainfrom
fix/undo-redo-clear-document

Conversation

@ThisIs-Developer
Copy link
Copy Markdown
Owner

Overview

This PR resolves critical issues with the editor's toolbar actions and event handling, implementing professional-grade support for Undo, Redo, and Clear Document across web, desktop, and mobile platforms.

Key Changes

  1. Tab-Aware State History (Undo & Redo):
    • Introduced a lightweight history engine that tracks values and selections (value, selectionStart, selectionEnd) independently per tab in a global tabHistories dictionary.
    • Intercepts default key shortcuts (Ctrl+Z / Ctrl+Shift+Z / Ctrl+Y) and routes them to custom state restoration when the editor is focused.
    • Groups manual keystrokes intelligently and commits states on word boundaries (space), line breaks, pastes, or programmatic additions.
    • Synchronizes toolbar button disabled states dynamically based on stack history.
  2. Clear Document Action:
    • Replaced "Clear Markdown formatting" button and modal with "Clear document", which clears all text inside the active document.
    • Clears content using replaceEditorRange after pushing to the active tab's custom undo stack, allowing full recovery of the cleared document via Undo (Ctrl+Z).
    • Forces immediate, synchronous visual updates of renderMarkdown(), updateLineNumbers(), updateFindHighlights(), and saveCurrentTabState() to update the preview pane, line number gutter, and background syntax highlights instantly without requiring key presses or timeout delays.

Verification

  • Stacks are fully isolated per tab.
  • History states can be fully undone/redone without desynchronization or cursor drift.
  • Cleared documents are fully restorable via Undo (Ctrl+Z).
  • No regressions on markdown rendering, themes, settings, or other toolbar options.

Copilot AI review requested due to automatic review settings June 1, 2026 18:19
@vercel
Copy link
Copy Markdown

vercel Bot commented Jun 1, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
markdown-viwer Ready Ready Preview, Comment Jun 1, 2026 6:19pm

@ThisIs-Developer ThisIs-Developer merged commit b5fa206 into main Jun 1, 2026
6 checks passed
@ThisIs-Developer ThisIs-Developer deleted the fix/undo-redo-clear-document branch June 1, 2026 18:19
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

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.

2 participants