Skip to content

Commit

Permalink
[SuperEditor][SuperReader] - Push SliverToBoxAdapter down to SingleCo…
Browse files Browse the repository at this point in the history
…lumnDocumentLayout (#1916)
  • Loading branch information
knopp authored Aug 14, 2024
1 parent 4c7472b commit 4b7b864
Show file tree
Hide file tree
Showing 40 changed files with 878 additions and 726 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,10 @@ class _ExampleEditorState extends State<ExampleEditor> {
// text.
// TODO: switch this to use a Leader and Follower
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
final docBoundingBox = (_docLayoutKey.currentState as DocumentLayout)
.getRectForSelection(_composer.selection!.base, _composer.selection!.extent)!;
final docBox = _docLayoutKey.currentContext!.findRenderObject() as RenderBox;
final overlayBoundingBox = Rect.fromPoints(
docBox.localToGlobal(docBoundingBox.topLeft),
docBox.localToGlobal(docBoundingBox.bottomRight),
);
final layout = _docLayoutKey.currentState as DocumentLayout;
final docBoundingBox = layout.getRectForSelection(_composer.selection!.base, _composer.selection!.extent)!;
final globalOffset = layout.getGlobalOffsetFromDocumentOffset(Offset.zero);
final overlayBoundingBox = docBoundingBox.shift(globalOffset);

_textSelectionAnchor.value = overlayBoundingBox.topCenter;
});
Expand Down
81 changes: 40 additions & 41 deletions super_editor/example/lib/demos/in_the_lab/feature_action_tags.dart
Original file line number Diff line number Diff line change
Expand Up @@ -106,49 +106,48 @@ class _ActionTagsFeatureDemoState extends State<ActionTagsFeatureDemo> {
}

Widget _buildEditor() {
return IntrinsicHeight(
child: SuperEditor(
editor: _editor,
focusNode: _editorFocusNode,
componentBuilders: [
TaskComponentBuilder(_editor),
...defaultComponentBuilders,
],
stylesheet: defaultStylesheet.copyWith(
inlineTextStyler: (attributions, existingStyle) {
TextStyle style = defaultInlineTextStyler(attributions, existingStyle);

if (attributions.contains(actionTagComposingAttribution)) {
style = style.copyWith(
color: Colors.blue,
);
}

return style;
},
addRulesAfter: [
...darkModeStyles,
],
),
documentOverlayBuilders: [
AttributedTextBoundsOverlay(
selector: (a) => a == actionTagComposingAttribution,
builder: (BuildContext context, Attribution attribution) {
return Leader(
link: _composingLink,
child: const SizedBox(),
);
},
),
DefaultCaretOverlayBuilder(
caretStyle: CaretStyle().copyWith(color: Colors.redAccent),
),
],
plugins: {
_actionTagPlugin,
return SuperEditor(
editor: _editor,
focusNode: _editorFocusNode,
componentBuilders: [
TaskComponentBuilder(_editor),
...defaultComponentBuilders,
],
shrinkWrap: true,
stylesheet: defaultStylesheet.copyWith(
inlineTextStyler: (attributions, existingStyle) {
TextStyle style = defaultInlineTextStyler(attributions, existingStyle);

if (attributions.contains(actionTagComposingAttribution)) {
style = style.copyWith(
color: Colors.blue,
);
}

return style;
},
addRulesAfter: [
...darkModeStyles,
],
),
documentOverlayBuilders: [
AttributedTextBoundsOverlay(
selector: (a) => a == actionTagComposingAttribution,
builder: (BuildContext context, Attribution attribution) {
return Leader(
link: _composingLink,
child: const SizedBox(),
);
},
),
);
DefaultCaretOverlayBuilder(
caretStyle: CaretStyle().copyWith(color: Colors.redAccent),
),
],
plugins: {
_actionTagPlugin,
},
);
}

Widget _buildTagList() {
Expand Down
55 changes: 27 additions & 28 deletions super_editor/example/lib/demos/in_the_lab/feature_pattern_tags.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,35 +61,34 @@ class _HashTagsFeatureDemoState extends State<HashTagsFeatureDemo> {
}

Widget _buildEditor() {
return IntrinsicHeight(
child: SuperEditor(
editor: _editor,
stylesheet: defaultStylesheet.copyWith(
inlineTextStyler: (attributions, existingStyle) {
TextStyle style = defaultInlineTextStyler(attributions, existingStyle);

if (attributions.whereType<PatternTagAttribution>().isNotEmpty) {
style = style.copyWith(
color: Colors.orange,
);
}

return style;
},
addRulesAfter: [
...darkModeStyles,
],
),
documentOverlayBuilders: [
DefaultCaretOverlayBuilder(
caretStyle: CaretStyle().copyWith(color: Colors.redAccent),
),
],
plugins: {
_hashTagPlugin,
},
return SuperEditor(
editor: _editor,
shrinkWrap: true,
stylesheet: defaultStylesheet.copyWith(
inlineTextStyler: (attributions, existingStyle) {
TextStyle style = defaultInlineTextStyler(attributions, existingStyle);

if (attributions.whereType<PatternTagAttribution>().isNotEmpty) {
style = style.copyWith(
color: Colors.orange,
);
}

return style;
},
addRulesAfter: [
...darkModeStyles,
],
),
documentOverlayBuilders: [
DefaultCaretOverlayBuilder(
caretStyle: CaretStyle().copyWith(color: Colors.redAccent),
),
);
],
plugins: {
_hashTagPlugin,
},
);
}

Widget _buildTagList() {
Expand Down
85 changes: 42 additions & 43 deletions super_editor/example/lib/demos/in_the_lab/feature_stable_tags.dart
Original file line number Diff line number Diff line change
Expand Up @@ -107,51 +107,50 @@ class _UserTagsFeatureDemoState extends State<UserTagsFeatureDemo> {
}

Widget _buildEditor() {
return IntrinsicHeight(
child: SuperEditor(
editor: _editor,
focusNode: _editorFocusNode,
stylesheet: defaultStylesheet.copyWith(
inlineTextStyler: (attributions, existingStyle) {
TextStyle style = defaultInlineTextStyler(attributions, existingStyle);

if (attributions.contains(stableTagComposingAttribution)) {
style = style.copyWith(
color: Colors.blue,
);
}

if (attributions.whereType<CommittedStableTagAttribution>().isNotEmpty) {
style = style.copyWith(
color: Colors.orange,
);
}

return style;
},
addRulesAfter: [
...darkModeStyles,
],
),
documentOverlayBuilders: [
AttributedTextBoundsOverlay(
selector: (a) => a == stableTagComposingAttribution,
builder: (context, attribution) {
return Leader(
link: _composingLink,
child: const SizedBox(),
);
},
),
DefaultCaretOverlayBuilder(
caretStyle: CaretStyle().copyWith(color: Colors.redAccent),
),
],
plugins: {
_userTagPlugin,
return SuperEditor(
editor: _editor,
focusNode: _editorFocusNode,
shrinkWrap: true,
stylesheet: defaultStylesheet.copyWith(
inlineTextStyler: (attributions, existingStyle) {
TextStyle style = defaultInlineTextStyler(attributions, existingStyle);

if (attributions.contains(stableTagComposingAttribution)) {
style = style.copyWith(
color: Colors.blue,
);
}

if (attributions.whereType<CommittedStableTagAttribution>().isNotEmpty) {
style = style.copyWith(
color: Colors.orange,
);
}

return style;
},
addRulesAfter: [
...darkModeStyles,
],
),
documentOverlayBuilders: [
AttributedTextBoundsOverlay(
selector: (a) => a == stableTagComposingAttribution,
builder: (context, attribution) {
return Leader(
link: _composingLink,
child: const SizedBox(),
);
},
),
);
DefaultCaretOverlayBuilder(
caretStyle: CaretStyle().copyWith(color: Colors.redAccent),
),
],
plugins: {
_userTagPlugin,
},
);
}

Widget _buildTagList() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ class _SelectedTextColorsDemoState extends State<SelectedTextColorsDemo> {
Widget build(BuildContext context) {
return InTheLabScaffold(
content: Center(
child: IntrinsicHeight(
child: _buildEditor(),
),
child: _buildEditor(),
),
supplemental: _buildControlPanel(),
overlay: _buildOverlay(),
Expand All @@ -72,6 +70,7 @@ class _SelectedTextColorsDemoState extends State<SelectedTextColorsDemo> {
Widget _buildEditor() {
return SuperEditor(
editor: _editor,
shrinkWrap: true,
stylesheet: defaultStylesheet.copyWith(
selectedTextColorStrategy: _selectedTextColorStrategy,
addRulesAfter: [
Expand Down
Loading

0 comments on commit 4b7b864

Please sign in to comment.