Skip to content

Commit

Permalink
Add magnifier to text selection & better platform-specific behavior o…
Browse files Browse the repository at this point in the history
…f text selection (#198)

* New contextual menu implementation (Strongly inspired by Flutter)

* Bring into view upon selection

* Spell check functional

* Handle dragging the base handle that makes it the extent on Apple platforms

* Apply suggested changes

* Show magnifier on long tap with collapsed selection (mobile)

* Add spell check configuration to example
  • Loading branch information
amantoux authored Jan 1, 2024
1 parent cc0ea76 commit 5c77e83
Show file tree
Hide file tree
Showing 10 changed files with 2,417 additions and 373 deletions.
5 changes: 5 additions & 0 deletions packages/fleather/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ class _HomePageState extends State<HomePage> {
onLaunchUrl: _launchUrl,
maxContentWidth: 800,
embedBuilder: _embedBuilder,
spellCheckConfiguration: SpellCheckConfiguration(
spellCheckService: DefaultSpellCheckService(),
misspelledSelectionColor: Colors.red,
misspelledTextStyle:
DefaultTextStyle.of(context).style),
),
),
],
Expand Down
7 changes: 7 additions & 0 deletions packages/fleather/lib/src/rendering/editable_text_line.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class RenderEditableTextLine extends RenderEditableBox {
//

InlineCodeThemeData _inlineCodeTheme;

set inlineCodeTheme(InlineCodeThemeData theme) {
if (_inlineCodeTheme == theme) return;
_inlineCodeTheme = theme;
Expand Down Expand Up @@ -332,6 +333,12 @@ class RenderEditableTextLine extends RenderEditableBox {
final lineDy = caret.translate(0.0, 0.5 * preferredLineHeight(position)).dy;
final boxes = getBoxesForSelection(
TextSelection(baseOffset: 0, extentOffset: node.length - 1));

// If document is empty, boxes will be empty
// TextPainter (RenderParagraphProxy -> RenderParagraph) returns no boxes
// when it has not text
if (boxes.isEmpty) return const TextRange.collapsed(0);

final lineBoxes = boxes
.where((element) => element.top < lineDy && element.bottom > lineDy)
.toList(growable: false);
Expand Down
1 change: 0 additions & 1 deletion packages/fleather/lib/src/rendering/editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,6 @@ class RenderEditor extends RenderEditableContainerBox
@override
List<TextSelectionPoint> getEndpointsForSelection(TextSelection selection) {
// _layoutText(minWidth: constraints.minWidth, maxWidth: constraints.maxWidth);

if (selection.isCollapsed) {
final child = childAtPosition(selection.extent);
final localPosition =
Expand Down
Loading

0 comments on commit 5c77e83

Please sign in to comment.