Skip to content
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

[SuperText] - Add support for inline widgets (Resolves #2441) #2448

Merged
merged 3 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading