Repository navigation
refactor(reader): type the reader surface with ReaderContent - #59
Merged
Merged
Conversation
The reader surface took `text: Any` and probed it with `is Spanned` at four sites. Retype it to the sealed `ReaderContent`, so the question becomes which of three known shapes it is rather than what it could possibly be. `ReaderContent.Spans` carries a `CharSequence` rather than a `Spanned`, because unstyled text is a real case and not a placeholder for one: the raw view and the plain-text format both hand over a `String`, and wrapping those in a `SpannableString` copies up to the maximum file size for no styling benefit. `PlainTextFormat` was paying that copy to satisfy the old signature and now hands its input straight through. `RenderedTextView` opens with an exhaustive `when` that yields the text to draw, so a shape it cannot render cannot gain a producer without a decision at that site. One `text as? Spanned` below it feeds every consumer that needs marker spans -- the span scans, split-mode detection and the split update pass -- which is where the narrowing genuinely belongs. Search keeps its own, for the same reason: counting matches and painting them with spans is a property of that implementation, not of the reader. Both casts at the format boundary go. The view models, the render cache and the editor preview all carry a `ReaderContent` now. The detekt baseline entry for `RenderedTextView` is re-keyed for its new parameter list rather than regenerated.
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.
The reader surface took
text: Anyand probed it withis Spannedat four sites. Retype it to the sealedReaderContent, so the question becomes which of three known shapes it is rather than what it could possibly be.ReaderContent.Spanscarries aCharSequencerather than aSpanned, because unstyled text is a real case and not a placeholder for one: the raw view and the plain-text format both hand over aString, and wrapping those in aSpannableStringcopies up to the maximum file size for no styling benefit.PlainTextFormatwas paying that copy to satisfy the old signature and now hands its input straight through.RenderedTextViewopens with an exhaustivewhenthat yields the text to draw, so a shape it cannot render cannot gain a producer without a decision at that site. Onetext as? Spannedbelow it feeds every consumer that needs marker spans -- the span scans, split-mode detection and the split update pass -- which is where the narrowing genuinely belongs. Search keeps its own, for the same reason: counting matches and painting them with spans is a property of that implementation, not of the reader.Both casts at the format boundary go. The view models, the render cache and the editor preview all carry a
ReaderContentnow.The detekt baseline entry for
RenderedTextViewis re-keyed for its new parameter list rather than regenerated.