Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

axiom-textkit-ref

БесплатноБез исполняемых скриптовНе проверен

TextKit 2 complete reference (architecture, migration, Writing Tools, SwiftUI TextEditor) through iOS 26

ComeOnOliverот ComeOnOliver★ 67 звёзд на GitHub

Об этом скилле

TextKit 2 Reference

Complete reference for TextKit 2 covering architecture, migration from TextKit 1, Writing Tools integration, and SwiftUI TextEditor with AttributedString through iOS 26.

Architecture

TextKit 2 uses MVC pattern with new classes optimized for correctness, safety, and performance.

Model Layer

NSTextContentManager (abstract)

  • Generates NSTextElement objects from backing store
  • Tracks element ranges within document
  • Default implementation: NSTextContentStorage

NSTextContentStorage

  • Uses NSTextStorage as backing store
  • Automatically divides content into NSTextParagraph elements
  • Generates updated elements when text changes

NSTextElement (abstract)

  • Represents portion of content (paragraph, attachment, custom type)
  • Immutable value semantics
  • Properties cannot change after creation
  • Default implementation: NSTextParagraph

NSTextParagraph

  • Represents single paragraph
  • Contains range within document

Controller Layer

NSTextLayoutManager

  • Replaces TextKit 1's NSLayoutManager
  • NO glyph APIs (abstracts away glyphs entirely)
  • Takes elements, lays out into container, generates layout fragments
  • Always uses noncontiguous layout

NSTextLayoutFragment

  • Immutable layout information for one or more elements
  • Key properties:
    • textLineFragments — array of NSTextLineFragment
    • layoutFragmentFrame — layout bounds within container
    • renderingSurfaceBounds — actual drawing bounds (can exceed frame)

NSTextLineFragment

  • Measurement info for single line of text
  • Used for line counting and geometric queries

View Layer

NSTextViewportLayoutController

  • Source of truth for viewport layout
  • Coordinates visible-only layout
  • Calls delegate methods: willLayout, configureRenderingSurface, didLayout

NSTextContainer

  • Provides geometric information for layout destination
  • Can define exclusion paths (non-rectangular layout)

Object-Based Ranges

NSTextLocation (protocol)

  • Represents single location in text
  • Replaces integer indices
  • Supports structured documents (e.g., DOM with nested elements)

NSTextRange

  • Start and end locations (end is excluded)
  • Can represent nested structure
  • Incompatible with NSRange for non-linear documents

NSTextSelection

  • Contains: granularity, affinity, possibly disjoint ranges
  • Read-only properties
  • Immutable value semantics

NSTextSelectionNavigation

  • Performs actions on selections
  • Returns new NSTextSelection instances
  • Handles bidirectional text correctly

Core Design Principles

1. Correctness — No Glyph APIs

From WWDC 2021:

"TextKit 2 abstracts away glyph handling to provide a consistent experience for international text."

Why no glyphs?

Problem: In scripts like Kannada and Arabic:

  • One glyph can represent multiple characters (ligatures)
  • One character can split into multiple glyphs
  • Glyphs reorder during shaping
  • No correct character→glyph mapping

Example (Kannada word "October"):

  • Character 4 splits into 2 glyphs
  • Glyphs reorder before ligature application
  • Glyph 3 becomes conjoining form and moves below another glyph

Solution: Use NSTextLocation, NSTextRange, NSTextSelection instead of glyph indices.

2. Safety — Value Semantics

Immutable objects:

  • NSTextElement
  • NSTextLayoutFragment
  • NSTextLineFragment
  • NSTextSelection

Benefits:

  • No unintended sharing
  • No side effects from mutations
  • Easier to reason about state

Pattern: To change layout/selection, create new instances with desired changes.

3. Performance — Viewport Layout

Always Noncontiguous: TextKit 2 performs layout only for visible content + overscroll region.

TextKit 1:

  • Optional noncontiguous layout (boolean property)
  • No visibility into layout state
  • Can't control which parts get laid out

TextKit 2:

  • Always noncontiguous
  • Viewport defines visible area
  • Consistent layout info for viewport
  • Notifications for viewport layout updates

Viewport Delegate Methods:

  1. textViewportLayoutControllerWillLayout(_:) — setup before layout
  2. textViewportLayoutController(_:configureRenderingSurfaceFor:) — per fragment
  3. textViewportLayoutControllerDidLayout(_:) — cleanup after layout

Migration from TextKit 1

Key Paradigm Shift

TextKit 1 TextKit 2
Glyphs Elements
NSRange NSTextLocation/NSTextRange
NSLayoutManager NSTextLayoutManager
Glyph APIs NO glyph APIs
Optional noncontiguous Always noncontiguous
NSTextStorage directly Via NSTextContentManager

API Naming Heuristics

From WWDC 2022:

  • .offset in name → TextKit 1
  • .location in name → TextKit 2

NSRange ↔ NSTextRange Conversion

NSRange → NSTextRange:

// UITextView/NSTextView
let nsRange = NSRange(location: 0, length: 10)

// Via content manager
let startLocation = textContentManager.location(
    textContentManager.documentRange.location,
    offsetBy:
Полный SKILL.md на GitHub

Установить axiom-textkit-ref в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

FAQ

Что делает скилл axiom-textkit-ref?

TextKit 2 complete reference (architecture, migration, Writing Tools, SwiftUI TextEditor) through iOS 26

Как установить скилл axiom-textkit-ref?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл axiom-textkit-ref запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить axiom-textkit-ref с