Skip to content

Commit

Permalink
Remove selection gestures when enableInteractiveSelection is false (#…
Browse files Browse the repository at this point in the history
…351)

* Remove selection gesture detector when enableInteractiveSelection is `false`
  • Loading branch information
amantoux authored May 12, 2024
1 parent 67db8d1 commit 2726f7d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
8 changes: 4 additions & 4 deletions packages/fleather/lib/src/widgets/editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -491,10 +491,10 @@ class _FleatherEditorState extends State<FleatherEditor>
),
);

return _selectionGestureDetectorBuilder.buildGestureDetector(
behavior: HitTestBehavior.translucent,
child: child,
);
return widget.enableInteractiveSelection
? _selectionGestureDetectorBuilder.buildGestureDetector(
behavior: HitTestBehavior.translucent, child: child)
: child;
}
}

Expand Down
9 changes: 6 additions & 3 deletions packages/fleather/test/testing.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class EditorSandBox {
ParchmentDocument? document,
FleatherThemeData? fleatherTheme,
bool autofocus = false,
bool enableSelectionInteraction = true,
FakeSpellCheckService? spellCheckService,
ClipboardManager clipboardManager = const PlainTextClipboardManager(),
FleatherEmbedBuilder embedBuilder = defaultFleatherEmbedBuilder,
Expand All @@ -27,6 +28,7 @@ class EditorSandBox {
controller: controller,
focusNode: focusNode,
autofocus: autofocus,
enableSelectionInteraction: enableSelectionInteraction,
spellCheckService: spellCheckService,
embedBuilder: embedBuilder,
clipboardManager: clipboardManager,
Expand Down Expand Up @@ -139,6 +141,7 @@ class _FleatherSandbox extends StatefulWidget {
required this.controller,
required this.focusNode,
this.autofocus = false,
this.enableSelectionInteraction = true,
this.spellCheckService,
this.embedBuilder = defaultFleatherEmbedBuilder,
this.clipboardManager = const PlainTextClipboardManager(),
Expand All @@ -147,6 +150,7 @@ class _FleatherSandbox extends StatefulWidget {
final FleatherController controller;
final FocusNode focusNode;
final bool autofocus;
final bool enableSelectionInteraction;
final FakeSpellCheckService? spellCheckService;
final FleatherEmbedBuilder embedBuilder;
final ClipboardManager clipboardManager;
Expand All @@ -167,6 +171,7 @@ class _FleatherSandboxState extends State<_FleatherSandbox> {
controller: widget.controller,
focusNode: widget.focusNode,
readOnly: !_enabled,
enableInteractiveSelection: widget.enableSelectionInteraction,
autofocus: widget.autofocus,
spellCheckConfiguration: widget.spellCheckService != null
? SpellCheckConfiguration(
Expand All @@ -178,9 +183,7 @@ class _FleatherSandboxState extends State<_FleatherSandbox> {
}

void disable() {
setState(() {
_enabled = false;
});
setState(() => _enabled = false);
}
}

Expand Down
8 changes: 8 additions & 0 deletions packages/fleather/test/widgets/editor_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,14 @@ void main() {
});

group('Text selection', () {
testWidgets('disabled selection interaction disables associated gestures',
(tester) async {
final editor =
EditorSandBox(tester: tester, enableSelectionInteraction: false);
await editor.pump();
expect(find.byType(TextSelectionGestureDetector), findsNothing);
});

testWidgets('hides toolbar and selection handles when text changed',
(tester) async {
const delta = TextEditingDeltaInsertion(
Expand Down

0 comments on commit 2726f7d

Please sign in to comment.