|
@@ -12,6 +12,7 @@ import 'document/line.dart';
|
12
|
12
|
import 'document/node.dart';
|
13
|
13
|
import 'heuristics.dart';
|
14
|
14
|
import 'history.dart';
|
|
15
|
+import 'search.dart';
|
15
|
16
|
|
16
|
17
|
/// Source of a [NotusChange].
|
17
|
18
|
enum ChangeSource {
|
|
@@ -44,6 +45,7 @@ class NotusDocument {
|
44
|
45
|
// _delta = Delta()..insert('\n') {
|
45
|
46
|
_history = NotusHistory(),
|
46
|
47
|
_delta = Delta()..insert('\n') {
|
|
48
|
+ _searchController = NotusSearch(_delta);
|
47
|
49
|
_loadDocument(_delta);
|
48
|
50
|
}
|
49
|
51
|
|
|
@@ -51,6 +53,7 @@ class NotusDocument {
|
51
|
53
|
: _heuristics = NotusHeuristics.fallback,
|
52
|
54
|
_history = NotusHistory(),
|
53
|
55
|
_delta = Delta.fromJson(data) {
|
|
56
|
+ _searchController = NotusSearch(_delta);
|
54
|
57
|
_loadDocument(_delta);
|
55
|
58
|
}
|
56
|
59
|
|
|
@@ -58,6 +61,7 @@ class NotusDocument {
|
58
|
61
|
: assert(delta != null),
|
59
|
62
|
_heuristics = NotusHeuristics.fallback,
|
60
|
63
|
_history = NotusHistory(),
|
|
64
|
+ _searchController = NotusSearch(delta),
|
61
|
65
|
_delta = delta {
|
62
|
66
|
_loadDocument(_delta);
|
63
|
67
|
}
|
|
@@ -73,6 +77,13 @@ class NotusDocument {
|
73
|
77
|
|
74
|
78
|
NotusHistory get history => _history;
|
75
|
79
|
|
|
80
|
+ NotusSearch _searchController;
|
|
81
|
+
|
|
82
|
+ set searchController(NotusSearch value) {
|
|
83
|
+ _searchController = value;
|
|
84
|
+ }
|
|
85
|
+ NotusSearch get searchController => _searchController;
|
|
86
|
+
|
76
|
87
|
/// The root node of this document tree.
|
77
|
88
|
RootNode get root => _root;
|
78
|
89
|
final RootNode _root = RootNode();
|
|
@@ -172,7 +183,7 @@ class NotusDocument {
|
172
|
183
|
/// Returns an instance of [Delta] actually composed into this document.
|
173
|
184
|
/// The returned [Delta] may be empty in which case this document remains
|
174
|
185
|
/// unchanged and no [NotusChange] is published to [changes] stream.
|
175
|
|
- Delta format(int index, int length, NotusAttribute attribute) {
|
|
186
|
+ Delta format(int index, int length, NotusAttribute attribute, {bool search = false}) {
|
176
|
187
|
assert(index >= 0 && length >= 0 && attribute != null);
|
177
|
188
|
|
178
|
189
|
var change = Delta();
|
|
@@ -188,7 +199,7 @@ class NotusDocument {
|
188
|
199
|
final formatChange =
|
189
|
200
|
_heuristics.applyFormatRules(this, index, length, attribute);
|
190
|
201
|
if (formatChange.isNotEmpty) {
|
191
|
|
- compose(formatChange, ChangeSource.local);
|
|
202
|
+ compose(formatChange, ChangeSource.local, search: search);
|
192
|
203
|
change = change.compose(formatChange);
|
193
|
204
|
}
|
194
|
205
|
|
|
@@ -230,7 +241,7 @@ class NotusDocument {
|
230
|
241
|
/// of this document.
|
231
|
242
|
///
|
232
|
243
|
/// In case the [change] is invalid, behavior of this method is unspecified.
|
233
|
|
- void compose(Delta change, ChangeSource source, {bool history}) {
|
|
244
|
+ void compose(Delta change, ChangeSource source, {bool history, bool search}) {
|
234
|
245
|
_checkMutable();
|
235
|
246
|
change.trim();
|
236
|
247
|
assert(change.isNotEmpty);
|
|
@@ -258,7 +269,8 @@ class NotusDocument {
|
258
|
269
|
// _controller.add(NotusChange(before, change, source));
|
259
|
270
|
final notusChange = NotusChange(before, change, source);
|
260
|
271
|
_controller.add(notusChange);
|
261
|
|
- if (history != true) _history?.handleDocChange(notusChange);
|
|
272
|
+ if (history != true && search != true) _history?.handleDocChange(notusChange);
|
|
273
|
+ if (search != true) _searchController = NotusSearch(_delta);
|
262
|
274
|
}
|
263
|
275
|
|
264
|
276
|
//
|
|
@@ -311,6 +323,10 @@ class NotusDocument {
|
311
|
323
|
}
|
312
|
324
|
}
|
313
|
325
|
|
|
326
|
+ void search(String text) {
|
|
327
|
+ _searchController.search(this, text);
|
|
328
|
+ }
|
|
329
|
+
|
314
|
330
|
Delta undo() {
|
315
|
331
|
return _history?.undo(this);
|
316
|
332
|
}
|