fix: the selection should be clear if header or footer is focusing (#525)
This commit is contained in:
parent
5155663163
commit
78b004565c
4 changed files with 84 additions and 5 deletions
|
|
@ -37,7 +37,7 @@ class _FocusExampleForEditorState extends State<FocusExampleForEditor> {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
backgroundColor: Colors.black,
|
backgroundColor: Colors.black,
|
||||||
title: const Text('Custom Theme For Editor'),
|
title: const Text('Focus Node Example'),
|
||||||
titleTextStyle: const TextStyle(color: Colors.white),
|
titleTextStyle: const TextStyle(color: Colors.white),
|
||||||
iconTheme: const IconThemeData(
|
iconTheme: const IconThemeData(
|
||||||
color: Colors.white,
|
color: Colors.white,
|
||||||
|
|
@ -52,7 +52,21 @@ class _FocusExampleForEditorState extends State<FocusExampleForEditor> {
|
||||||
builder: (context, snapshot) {
|
builder: (context, snapshot) {
|
||||||
return !snapshot.hasData
|
return !snapshot.hasData
|
||||||
? const Center(child: CircularProgressIndicator())
|
? const Center(child: CircularProgressIndicator())
|
||||||
: AppFlowyEditor(editorState: snapshot.data!);
|
: AppFlowyEditor(
|
||||||
|
editorState: snapshot.data!,
|
||||||
|
header: const TextField(
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
decoration: InputDecoration(
|
||||||
|
hintText: 'Header: Please input something ...',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
footer: const TextField(
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
decoration: InputDecoration(
|
||||||
|
hintText: 'Footer: Please input something ...',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,54 @@
|
||||||
|
import 'dart:math';
|
||||||
|
|
||||||
|
import 'package:appflowy_editor/appflowy_editor.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
|
class IgnoreEditorSelectionGesture extends StatefulWidget {
|
||||||
|
const IgnoreEditorSelectionGesture({
|
||||||
|
super.key,
|
||||||
|
required this.child,
|
||||||
|
});
|
||||||
|
|
||||||
|
final Widget child;
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<IgnoreEditorSelectionGesture> createState() =>
|
||||||
|
_IgnoreEditorSelectionGestureState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _IgnoreEditorSelectionGestureState
|
||||||
|
extends State<IgnoreEditorSelectionGesture> {
|
||||||
|
final key = Random(10000).toString();
|
||||||
|
late final SelectionGestureInterceptor interceptor;
|
||||||
|
late final EditorState editorState = context.read<EditorState>();
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
|
||||||
|
interceptor = SelectionGestureInterceptor(
|
||||||
|
key: key,
|
||||||
|
canTap: (details) {
|
||||||
|
final renderObject = context.findRenderObject();
|
||||||
|
if (renderObject != null && renderObject is RenderBox) {
|
||||||
|
final offset = renderObject.globalToLocal(details.globalPosition);
|
||||||
|
return !renderObject.paintBounds.contains(offset);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
editorState.selectionService.registerGestureInterceptor(interceptor);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
editorState.selectionService.unregisterGestureInterceptor(key);
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return widget.child;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import 'package:appflowy_editor/appflowy_editor.dart';
|
import 'package:appflowy_editor/appflowy_editor.dart';
|
||||||
|
import 'package:appflowy_editor/src/editor/block_component/base_component/widget/ignore_parent_gesture.dart';
|
||||||
import 'package:appflowy_editor/src/flutter/scrollable_positioned_list/scrollable_positioned_list.dart';
|
import 'package:appflowy_editor/src/flutter/scrollable_positioned_list/scrollable_positioned_list.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
|
|
@ -82,8 +83,16 @@ class PageBlockComponent extends BlockComponentStatelessWidget {
|
||||||
itemCount: items.length + extentCount,
|
itemCount: items.length + extentCount,
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
editorState.updateAutoScroller(Scrollable.of(context));
|
editorState.updateAutoScroller(Scrollable.of(context));
|
||||||
if (header != null && index == 0) return header!;
|
if (header != null && index == 0) {
|
||||||
if (footer != null && index == items.length + 1) return footer!;
|
return IgnoreEditorSelectionGesture(
|
||||||
|
child: header!,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (footer != null && index == items.length + 1) {
|
||||||
|
return IgnoreEditorSelectionGesture(
|
||||||
|
child: footer!,
|
||||||
|
);
|
||||||
|
}
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: editorState.editorStyle.padding,
|
padding: editorState.editorStyle.padding,
|
||||||
child: editorState.renderer.build(
|
child: editorState.renderer.build(
|
||||||
|
|
|
||||||
|
|
@ -196,7 +196,9 @@ class _DesktopSelectionServiceWidgetState
|
||||||
final canTap = _interceptors.every(
|
final canTap = _interceptors.every(
|
||||||
(element) => element.canTap?.call(details) ?? true,
|
(element) => element.canTap?.call(details) ?? true,
|
||||||
);
|
);
|
||||||
if (!canTap) return;
|
if (!canTap) {
|
||||||
|
return updateSelection(null);
|
||||||
|
}
|
||||||
|
|
||||||
final offset = details.globalPosition;
|
final offset = details.globalPosition;
|
||||||
final node = getNodeInOffset(offset);
|
final node = getNodeInOffset(offset);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue