apple-text-undo

Manage undo/redo for Apple text editors using NSTextStorage and UndoManager.

Updated Mar 19, 2026
One-click install
npx skills add https://github.com/sitapix/apple-text --skill apple-text-undo
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: apple-text-undo
Source: https://github.com/sitapix/apple-text/tree/main/skills/apple-text-undo
Command: npx skills add https://github.com/sitapix/apple-text --skill apple-text-undo

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Undo/redo management for Apple text editors, ensuring reliable grouping, coalescing, and correct inverse edits across TextKit 1/2 and NSTextStorage.

Core Features & Use Cases

  • Built-in undo support in UITextView/NSTextView via the undoManager and processEditing lifecycle.
  • Programmatic edits become undoable when routed through textStorage with beginEditing/endEditing.
  • Grouping and coalescing programmatic edits to behave as a single undo operation, with explicit beginUndoGrouping and endUndoGrouping.
  • Support for custom NSTextStorage subclasses and TextKit 2 patterns, including performEditingTransaction semantics.
  • Common pitfalls and guardrails to prevent misregistrations or broken undo chains.

Quick Start

Explain how to implement and debug undo/redo in a custom text editor using NSTextStorage and UndoManager.

Frequently Asked Questions about apple-text-undo

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I make programmatic edits undoable in NSTextStorage?

To make programmatic edits undoable in NSTextStorage, route changes through textStorage using beginEditing and endEditing lifecycle methods. This ensures the UndoManager properly registers edits and changeInLength handling for reliable inverse operations.

Why does undo stop working with custom NSTextStorage subclasses?

Undo breaks in custom NSTextStorage subclasses when processEditing lifecycle or changeInLength handling is mismanaged. Proper beginEditing/endEditing grouping and UndoManager registration are required to maintain safe undo chains and prevent broken inverse edits.

What's the best way to group multiple text edits into a single undo action?

Group multiple text edits into a single undo action by wrapping programmatic changes with explicit beginUndoGrouping and endUndoGrouping calls. This coalesces edits within NSTextStorage to behave as one predictable undo operation.

Does TextKit 2 support the same UndoManager patterns as TextKit 1?

TextKit 2 supports UndoManager patterns but requires performEditingTransaction semantics for custom NSTextStorage. The Skill addresses both TextKit 1 and TextKit 2 patterns to ensure reliable grouping and coalescing across both versions.

Can I use beginEditing and endEditing to fix broken undo chains in UITextView?

Yes, wrapping programmatic edits in beginEditing and endEditing fixes broken undo chains in UITextView. These methods ensure processEditing lifecycle correctly registers changes with UndoManager and maintains proper changeInLength tracking for safe undo data.

What are common pitfalls when implementing undo with NSTextStorage?

Common pitfalls include misregistrations with UndoManager, improper changeInLength handling, and broken undo chains from incorrect beginEditing/endEditing nesting. The Skill provides guardrails to prevent these issues and ensure reliable coalescing across TextKit 1/2.