Browse Source

fix search

lucky1213 4 years ago
parent
commit
8f26f3c1ba

+ 1
- 1
packages/notus/lib/src/document.dart View File

@@ -325,7 +325,7 @@ class NotusDocument {
325 325
     }
326 326
   }
327 327
 
328
-  SearchResultEntity search(String text) {
328
+  SearchResultEntity search([String text = '']) {
329 329
     return _searchController.search(this, text);
330 330
   }
331 331
 

+ 1
- 1
packages/notus/lib/src/search.dart View File

@@ -12,7 +12,7 @@ class NotusSearch {
12 12
   List<RegExpMatch> _result = [];
13 13
   SearchResultEntity _entity = const SearchResultEntity();
14 14
 
15
-  SearchResultEntity search(NotusDocument doc, String text) {
15
+  SearchResultEntity search(NotusDocument doc, [String text = '']) {
16 16
     // 恢复
17 17
     for (var i = 0; i < _result.length; i++) {
18 18
       RegExpMatch item = _result[i];

+ 3
- 2
packages/zefyr/lib/src/widgets/common.dart View File

@@ -110,16 +110,17 @@ class _ZefyrLineState extends State<ZefyrLine> {
110 110
     final RenderAbstractViewport viewport = RenderAbstractViewport.of(object);
111 111
     assert(viewport != null);
112 112
     final lineTheme = ZefyrTheme.of(context).defaultLineTheme;
113
+    final lineHieght = lineTheme.textStyle.fontSize * lineTheme.textStyle.height;
113 114
 
114 115
     final double offset = scrollable.position.pixels;
115 116
     double target = viewport.getOffsetToReveal(object, 0.0).offset;
116 117
     if (target - offset < 0.0) {
117
-      scrollable.position.jumpTo(target + lineTheme.textStyle.fontSize);
118
+      scrollable.position.jumpTo(target + lineHieght);
118 119
       return;
119 120
     }
120 121
     target = viewport.getOffsetToReveal(object, 1.0).offset;
121 122
     if (target - offset > 0.0) {
122
-      scrollable.position.jumpTo(target + lineTheme.textStyle.fontSize);
123
+      scrollable.position.jumpTo(target + lineHieght);
123 124
     }
124 125
   }
125 126
 

+ 6
- 3
packages/zefyr/lib/src/widgets/controller.dart View File

@@ -229,21 +229,24 @@ class ZefyrController extends ChangeNotifier {
229 229
   SearchResultEntity search(String text) {
230 230
     SearchResultEntity result = document.search(text);
231 231
     updateSelection(TextSelection.collapsed(offset: result.offset), source: ChangeSource.remote);
232
-    notifyListeners();
232
+    return result;
233
+  }
234
+
235
+  SearchResultEntity closeSearch() {
236
+    SearchResultEntity result = document.search();
237
+    updateSelection(TextSelection.collapsed(offset: result.offset), source: ChangeSource.remote);
233 238
     return result;
234 239
   }
235 240
 
236 241
   SearchResultEntity searchPrev() {
237 242
     SearchResultEntity result = document.searchPrev();
238 243
     updateSelection(TextSelection.collapsed(offset: result.offset), source: ChangeSource.remote);
239
-    notifyListeners();
240 244
     return result;
241 245
   }
242 246
 
243 247
   SearchResultEntity searchNext() {
244 248
     SearchResultEntity result = document.searchNext();
245 249
     updateSelection(TextSelection.collapsed(offset: result.offset), source: ChangeSource.remote);
246
-    notifyListeners();
247 250
     return result;
248 251
   }
249 252