-
Notifications
You must be signed in to change notification settings - Fork 17
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
Merged
thecoolwinter
merged 35 commits into
CodeEditApp:main
from
thecoolwinter:feat/text-attachment-support
May 9, 2025
Merged
Text Attachment Support #93
thecoolwinter
merged 35 commits into
CodeEditApp:main
from
thecoolwinter:feat/text-attachment-support
May 9, 2025
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
tom-ludwig
requested changes
May 7, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just skimmed through the code and definitely think a second reviewer is needed for changes of this size. That said, the changes look really good, to be honest.
...eEditTextViewExample/CodeEditTextViewExample/Documents/CodeEditTextViewExampleDocument.swift
Outdated
Show resolved
Hide resolved
Sources/CodeEditTextView/TextLayoutManager/TextAttachments/TextAttachmentManager.swift
Show resolved
Hide resolved
Sources/CodeEditTextView/TextLayoutManager/TextAttachments/TextAttachmentManager.swift
Outdated
Show resolved
Hide resolved
Sources/CodeEditTextView/TextLayoutManager/TextAttachments/TextAttachmentManager.swift
Show resolved
Hide resolved
Sources/CodeEditTextView/TextLayoutManager/TextLayoutManager+Iterator.swift
Show resolved
Hide resolved
Sources/CodeEditTextView/TextLayoutManager/TextLayoutManager+Iterator.swift
Outdated
Show resolved
Hide resolved
Sources/CodeEditTextView/TextLine/Typesetter/LineFragmentTypesetContext.swift
Outdated
Show resolved
Hide resolved
Sources/CodeEditTextView/TextLine/Typesetter/TypesetContext.swift
Outdated
Show resolved
Hide resolved
Tests/CodeEditTextViewTests/LayoutManager/TextLayoutManagerTests.swift
Outdated
Show resolved
Hide resolved
Co-authored-by: Tom Ludwig <tommludwig@icloud.com>
Co-authored-by: Tom Ludwig <tommludwig@icloud.com>
…coolwinter/CodeEditTextView into feat/text-attachment-support
6 tasks
tom-ludwig
previously approved these changes
May 8, 2025
tom-ludwig
approved these changes
May 8, 2025
6 tasks
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