Created
August 13, 2024 08:34
-
-
Save Hixie/511502f3da9ff6c028a30153667d5064 to your computer and use it in GitHub Desktop.
This file contains 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
abstract class Annotation { | |
ui.TextStyle? get style; | |
void build(...); | |
} | |
class Range { | |
// ... | |
} | |
@immutable | |
class RangeSpan extends InlineSpan implements HitTestTarget, MouseTrackerAnnotation { | |
const TextSpan({ | |
this.text, | |
this.annotations, | |
}); | |
final String? text; | |
final List<(Range, Annotation)> annotations; | |
@override | |
void handleEvent(PointerEvent event, HitTestEntry entry) { | |
...for each annotation that overlaps the destination: | |
annotation.handleEvent(...) | |
} | |
@override | |
void build( | |
ui.ParagraphBuilder builder, { | |
TextScaler textScaler = TextScaler.noScaling, | |
List<PlaceholderDimensions>? dimensions, | |
}) { | |
split the text into which subranges are affected by different annotations | |
for each subrange: | |
for each annotation with a style: | |
builder.pushStyle(annotation.style) | |
for each subrange: | |
for each annotation that wants to build something (e.g. insert a WidgetSpan): | |
annotation.build(...) | |
builder.addText(text of subrange); | |
for each subrange: | |
for each annotation with a style: | |
builder.pop | |
} | |
@override | |
bool visitChildren(InlineSpanVisitor visitor) { | |
walk each annotation that wants to build something (e.g. insert a WidgetSpan) | |
} | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment