瀏覽代碼

fix scrollable offset lose

lucky1213 4 年之前
父節點
當前提交
7fb7e4b03d

+ 20
- 0
packages/zefyr/example/lib/src/full_page.dart 查看文件

@@ -141,6 +141,24 @@ class _FullPageEditorScreenState extends State<FullPageEditorScreen> {
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 162
           Expanded(
145 163
             child: ZefyrScaffold(
146 164
               child: ZefyrTheme(
@@ -180,6 +198,8 @@ class _FullPageEditorScreenState extends State<FullPageEditorScreen> {
180 198
   }
181 199
 
182 200
   void handlePopupItemSelected(value) {
201
+    FocusScope.of(context).unfocus();
202
+    print(FocusScope.of(context));
183 203
     if (!mounted) return;
184 204
     setState(() {
185 205
       if (value == _Options.darkTheme) {

+ 4
- 8
packages/zefyr/lib/src/widgets/common.dart 查看文件

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

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

+ 13
- 10
packages/zefyr/lib/src/widgets/editable_text.dart 查看文件

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

+ 12
- 1
packages/zefyr/lib/src/widgets/editor.dart 查看文件

@@ -171,6 +171,8 @@ class _ZefyrEditorState extends State<ZefyrEditor> {
171 171
         : fallbackTheme;
172 172
 
173 173
     if (_scope == null) {
174
+      // FocusScope.of(context).requestFocus(widget.focusNode);
175
+      // FocusScope.of(context).setFirstFocus(FocusScope.of(context));
174 176
       _scope = ZefyrScope.editable(
175 177
         mode: widget.mode,
176 178
         imageDelegate: _imageDelegate,
@@ -216,11 +218,20 @@ class _ZefyrEditorState extends State<ZefyrEditor> {
216 218
       selectionControls: widget.selectionControls,
217 219
       autofocus: widget.autofocus,
218 220
       mode: widget.mode,
219
-      input: _scope.input,
221
+      // input: _scope.input,
220 222
       padding: widget.padding,
221 223
       physics: widget.physics,
222 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 236
     return ZefyrTheme(
226 237
       data: _themeData,

+ 4
- 5
packages/zefyr/lib/src/widgets/scaffold.dart 查看文件

@@ -9,9 +9,8 @@ class ZefyrScaffold extends StatefulWidget {
9 9
   const ZefyrScaffold({Key key, this.child}) : super(key: key);
10 10
 
11 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 16
   @override
@@ -54,10 +53,10 @@ class ZefyrScaffoldState extends State<ZefyrScaffold> {
54 53
 class _ZefyrScaffoldAccess extends InheritedWidget {
55 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 58
   @override
60 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 查看文件

@@ -59,9 +59,9 @@ class ZefyrScope extends ChangeNotifier {
59 59
         _focusNode = focusNode,
60 60
         _focusScope = focusScope,
61 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 65
         _renderContext = ZefyrRenderContext() {
66 66
     _selectionStyle = _controller.getSelectionStyle();
67 67
     _selection = _controller.selection;
@@ -75,8 +75,8 @@ class ZefyrScope extends ChangeNotifier {
75 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 81
   bool _keepOverlay = false;
82 82
   bool get keepOverlay => _keepOverlay;

+ 3
- 2
packages/zefyr/lib/src/widgets/theme.dart 查看文件

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

+ 7
- 8
packages/zefyr/lib/src/widgets/toolbar.dart 查看文件

@@ -117,13 +117,6 @@ const kSpecialIconSizes = {
117 117
 
118 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 120
 const kTextColors = [
128 121
   Color(0xFFFA6400),
129 122
   Color(0xFFF7B500),
@@ -324,7 +317,13 @@ class ZefyrToolbarState extends State<ZefyrToolbar>
324 317
       _keyboardHeight = MediaQuery.of(context).viewInsets.bottom;
325 318
     }
326 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 327
     final layers = <Widget>[];
329 328
     Widget overlay;
330 329