|
@@ -15,15 +15,14 @@ class ZefyrEditorScope extends ChangeNotifier {
|
15
|
15
|
@required ZefyrImageDelegate imageDelegate,
|
16
|
16
|
@required ZefyrController controller,
|
17
|
17
|
@required FocusNode focusNode,
|
18
|
|
- @required FocusNode toolbarFocusNode,
|
|
18
|
+ @required FocusScopeNode focusScope,
|
19
|
19
|
}) : _controller = controller,
|
20
|
20
|
_imageDelegate = imageDelegate,
|
21
|
|
- _focusNode = focusNode,
|
22
|
|
- _toolbarFocusNode = toolbarFocusNode {
|
|
21
|
+ _focusScope = focusScope,
|
|
22
|
+ _focusNode = focusNode {
|
23
|
23
|
_selectionStyle = _controller.getSelectionStyle();
|
24
|
24
|
_selection = _controller.selection;
|
25
|
25
|
_controller.addListener(_handleControllerChange);
|
26
|
|
- toolbarFocusNode.addListener(_handleFocusChange);
|
27
|
26
|
_focusNode.addListener(_handleFocusChange);
|
28
|
27
|
}
|
29
|
28
|
|
|
@@ -32,9 +31,9 @@ class ZefyrEditorScope extends ChangeNotifier {
|
32
|
31
|
ZefyrImageDelegate _imageDelegate;
|
33
|
32
|
ZefyrImageDelegate get imageDelegate => _imageDelegate;
|
34
|
33
|
|
|
34
|
+ FocusScopeNode get focusScope => _focusScope;
|
|
35
|
+ FocusScopeNode _focusScope;
|
35
|
36
|
FocusNode _focusNode;
|
36
|
|
- FocusNode _toolbarFocusNode;
|
37
|
|
- FocusNode get toolbarFocusNode => _toolbarFocusNode;
|
38
|
37
|
|
39
|
38
|
ZefyrController _controller;
|
40
|
39
|
NotusStyle get selectionStyle => _selectionStyle;
|
|
@@ -46,7 +45,6 @@ class ZefyrEditorScope extends ChangeNotifier {
|
46
|
45
|
void dispose() {
|
47
|
46
|
assert(!_disposed);
|
48
|
47
|
_controller.removeListener(_handleControllerChange);
|
49
|
|
- _toolbarFocusNode.removeListener(_handleFocusChange);
|
50
|
48
|
_focusNode.removeListener(_handleFocusChange);
|
51
|
49
|
_disposed = true;
|
52
|
50
|
super.dispose();
|
|
@@ -102,11 +100,23 @@ class ZefyrEditorScope extends ChangeNotifier {
|
102
|
100
|
notifyListeners();
|
103
|
101
|
}
|
104
|
102
|
|
|
103
|
+ FocusNode _toolbarFocusNode;
|
|
104
|
+
|
|
105
|
+ void setToolbarFocusNode(FocusNode node) {
|
|
106
|
+ assert(!_disposed);
|
|
107
|
+ if (_toolbarFocusNode != node) {
|
|
108
|
+ _toolbarFocusNode?.removeListener(_handleFocusChange);
|
|
109
|
+ _toolbarFocusNode = node;
|
|
110
|
+ _toolbarFocusNode.addListener(_handleFocusChange);
|
|
111
|
+ notifyListeners();
|
|
112
|
+ }
|
|
113
|
+ }
|
|
114
|
+
|
105
|
115
|
FocusOwner get focusOwner {
|
106
|
116
|
assert(!_disposed);
|
107
|
117
|
if (_focusNode.hasFocus) {
|
108
|
118
|
return FocusOwner.editor;
|
109
|
|
- } else if (toolbarFocusNode.hasFocus) {
|
|
119
|
+ } else if (_toolbarFocusNode?.hasFocus == true) {
|
110
|
120
|
return FocusOwner.toolbar;
|
111
|
121
|
} else {
|
112
|
122
|
return FocusOwner.none;
|
|
@@ -124,9 +134,9 @@ class ZefyrEditorScope extends ChangeNotifier {
|
124
|
134
|
_controller.formatSelection(value);
|
125
|
135
|
}
|
126
|
136
|
|
127
|
|
- void focus(BuildContext context) {
|
|
137
|
+ void focus() {
|
128
|
138
|
assert(!_disposed);
|
129
|
|
- FocusScope.of(context).requestFocus(_focusNode);
|
|
139
|
+ _focusScope.requestFocus(_focusNode);
|
130
|
140
|
}
|
131
|
141
|
|
132
|
142
|
void hideKeyboard() {
|
|
@@ -181,7 +191,6 @@ class ZefyrEditor extends StatefulWidget {
|
181
|
191
|
}
|
182
|
192
|
|
183
|
193
|
class _ZefyrEditorState extends State<ZefyrEditor> {
|
184
|
|
- final FocusNode _toolbarFocusNode = new FocusNode();
|
185
|
194
|
ZefyrImageDelegate _imageDelegate;
|
186
|
195
|
ZefyrEditorScope _scope;
|
187
|
196
|
ZefyrThemeData _themeData;
|
|
@@ -194,7 +203,6 @@ class _ZefyrEditorState extends State<ZefyrEditor> {
|
194
|
203
|
builder: (context) => _ZefyrToolbarContainer(
|
195
|
204
|
theme: _themeData,
|
196
|
205
|
toolbar: ZefyrToolbar(
|
197
|
|
- focusNode: _toolbarFocusNode,
|
198
|
206
|
editor: _scope,
|
199
|
207
|
delegate: widget.toolbarDelegate,
|
200
|
208
|
),
|
|
@@ -213,6 +221,10 @@ class _ZefyrEditorState extends State<ZefyrEditor> {
|
213
|
221
|
hideToolbar();
|
214
|
222
|
} else if (_toolbar == null) {
|
215
|
223
|
showToolbar();
|
|
224
|
+ } else {
|
|
225
|
+ WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
226
|
+ _toolbar?.markNeedsBuild();
|
|
227
|
+ });
|
216
|
228
|
}
|
217
|
229
|
}
|
218
|
230
|
|
|
@@ -220,13 +232,6 @@ class _ZefyrEditorState extends State<ZefyrEditor> {
|
220
|
232
|
void initState() {
|
221
|
233
|
super.initState();
|
222
|
234
|
_imageDelegate = widget.imageDelegate ?? new ZefyrDefaultImageDelegate();
|
223
|
|
- _scope = ZefyrEditorScope(
|
224
|
|
- toolbarFocusNode: _toolbarFocusNode,
|
225
|
|
- imageDelegate: _imageDelegate,
|
226
|
|
- controller: widget.controller,
|
227
|
|
- focusNode: widget.focusNode,
|
228
|
|
- );
|
229
|
|
- _scope.addListener(_handleChange);
|
230
|
235
|
}
|
231
|
236
|
|
232
|
237
|
@override
|
|
@@ -244,6 +249,21 @@ class _ZefyrEditorState extends State<ZefyrEditor> {
|
244
|
249
|
void didChangeDependencies() {
|
245
|
250
|
super.didChangeDependencies();
|
246
|
251
|
|
|
252
|
+ if (_scope == null) {
|
|
253
|
+ _scope = ZefyrEditorScope(
|
|
254
|
+ imageDelegate: _imageDelegate,
|
|
255
|
+ controller: widget.controller,
|
|
256
|
+ focusNode: widget.focusNode,
|
|
257
|
+ focusScope: FocusScope.of(context),
|
|
258
|
+ );
|
|
259
|
+ _scope.addListener(_handleChange);
|
|
260
|
+ } else {
|
|
261
|
+ final focusScope = FocusScope.of(context);
|
|
262
|
+ if (focusScope != _scope._focusScope) {
|
|
263
|
+ _scope._focusScope = focusScope;
|
|
264
|
+ }
|
|
265
|
+ }
|
|
266
|
+
|
247
|
267
|
final parentTheme = ZefyrTheme.of(context, nullOk: true);
|
248
|
268
|
final fallbackTheme = ZefyrThemeData.fallback(context);
|
249
|
269
|
_themeData = (parentTheme != null)
|
|
@@ -263,7 +283,6 @@ class _ZefyrEditorState extends State<ZefyrEditor> {
|
263
|
283
|
hideToolbar();
|
264
|
284
|
_scope.removeListener(_handleChange);
|
265
|
285
|
_scope.dispose();
|
266
|
|
- _toolbarFocusNode.dispose();
|
267
|
286
|
super.dispose();
|
268
|
287
|
}
|
269
|
288
|
|