Преглед на файлове

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

Anatoly Pulyaevskiy преди 6 години
родител
ревизия
bc10154b17

+ 4
- 2
packages/zefyr/CHANGELOG.md Целия файл

@@ -1,7 +1,9 @@
1 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 8
 ## 0.1.1
7 9
 

+ 9
- 0
packages/zefyr/lib/src/widgets/render_context.dart Целия файл

@@ -109,6 +109,15 @@ class ZefyrRenderContext extends ChangeNotifier {
109 109
       final localPoint = p.globalToLocal(point);
110 110
       return (localPoint.dy >= 0 && localPoint.dy < p.size.height);
111 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 122
     return box;
114 123
   }

+ 5
- 2
packages/zefyr/lib/src/widgets/selection.dart Целия файл

@@ -231,8 +231,11 @@ class _ZefyrSelectionOverlayState extends State<ZefyrSelectionOverlay>
231 231
     );
232 232
     if (_didCaretTap && _selection == selection) {
233 233
       _didCaretTap = false;
234
-      hideToolbar();
235
-      showToolbar();
234
+      if (isToolbarVisible) {
235
+        hideToolbar();
236
+      } else {
237
+        showToolbar();
238
+      }
236 239
     } else {
237 240
       _didCaretTap = true;
238 241
     }

+ 29
- 2
packages/zefyr/test/widgets/selection_test.dart Целия файл

@@ -34,8 +34,7 @@ void main() {
34 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 38
       final editor = new EditorSandBox(tester: tester);
40 39
       await editor.tapEditor();
41 40
       editor.controller
@@ -52,5 +51,33 @@ void main() {
52 51
       expect(editor.controller.selection.isCollapsed, isTrue);
53 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
 }