Skip to content

Commit

Permalink
[SuperText] - Add support for inline widgets (Resolves #2441) (#2448)
Browse files Browse the repository at this point in the history
  • Loading branch information
matthew-carroll authored and web-flow committed Dec 10, 2024
1 parent 0e4690e commit 1241dd9
Show file tree
Hide file tree
Showing 18 changed files with 384 additions and 2 deletions.
31 changes: 31 additions & 0 deletions super_text_layout/lib/src/inline_widgets.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/// A placeholder to be given to an `AttributedText`, and later replaced
/// within an inline network image.
class InlineNetworkImagePlaceholder {
const InlineNetworkImagePlaceholder(this.url);

final String url;

@override
bool operator ==(Object other) =>
identical(this, other) ||
other is InlineNetworkImagePlaceholder && runtimeType == other.runtimeType && url == other.url;

@override
int get hashCode => url.hashCode;
}

/// A placeholder to be given to an `AttributedText`, and later replaced
/// within an inline asset image.
class InlineAssetImagePlaceholder {
const InlineAssetImagePlaceholder(this.assetPath);

final String assetPath;

@override
bool operator ==(Object other) =>
identical(this, other) ||
other is InlineAssetImagePlaceholder && runtimeType == other.runtimeType && assetPath == other.assetPath;

@override
int get hashCode => assetPath.hashCode;
}
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,13 @@ class _RebuildOptimizedSuperTextWithSelectionState extends State<_RebuildOptimiz
style: userSelection.caretStyle,
blinkCaret: userSelection.blinkCaret,
blinkTimingMode: userSelection.blinkTimingMode,
position: userSelection.selection.extent,
position: TextPosition(
offset: userSelection.selection.extent.offset,
affinity: TextAffinity.downstream,
),
// ^ We force downstream, instead of upstream, to reduce the buggyness
// of caret sizing in Flutter when placed near an inline widget.
// Issue: https://github.com/flutter/flutter/issues/159932
caretTracker: userSelection.caretFollower,
),
],
Expand Down
7 changes: 6 additions & 1 deletion super_text_layout/lib/src/text_selection_layer.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:ui';

import 'package:flutter/widgets.dart';

import 'text_layout.dart';
Expand Down Expand Up @@ -160,7 +162,10 @@ class TextSelectionPainter extends CustomPainter {
return;
}

final selectionBoxes = textLayout!.getBoxesForSelection(textSelection!);
final selectionBoxes = textLayout!.getBoxesForSelection(
textSelection!,
boxHeightStyle: BoxHeightStyle.max,
);

for (final box in selectionBoxes) {
final rawRect = box.toRect();
Expand Down
1 change: 1 addition & 0 deletions super_text_layout/lib/super_text_layout.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export 'src/caret_layer.dart';
export 'src/inline_widgets.dart';
export 'src/super_text.dart';
export 'src/super_text_layout_with_selection.dart';
export 'src/text_layout.dart';
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified super_text_layout/test_goldens/goldens/SuperText_layers_caret.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 1241dd9

Please sign in to comment.