txt-viewport-rendering

Configure TextKit 2 viewport layout, fragment geometry, and rendering attributes.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? TextKit 2's viewport-driven layout, fragment geometry, and rendering-attribute system are easy to misuse, producing clipped diacritics, jiggling scroll bars, missing trailing cursors, and glyphs rendered as .notdef boxes. This Skill explains how the viewport layout pass, layout fragments, line fragments, and rendering attributes actually work so you can implement and debug custom text rendering correctly. ## Core Features & Use Cases - Viewport Layout Model: Explains NSTextViewportLayoutController callbacks, estimated vs visible regions, and why usageBoundsForTextContainer.height causes scroll-bar jiggle. - Fragment Geometry: Covers layoutFragmentFrame vs renderingSurfaceBounds, line-fragment local coordinates, the extra trailing line fragment, exclusion-path line splitting, and lineFragmentPadding vs textContainerInset. - Rendering Attributes & Font Substitution: Distinguishes rendering attributes from storage attributes and explains why fonts must be set in willProcessEditing so fixAttributes can perform fallback substitution. - Use Case: You are building a custom editor and the cursor disappears after a trailing newline, or a custom fragment's drawing is clipped at its frame edge. This Skill identifies the missing .ensuresExtraLineFragment option or the missing renderingSurfaceBounds override. ## Quick Start Ask the AI to explain why your custom NSTextLayoutFragment drawing is clipped at the layout frame and how to fix it with renderingSurfaceBounds.

Frequently Asked Questions about txt-viewport-rendering

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

FAQPage Schema
How does TextKit 2 viewport layout work?▼

TextKit 2 lays out only content near the viewport, dividing the document into estimated, overscroll, and visible regions. NSTextViewportLayoutController runs willLayout, lays out visible fragments, calls configureRenderingSurfaceFor per fragment, then didLayout, keeping layout cost proportional to the viewport rather than the document.

Why is my custom NSTextLayoutFragment drawing clipped?▼

Drawing outside layoutFragmentFrame is clipped unless you override renderingSurfaceBounds to expand the dirty rect. Diacritics, descenders, shadows, and custom backgrounds that extend past the layout frame all require this override to render fully.

What is the difference between rendering attributes and text storage attributes?▼

Rendering attributes are a visual overlay set on the layout manager that never modifies storage, layout, undo, or serialization. Storage attributes persist in the document. Use setRenderingAttributes for transient effects like find highlights instead of textStorage.addAttribute.

Why do characters show as .notdef boxes after setting a font?▼

Setting fonts in didProcessEditing bypasses fixAttributes, which performs font fallback substitution during the editing pass. Move font changes to willProcessEditing so characters missing from the requested font are reassigned to a fallback font.

Why does the scroll bar jiggle or stop mid-scroll in TextKit 2?▼

usageBoundsForTextContainer.height is an estimate that refines as fragments lay out during scrolling, so scroll-bar metrics tied to it shift. Code needing exact heights must force layout for the relevant range or use TextKit 1.

When should I use TextKit 1 instead of TextKit 2?▼

TextKit 1 fits cases needing exact total heights, precise jump-to-position navigation, or production syntax highlighting via temporary attributes, since TextKit 2 rendering attributes have known drawing-artifact bugs. TextKit 2 suits large documents where viewport-only layout performance matters.