-
Notifications
You must be signed in to change notification settings - Fork 15
Text Attachment Support #93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
thecoolwinter
wants to merge
23
commits into
CodeEditApp:main
Choose a base branch
from
thecoolwinter:feat/text-attachment-support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Text Attachment Support #93
thecoolwinter
wants to merge
23
commits into
CodeEditApp:main
from
thecoolwinter:feat/text-attachment-support
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Adds an API for creating "text attachments". Essentially, views that replace ranges of text and act as a single character in typesetting, layout, and selection.
Detailed Changes
Text layout consists of two steps:
The changes in this PR mostly consist of changes to the typesetting step. This step breaks down a line of text into fragments that fit into a constrained width. Text attachments are built by making 'runs' of content in that typesetting step.
TextAttachment
protocol. A generic type that can draw it's contents in a line.AnyTextAttachment
helps type-eraseany TextAttachment
and has arange
for CETV to use. Very similar toAnyHashable
orAnyView
.TextAttachmentManager
manages an ordered array of attachments, and manages hiding and showing text lines as needed, as well as invalidating layout when modifications happen.TextLayoutManager
changes:determineVisiblePosition
method. This method takes in a line position and returns a new (potentially larger) position by merging lines covered by attachments. This is the foundational method for merging lines that attachments cover.Iterator
.YPositionIterator
andRangeIterator
that iterate over a range of y positions and text offsets, respectively. These iterators are now used by thelayoutLines
method to merge lines that have attachments and not layout hidden lines.Typesetter.swift
is marked as new, but that's because it's drastically changed.Typesetter
still performs typesetting on a text line, but it now takes into account attachments. It breaks the line into content runs, then calculates line fragments using those runs and a constrained width.TypesetContext
andLineFragmentTypesetContext
represent partial parsing states while typesetting. They're both used once during typesetting and then discarded. Keeping them in their own structs makesTypesetter
much more readable.CTLineTypesetData
was previously represented by a tuple, but a struct makes things clearer. It represents layout information received from aCTTypesetter
for aCTLine
.CTTypesetter
extension. Each method was taking atypesetter
argument, so moving to an extension makes them more ergonomic.startOffset
to instead pass asubrange
that the typesetter finds line breaks in.LineFragment
Testing
Related Issues
Checklist
Screenshots
To test the changes like in the demo video replace
TextView+Menu.swift
with this:`TextView+Menu.swift`
Screen.Recording.2025-05-05.at.2.25.10.PM.mov