txt-textkit2

Documents TextKit 2 APIs for NSTextLayoutManager, content storage, fragments, and viewport layout.

2|Updated Sep 8, 2026
One-click install
npx skills add https://github.com/hanshi-notes/hanshi --skill txt-textkit2-hanshi-notes
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: txt-textkit2
Source: https://github.com/hanshi-notes/hanshi/tree/main/.agents/skills/txt-textkit2
Command: npx skills add https://github.com/hanshi-notes/hanshi --skill txt-textkit2-hanshi-notes

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? TextKit 2 replaces TextKit 1 with an element-based, viewport-driven model that breaks many assumptions from NSLayoutManager-era code, and its API surface keeps changing across iOS releases. This Skill provides a verified reference for the modern stack so you avoid stale fragments, clipped drawing, and full-document layout traps. ## Core Features & Use Cases - API Reference: Covers NSTextContentManager, NSTextContentStorage, NSTextLayoutManager, NSTextLayoutFragment, NSTextLineFragment, NSTextViewportLayoutController, and object-based NSTextRange/NSTextLocation addressing. - Common Mistakes Catalog: Documents ten confirmed pitfalls, including editing outside performEditingTransaction, treating line-fragment characterRange as document-relative, and calling ensureLayout over the document range. - Migration Mapping: A sidecar reference maps TextKit 1 APIs (glyph APIs, temporary attributes, boundingRect) to their TextKit 2 equivalents or flags cases with no equivalent. - Use Case: When adding Writing Tools inline support or a custom code-block background to an NSTextLayoutManager-based editor, consult this Skill to wire the viewport delegate callbacks and supply a custom NSTextLayoutFragment subclass correctly. ## Quick Start Ask how to correctly invalidate layout and redraw a paragraph range in an NSTextLayoutManager-based text view.

Frequently Asked Questions about txt-textkit2

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

FAQPage Schema
How do I perform text edits with NSTextLayoutManager?▼

Wrap all NSTextStorage mutations in textContentManager.performEditingTransaction so element regeneration and layout invalidation fire at the close of the block. Direct mutations outside the transaction go through but leave fragments stale.

What replaces temporary attributes in TextKit 2?▼

Rendering attributes replace TextKit 1 temporary attributes. Use textLayoutManager.setRenderingAttributes or addRenderingAttribute for a visual-only overlay that does not modify storage, invalidate layout, or leak into copy/paste and serialization.

Does TextKit 2 support multiple text containers?▼

No. NSTextLayoutManager supports exactly one NSTextContainer. Multi-container layouts such as multi-page, multi-column, or linked text views require TextKit 1 with NSLayoutManager.

Why is my TextKit 2 scrolling slow or jittery?▼

Common causes are calling ensureLayout over the document range, which materializes every fragment, and reading usageBoundsForTextContainer directly into contentSize during a viewport pass. Update content size only inside textViewportLayoutControllerDidLayout and keep line wrapping enabled.

When should I stay on TextKit 1 instead of TextKit 2?▼

Stay on TextKit 1 when you need glyph-level APIs, multi-container layout, exact stable document height for minimaps or rulers, or well-tested temporary attributes for syntax highlighting. TextKit 2 removed glyph APIs entirely.