Ver código fonte

fix scrollable offset lose

lucky1213 5 anos atrás
pai
commit
7fb7e4b03d

+ 20
- 0
packages/zefyr/example/lib/src/full_page.dart Ver arquivo

141
               ],
141
               ],
142
             ),
142
             ),
143
           ),
143
           ),
144
+          // Expanded(
145
+          //   child: Container(
146
+          //     margin: EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom),
147
+          //     child: TextField(
148
+          //       // config: TextFieldConfig(
149
+          //       //   maxLines: null,
150
+          //       // ),
151
+          //       // style: TextFieldStyle(
152
+          //       //   padding: EdgeInsets.symmetric(
153
+          //       //     vertical: Dimens.gap_dp16,
154
+          //       //     horizontal: Dimens.gap_dp20,
155
+          //       //   ),
156
+          //       // ),
157
+          //       maxLines: null,
158
+          //       controller: TextEditingController(text: _controller.document.toString()),
159
+          //     ),
160
+          //   ),
161
+          // ),
144
           Expanded(
162
           Expanded(
145
             child: ZefyrScaffold(
163
             child: ZefyrScaffold(
146
               child: ZefyrTheme(
164
               child: ZefyrTheme(
180
   }
198
   }
181
 
199
 
182
   void handlePopupItemSelected(value) {
200
   void handlePopupItemSelected(value) {
201
+    FocusScope.of(context).unfocus();
202
+    print(FocusScope.of(context));
183
     if (!mounted) return;
203
     if (!mounted) return;
184
     setState(() {
204
     setState(() {
185
       if (value == _Options.darkTheme) {
205
       if (value == _Options.darkTheme) {

+ 4
- 8
packages/zefyr/lib/src/widgets/common.dart Ver arquivo

56
         node: widget.node,
56
         node: widget.node,
57
         text: buildText(context),
57
         text: buildText(context),
58
       );
58
       );
59
-      // content = RichText(
60
-      //   text: TextSpan(
61
-      //     text: '123',
62
-      //   )
63
-      // );
64
     }
59
     }
65
 
60
 
66
     if (scope.isEditable) {
61
     if (scope.isEditable) {
101
 
96
 
102
   void ensureVisible(BuildContext context, ZefyrScope scope) {
97
   void ensureVisible(BuildContext context, ZefyrScope scope) {
103
     if (scope.selection.isCollapsed &&
98
     if (scope.selection.isCollapsed &&
104
-        widget.node.containsOffset(scope.selection.extentOffset)) {
99
+        widget.node.containsOffset(scope.selection.extentOffset) && scope.selection.extentOffset != 0) {
105
       WidgetsBinding.instance.addPostFrameCallback((_) {
100
       WidgetsBinding.instance.addPostFrameCallback((_) {
106
         bringIntoView(context);
101
         bringIntoView(context);
107
       });
102
       });
114
     assert(object.attached);
109
     assert(object.attached);
115
     final RenderAbstractViewport viewport = RenderAbstractViewport.of(object);
110
     final RenderAbstractViewport viewport = RenderAbstractViewport.of(object);
116
     assert(viewport != null);
111
     assert(viewport != null);
112
+    final lineTheme = ZefyrTheme.of(context).defaultLineTheme;
117
 
113
 
118
     final double offset = scrollable.position.pixels;
114
     final double offset = scrollable.position.pixels;
119
     double target = viewport.getOffsetToReveal(object, 0.0).offset;
115
     double target = viewport.getOffsetToReveal(object, 0.0).offset;
120
     if (target - offset < 0.0) {
116
     if (target - offset < 0.0) {
121
-      scrollable.position.jumpTo(target);
117
+      scrollable.position.jumpTo(target + lineTheme.textStyle.fontSize);
122
       return;
118
       return;
123
     }
119
     }
124
     target = viewport.getOffsetToReveal(object, 1.0).offset;
120
     target = viewport.getOffsetToReveal(object, 1.0).offset;
125
     if (target - offset > 0.0) {
121
     if (target - offset > 0.0) {
126
-      scrollable.position.jumpTo(target);
122
+      scrollable.position.jumpTo(target + lineTheme.textStyle.fontSize);
127
     }
123
     }
128
   }
124
   }
129
 
125
 

+ 3
- 0
packages/zefyr/lib/src/widgets/controller.dart Ver arquivo

34
   /// Zefyr document managed by this controller.
34
   /// Zefyr document managed by this controller.
35
   NotusDocument get document => _document;
35
   NotusDocument get document => _document;
36
   NotusDocument _document;
36
   NotusDocument _document;
37
+  set document(NotusDocument value) {
38
+    _document = value;
39
+  }
37
 
40
 
38
   /// Currently selected text within the [document].
41
   /// Currently selected text within the [document].
39
   TextSelection get selection => _selection;
42
   TextSelection get selection => _selection;

+ 13
- 10
packages/zefyr/lib/src/widgets/editable_text.dart Ver arquivo

39
     this.selectionControls,
39
     this.selectionControls,
40
     this.autofocus = true,
40
     this.autofocus = true,
41
     this.mode = ZefyrMode.edit,
41
     this.mode = ZefyrMode.edit,
42
-    @required this.input,
42
+    // @required this.input,
43
     this.padding = const EdgeInsets.symmetric(horizontal: 16.0),
43
     this.padding = const EdgeInsets.symmetric(horizontal: 16.0),
44
     this.physics,
44
     this.physics,
45
     this.keyboardAppearance = Brightness.light,
45
     this.keyboardAppearance = Brightness.light,
68
   /// Editing mode of this text field.
68
   /// Editing mode of this text field.
69
   final ZefyrMode mode;
69
   final ZefyrMode mode;
70
 
70
 
71
-  final InputConnectionController input;
71
+  // final InputConnectionController input;
72
 
72
 
73
   /// Controls physics of scrollable text field.
73
   /// Controls physics of scrollable text field.
74
   final ScrollPhysics physics;
74
   final ScrollPhysics physics;
89
   final Brightness keyboardAppearance;
89
   final Brightness keyboardAppearance;
90
 
90
 
91
   @override
91
   @override
92
-  _ZefyrEditableTextState createState() => _ZefyrEditableTextState();
92
+  ZefyrEditableTextState createState() => ZefyrEditableTextState();
93
 }
93
 }
94
 
94
 
95
-class _ZefyrEditableTextState extends State<ZefyrEditableText>
95
+class ZefyrEditableTextState extends State<ZefyrEditableText>
96
     with AutomaticKeepAliveClientMixin {
96
     with AutomaticKeepAliveClientMixin {
97
   //
97
   //
98
   // New public members
98
   // New public members
176
     _focusNode = widget.focusNode;
176
     _focusNode = widget.focusNode;
177
     super.initState();
177
     super.initState();
178
     _focusAttachment = _focusNode.attach(context);
178
     _focusAttachment = _focusNode.attach(context);
179
+    // widget.controller.updateSelection(TextSelection.collapsed(offset: widget.controller.plainTextEditingValue.text.length));
180
+    _input = InputConnectionController(_handleRemoteValueChange);
181
+    // ..openConnection(widget.controller.plainTextEditingValue, widget.keyboardAppearance, showKeyboard: false);
182
+    
179
     _updateSubscriptions();
183
     _updateSubscriptions();
180
   }
184
   }
181
 
185
 
205
       _cursorTimer = scope.cursorTimer;
209
       _cursorTimer = scope.cursorTimer;
206
       _cursorTimer.startOrStop(_focusNode, selection);
210
       _cursorTimer.startOrStop(_focusNode, selection);
207
     }
211
     }
212
+    print(FocusScope.of(context));
208
     focusOrUnfocusIfNeeded();
213
     focusOrUnfocusIfNeeded();
209
   }
214
   }
210
 
215
 
229
   final ScrollController _scrollController = ScrollController();
234
   final ScrollController _scrollController = ScrollController();
230
   ZefyrRenderContext _renderContext;
235
   ZefyrRenderContext _renderContext;
231
   CursorTimer _cursorTimer;
236
   CursorTimer _cursorTimer;
232
-  InputConnectionController get _input => widget.input;
237
+  InputConnectionController _input;
238
+  // InputConnectionController get _input => widget.input;
233
   bool _didAutoFocus = false;
239
   bool _didAutoFocus = false;
234
 
240
 
235
   List<Widget> _buildChildren(BuildContext context) {
241
   List<Widget> _buildChildren(BuildContext context) {
248
         return ZefyrHeading(node: node);
254
         return ZefyrHeading(node: node);
249
       }
255
       }
250
       return ZefyrParagraph(node: node);
256
       return ZefyrParagraph(node: node);
251
-      //  else if (node.style.contains(NotusAttribute.line)) {
252
-      //   return ZefyrLineDecoration(node: node);
253
-      // }
254
     }
257
     }
255
 
258
 
256
     final BlockNode block = node;
259
     final BlockNode block = node;
283
     if (widget.focusNode != oldWidget.focusNode) {
286
     if (widget.focusNode != oldWidget.focusNode) {
284
       oldWidget.focusNode.removeListener(_handleFocusChange);
287
       oldWidget.focusNode.removeListener(_handleFocusChange);
285
       widget.focusNode.addListener(_handleFocusChange);
288
       widget.focusNode.addListener(_handleFocusChange);
286
-      updateKeepAlive();
289
+      // updateKeepAlive();
287
     }
290
     }
288
   }
291
   }
289
 
292
 
320
     _input.openOrCloseConnection(_focusNode,
323
     _input.openOrCloseConnection(_focusNode,
321
         widget.controller.plainTextEditingValue, widget.keyboardAppearance, showKeyboard: showKeyboard);
324
         widget.controller.plainTextEditingValue, widget.keyboardAppearance, showKeyboard: showKeyboard);
322
     _cursorTimer.startOrStop(_focusNode, selection);
325
     _cursorTimer.startOrStop(_focusNode, selection);
323
-    updateKeepAlive();
326
+    // updateKeepAlive();
324
   }
327
   }
325
 
328
 
326
   void _handleRemoteValueChange(
329
   void _handleRemoteValueChange(

+ 12
- 1
packages/zefyr/lib/src/widgets/editor.dart Ver arquivo

171
         : fallbackTheme;
171
         : fallbackTheme;
172
 
172
 
173
     if (_scope == null) {
173
     if (_scope == null) {
174
+      // FocusScope.of(context).requestFocus(widget.focusNode);
175
+      // FocusScope.of(context).setFirstFocus(FocusScope.of(context));
174
       _scope = ZefyrScope.editable(
176
       _scope = ZefyrScope.editable(
175
         mode: widget.mode,
177
         mode: widget.mode,
176
         imageDelegate: _imageDelegate,
178
         imageDelegate: _imageDelegate,
216
       selectionControls: widget.selectionControls,
218
       selectionControls: widget.selectionControls,
217
       autofocus: widget.autofocus,
219
       autofocus: widget.autofocus,
218
       mode: widget.mode,
220
       mode: widget.mode,
219
-      input: _scope.input,
221
+      // input: _scope.input,
220
       padding: widget.padding,
222
       padding: widget.padding,
221
       physics: widget.physics,
223
       physics: widget.physics,
222
       keyboardAppearance: keyboardAppearance,
224
       keyboardAppearance: keyboardAppearance,
223
     );
225
     );
226
+    // Widget editable = SingleChildScrollView(
227
+    //       physics: widget.physics,
228
+    //       child: Column(
229
+    //         children: List.generate(100, (index) => Container(
230
+    //           height: 50,
231
+    //           color: Colors.black.withOpacity(index / 100),
232
+    //         ),),
233
+    //       ),
234
+    //     );
224
 
235
 
225
     return ZefyrTheme(
236
     return ZefyrTheme(
226
       data: _themeData,
237
       data: _themeData,

+ 4
- 5
packages/zefyr/lib/src/widgets/scaffold.dart Ver arquivo

9
   const ZefyrScaffold({Key key, this.child}) : super(key: key);
9
   const ZefyrScaffold({Key key, this.child}) : super(key: key);
10
 
10
 
11
   static ZefyrScaffoldState of(BuildContext context) {
11
   static ZefyrScaffoldState of(BuildContext context) {
12
-    final _ZefyrScaffoldAccess widget =
13
-        context.dependOnInheritedWidgetOfExactType<_ZefyrScaffoldAccess>();
14
-    return widget.scaffold;
12
+    final widget = context.dependOnInheritedWidgetOfExactType<_ZefyrScaffoldAccess>();
13
+    return widget?.scaffold;
15
   }
14
   }
16
 
15
 
17
   @override
16
   @override
54
 class _ZefyrScaffoldAccess extends InheritedWidget {
53
 class _ZefyrScaffoldAccess extends InheritedWidget {
55
   final ZefyrScaffoldState scaffold;
54
   final ZefyrScaffoldState scaffold;
56
 
55
 
57
-  _ZefyrScaffoldAccess({Widget child, this.scaffold}) : super(child: child);
56
+  _ZefyrScaffoldAccess({Key key, Widget child, this.scaffold}) : super(key: key, child: child);
58
 
57
 
59
   @override
58
   @override
60
   bool updateShouldNotify(_ZefyrScaffoldAccess oldWidget) {
59
   bool updateShouldNotify(_ZefyrScaffoldAccess oldWidget) {
61
-    return oldWidget.scaffold != scaffold;
60
+    return true;//oldWidget.scaffold != scaffold;
62
   }
61
   }
63
 }
62
 }

+ 5
- 5
packages/zefyr/lib/src/widgets/scope.dart Ver arquivo

59
         _focusNode = focusNode,
59
         _focusNode = focusNode,
60
         _focusScope = focusScope,
60
         _focusScope = focusScope,
61
         _cursorTimer = CursorTimer(),
61
         _cursorTimer = CursorTimer(),
62
-        _input = InputConnectionController((int start, String deleted, String inserted, TextSelection selection) {
63
-          controller.replaceText(start, deleted.length, inserted, selection: selection);
64
-        }),
62
+        // _input = InputConnectionController((int start, String deleted, String inserted, TextSelection selection) {
63
+        //   controller.replaceText(start, deleted.length, inserted, selection: selection);
64
+        // }),
65
         _renderContext = ZefyrRenderContext() {
65
         _renderContext = ZefyrRenderContext() {
66
     _selectionStyle = _controller.getSelectionStyle();
66
     _selectionStyle = _controller.getSelectionStyle();
67
     _selection = _controller.selection;
67
     _selection = _controller.selection;
75
     return widget.scope;
75
     return widget.scope;
76
   }
76
   }
77
 
77
 
78
-  InputConnectionController _input;
79
-  InputConnectionController get input => _input;
78
+  // InputConnectionController _input;
79
+  // InputConnectionController get input => _input;
80
 
80
 
81
   bool _keepOverlay = false;
81
   bool _keepOverlay = false;
82
   bool get keepOverlay => _keepOverlay;
82
   bool get keepOverlay => _keepOverlay;

+ 3
- 2
packages/zefyr/lib/src/widgets/theme.dart Ver arquivo

72
 
72
 
73
   /// The default editor theme.
73
   /// The default editor theme.
74
   factory ZefyrThemeData.fallback(BuildContext context) {
74
   factory ZefyrThemeData.fallback(BuildContext context) {
75
+    final theme = Theme.of(context);
75
     final defaultStyle = DefaultTextStyle.of(context);
76
     final defaultStyle = DefaultTextStyle.of(context);
76
     final defaultLineTheme = LineTheme(
77
     final defaultLineTheme = LineTheme(
77
       textStyle: defaultStyle.style.copyWith(
78
       textStyle: defaultStyle.style.copyWith(
78
         fontSize: 16.0,
79
         fontSize: 16.0,
79
         height: 1.3,
80
         height: 1.3,
80
-        color: Color(0xFF595959),
81
+        color: theme.brightness == Brightness.light ? Color(0xFF595959) : Color(0xFFA8A8A8),
81
       ),
82
       ),
82
       padding: EdgeInsets.symmetric(vertical: 8.0),
83
       padding: EdgeInsets.symmetric(vertical: 8.0),
83
     );
84
     );
388
           height: 1.5,
389
           height: 1.5,
389
           fontWeight: FontWeight.w500,
390
           fontWeight: FontWeight.w500,
390
         ),
391
         ),
391
-        padding: EdgeInsets.only(top: 16.0),
392
+        padding: EdgeInsets.only(top: 8.0),
392
       ),
393
       ),
393
       heading2: LineTheme(
394
       heading2: LineTheme(
394
         textStyle: defaultLineTheme.textStyle.copyWith(
395
         textStyle: defaultLineTheme.textStyle.copyWith(

+ 7
- 8
packages/zefyr/lib/src/widgets/toolbar.dart Ver arquivo

117
 
117
 
118
 const kDefaultButtonTexts = {};
118
 const kDefaultButtonTexts = {};
119
 
119
 
120
-final kToolbarDivider = Container(
121
-  width: 1,
122
-  color: Color(0xFFE2E2E2),
123
-  height: 28,
124
-  margin: EdgeInsets.symmetric(horizontal: 10),
125
-);
126
-
127
 const kTextColors = [
120
 const kTextColors = [
128
   Color(0xFFFA6400),
121
   Color(0xFFFA6400),
129
   Color(0xFFF7B500),
122
   Color(0xFFF7B500),
324
       _keyboardHeight = MediaQuery.of(context).viewInsets.bottom;
317
       _keyboardHeight = MediaQuery.of(context).viewInsets.bottom;
325
     }
318
     }
326
     final theme = ZefyrTheme.of(context).toolbarTheme;
319
     final theme = ZefyrTheme.of(context).toolbarTheme;
327
-    
320
+
321
+    final kToolbarDivider = Container(
322
+      width: 1,
323
+      color: theme.dividerColor,
324
+      height: 28,
325
+      margin: EdgeInsets.symmetric(horizontal: 10),
326
+    );
328
     final layers = <Widget>[];
327
     final layers = <Widget>[];
329
     Widget overlay;
328
     Widget overlay;
330
 
329