Quellcode durchsuchen

Handle user taps on empty area inside editor; toggle selection toolbar on double tap

Anatoly Pulyaevskiy vor 6 Jahren
Ursprung
Commit
bc10154b17

+ 4
- 2
packages/zefyr/CHANGELOG.md Datei anzeigen

1
 ## 0.1.2
1
 ## 0.1.2
2
 
2
 
3
-* Fixed analysis warnings
4
-* Handle user taps on padding area around the editor.
3
+* Fixed analysis warnings.
4
+* UX: User taps on padding area around the editor and in empty space inside it now look for the nearest
5
+  paragraph to move caret to.
6
+* UX: Toggle selection toolbar on double tap instead of refreshing it.
5
 
7
 
6
 ## 0.1.1
8
 ## 0.1.1
7
 
9
 

+ 9
- 0
packages/zefyr/lib/src/widgets/render_context.dart Datei anzeigen

109
       final localPoint = p.globalToLocal(point);
109
       final localPoint = p.globalToLocal(point);
110
       return (localPoint.dy >= 0 && localPoint.dy < p.size.height);
110
       return (localPoint.dy >= 0 && localPoint.dy < p.size.height);
111
     }, orElse: _null);
111
     }, orElse: _null);
112
+    if (box != null) return box;
113
+
114
+    box = _activeBoxes.map((p) {
115
+      final localPoint = p.globalToLocal(point);
116
+      final distance = localPoint.dy - p.size.height;
117
+      return new MapEntry(distance.abs(), p);
118
+    }).reduce((a, b) {
119
+      return (a.key <= b.key) ? a : b;
120
+    }).value;
112
 
121
 
113
     return box;
122
     return box;
114
   }
123
   }

+ 5
- 2
packages/zefyr/lib/src/widgets/selection.dart Datei anzeigen

231
     );
231
     );
232
     if (_didCaretTap && _selection == selection) {
232
     if (_didCaretTap && _selection == selection) {
233
       _didCaretTap = false;
233
       _didCaretTap = false;
234
-      hideToolbar();
235
-      showToolbar();
234
+      if (isToolbarVisible) {
235
+        hideToolbar();
236
+      } else {
237
+        showToolbar();
238
+      }
236
     } else {
239
     } else {
237
       _didCaretTap = true;
240
       _didCaretTap = true;
238
     }
241
     }

+ 29
- 2
packages/zefyr/test/widgets/selection_test.dart Datei anzeigen

34
       expect(editor.findSelectionHandle(), findsNothing);
34
       expect(editor.findSelectionHandle(), findsNothing);
35
     });
35
     });
36
 
36
 
37
-    testWidgets('tap outside of text area finds closest paragraph',
38
-        (tester) async {
37
+    testWidgets('tap on padding area finds closest paragraph', (tester) async {
39
       final editor = new EditorSandBox(tester: tester);
38
       final editor = new EditorSandBox(tester: tester);
40
       await editor.tapEditor();
39
       await editor.tapEditor();
41
       editor.controller
40
       editor.controller
52
       expect(editor.controller.selection.isCollapsed, isTrue);
51
       expect(editor.controller.selection.isCollapsed, isTrue);
53
       expect(editor.controller.selection.extentOffset, 0);
52
       expect(editor.controller.selection.extentOffset, 0);
54
     });
53
     });
54
+
55
+    testWidgets('tap on empty space finds closest paragraph', (tester) async {
56
+      final editor = new EditorSandBox(tester: tester);
57
+      await editor.tapEditor();
58
+      editor.controller.replaceText(10, 1, '\n',
59
+          selection: new TextSelection.collapsed(offset: 0));
60
+      await tester.pumpAndSettle();
61
+      expect(editor.controller.document.toPlainText(),
62
+          'This House\nIs A Circus\n');
63
+      expect(editor.controller.selection.extentOffset, 0);
64
+
65
+      RenderBox renderObject =
66
+          tester.firstRenderObject(find.byType(ZefyrEditableText));
67
+      var offset = renderObject.localToGlobal(Offset.zero);
68
+      offset += Offset(50.0, renderObject.size.height - 5.0);
69
+      await tester.tapAt(offset);
70
+      await tester.pumpAndSettle();
71
+      expect(editor.controller.selection.isCollapsed, isTrue);
72
+      expect(editor.controller.selection.extentOffset,
73
+          13); // Note that this is probably too fragile.
74
+
75
+      offset = renderObject.localToGlobal(Offset.zero) + Offset(50.0, 1.0);
76
+      await tester.tapAt(offset);
77
+      await tester.pumpAndSettle();
78
+      expect(editor.controller.selection.isCollapsed, isTrue);
79
+      expect(editor.controller.selection.extentOffset,
80
+          2); // Note that this is probably too fragile.
81
+    });
55
   });
82
   });
56
 }
83
 }