@difizen/libro-search-code-cell 0.1.14 → 0.1.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"code-cell-search-provider.d.ts","sourceRoot":"","sources":["../src/code-cell-search-provider.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,KAAK,EAAE,qBAAqB,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAClF,OAAO,EAAE,4BAA4B,EAAE,MAAM,uBAAuB,CAAC;AAGrE,OAAO,EACL,oBAAoB,EACpB,kCAAkC,EACnC,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,4BAA4B,EAAE,MAAM,uCAAuC,CAAC;AAErF,qBACa,sBAAuB,SAAQ,4BAA4B;IACtE,SAAS,CAAC,4BAA4B,EAAE,4BAA4B,CAAC;IAC7D,SAAS,CAAC,eAAe,EAAE,qBAAqB,EAAE,CAAC;IACnD,SAAS,CAAC,oBAAoB,EAAE,MAAM,CAAC;IAC/C;;;;OAIG;gBAGD,kBAAkB,EAAE,kCAAkC,EAEtD,4BAA4B,EAAE,4BAA4B,EAC5B,MAAM,EAAE,oBAAoB;IAuB5D;;OAEG;IACH,IAAa,YAAY,IAAI,MAAM,CAYlC;IAED;;OAEG;IACY,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC;IAO9C;;OAEG;IACM,OAAO,IAAI,IAAI;IAWxB;;;;OAIG;IACY,aAAa,IAAI,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC;IAqChE;;;;OAIG;IACY,iBAAiB,IAAI,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC;IAqCpE;;;;;;OAMG;IACY,UAAU,CACvB,KAAK,EAAE,MAAM,GAAG,IAAI,EACpB,OAAO,CAAC,EAAE,aAAa,GACtB,OAAO,CAAC,IAAI,CAAC;IAYD,QAAQ,IAAI,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AC,mBAAmB,sBAc3B;CACH"}
@@ -56,11 +56,15 @@ export var CodeCellSearchProvider = (_dec = transient(), _dec2 = prop(), _dec3 =
56
56
  view: output
57
57
  });
58
58
  });
59
- if (_this.isActive && _this.query && ((_this$filters = _this.filters) === null || _this$filters === void 0 ? void 0 : _this$filters.searchCellOutput) !== false) {
60
- _this.refresh();
59
+ if (!(_this.isActive && _this.query && ((_this$filters = _this.filters) === null || _this$filters === void 0 ? void 0 : _this$filters.searchCellOutput) !== false)) {
60
+ _context.next = 7;
61
+ break;
61
62
  }
63
+ _context.next = 7;
64
+ return _this.refresh();
65
+ case 7:
62
66
  _this.stateChangedEmitter.fire();
63
- case 6:
67
+ case 8:
64
68
  case "end":
65
69
  return _context.stop();
66
70
  }
@@ -70,9 +74,9 @@ export var CodeCellSearchProvider = (_dec = transient(), _dec2 = prop(), _dec3 =
70
74
  _this.currentProviderIndex = -1;
71
75
  _this.outputsProvider = [];
72
76
  _this.setupOutputProvider();
73
- _this.cell.outputArea.onUpdate(function () {
77
+ _this.toDispose.push(_this.cell.outputArea.onUpdate(function () {
74
78
  _this.setupOutputProvider();
75
- });
79
+ }));
76
80
  _this.toDispose.push(watch(_this.cell.model, 'hasOutputHidden', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
77
81
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
78
82
  while (1) switch (_context2.prev = _context2.next) {
@@ -11,7 +11,7 @@ import { CodeEditorSearchHighlighterFactory } from './code-cell-search-protocol.
11
11
  export declare class CodeEditorCellSearchProvider implements BaseSearchProvider {
12
12
  protected toDispose: DisposableCollection;
13
13
  /**
14
- * CodeMirror search highlighter
14
+ * code editor search highlighter
15
15
  */
16
16
  protected editorHighlighter: CodeEditorSearchHighlighter;
17
17
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"code-editor-cell-search-provider.d.ts","sourceRoot":"","sources":["../src/code-editor-cell-search-provider.ts"],"names":[],"mappings":"AAAA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,IAAI,KAAK,CAAC,IAAI,CAAC,CAE9B;IAED;;OAEG;IACH,IAAI,iBAAiB,IAAI,MAAM,GAAG,SAAS,CAE1C;IAED;;;;OAIG;IACH,IAAI,QAAQ,IAAI,OAAO,CAEtB;IAED;;OAEG;IACH,IAAI,UAAU,IAAI,OAAO,CAExB;IAED;;OAEG;IACH,IAAI,YAAY,IAAI,MAAM,CAEzB;IAED,IAAI,cAAc,IAAI,OAAO,CAE5B;IAED;;OAEG;IACH,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC;IAO/B;;OAEG;IACH,OAAO,IAAI,IAAI;IAaf;;;;;;;OAOG;IACG,WAAW,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAa5C;;;;;;OAMG;IACG,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;IAW9E;;OAEG;IACG,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAM/B;;;;OAIG;IACG,aAAa,IAAI,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC;IAuBvD;;;;OAIG;IACG,iBAAiB,IAAI,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC;IAiB3D;;;;;;;OAOG;IACH,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAoCtD;;;;;OAKG;IACH,iBAAiB,YAAa,MAAM,KAAG,QAAQ,OAAO,CAAC,CA+BrD;IAEF;;;;OAIG;IACH,SAAS,CAAC,eAAe,IAAI,WAAW,GAAG,SAAS;IAYpD,SAAS,CAAC,aAAa,sBAgBrB;CACH"}
1
+ {"version":3,"file":"code-editor-cell-search-provider.d.ts","sourceRoot":"","sources":["../src/code-editor-cell-search-provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,KAAK,EAAE,S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M,GAAG,SAAS,CAE1C;IAED;;;;OAIG;IACH,IAAI,QAAQ,IAAI,OAAO,CAEtB;IAED;;OAEG;IACH,IAAI,UAAU,IAAI,OAAO,CAExB;IAED;;OAEG;IACH,IAAI,YAAY,IAAI,MAAM,CAEzB;IAED,IAAI,cAAc,IAAI,OAAO,CAE5B;IAED;;OAEG;IACH,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC;IAO/B;;OAEG;IACH,OAAO,IAAI,IAAI;IAaf;;;;;;;OAOG;IACG,WAAW,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAa5C;;;;;;OAMG;IACG,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;IAW9E;;OAEG;IACG,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAM/B;;;;OAIG;IACG,aAAa,IAAI,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC;IAuBvD;;;;OAIG;IACG,iBAAiB,IAAI,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC;IAiB3D;;;;;;;OAOG;IACH,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAoCtD;;;;;OAKG;IACH,iBAAiB,YAAa,MAAM,KAAG,QAAQ,OAAO,CAAC,CA+BrD;IAEF;;;;OAIG;IACH,SAAS,CAAC,eAAe,IAAI,WAAW,GAAG,SAAS;IAYpD,SAAS,CAAC,aAAa,sBAwBrB;CACH"}
@@ -12,6 +12,7 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
12
12
  function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { var desc = {}; Object.keys(descriptor).forEach(function (key) { desc[key] = descriptor[key]; }); desc.enumerable = !!desc.enumerable; desc.configurable = !!desc.configurable; if ('value' in desc || desc.initializer) { desc.writable = true; } desc = decorators.slice().reverse().reduce(function (desc, decorator) { return decorator(target, property, desc) || desc; }, desc); if (context && desc.initializer !== void 0) { desc.value = desc.initializer ? desc.initializer.call(context) : void 0; desc.initializer = undefined; } if (desc.initializer === void 0) { Object.defineProperty(target, property, desc); desc = null; } return desc; }
13
13
  function _initializerWarningHelper(descriptor, context) { throw new Error('Decorating class property failed. Please ensure that ' + 'transform-class-properties is enabled and runs after the decorators transform.'); }
14
14
  import { searchText } from '@difizen/libro-search';
15
+ import { Disposable } from '@difizen/mana-app';
15
16
  import { prop } from '@difizen/mana-app';
16
17
  import { DisposableCollection, Emitter } from '@difizen/mana-app';
17
18
  import { watch } from '@difizen/mana-app';
@@ -27,11 +28,13 @@ export var CodeEditorCellSearchProvider = (_dec = transient(), _dec2 = prop(), _
27
28
  * @param cell Cell widget
28
29
  */
29
30
  function CodeEditorCellSearchProvider(highlighterFactory, cell) {
30
- var _this = this;
31
+ var _this = this,
32
+ _this$cell$editorView,
33
+ _this$cell$editorView2;
31
34
  _classCallCheck(this, CodeEditorCellSearchProvider);
32
35
  this.toDispose = new DisposableCollection();
33
36
  /**
34
- * CodeMirror search highlighter
37
+ * code editor search highlighter
35
38
  */
36
39
  _initializerDefineProperty(this, "editorHighlighter", _descriptor, this);
37
40
  /**
@@ -89,16 +92,16 @@ export var CodeEditorCellSearchProvider = (_dec = transient(), _dec2 = prop(), _
89
92
  return Promise.resolve(occurred);
90
93
  };
91
94
  this.updateMatches = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
92
- var matches, _this$cell$editor$get, _this$cell$editor, cursorOffset, index;
95
+ var matches, _this$cell$editor, _this$cell$editor$get, _this$cell$editor2, cursorOffset, index;
93
96
  return _regeneratorRuntime().wrap(function _callee$(_context) {
94
97
  while (1) switch (_context.prev = _context.next) {
95
98
  case 0:
96
99
  if (!(_this.query !== null)) {
97
- _context.next = 10;
100
+ _context.next = 15;
98
101
  break;
99
102
  }
100
103
  if (!_this.isActive) {
101
- _context.next = 9;
104
+ _context.next = 14;
102
105
  break;
103
106
  }
104
107
  _context.next = 4;
@@ -106,21 +109,33 @@ export var CodeEditorCellSearchProvider = (_dec = transient(), _dec2 = prop(), _
106
109
  case 4:
107
110
  matches = _context.sent;
108
111
  _this.editorHighlighter.matches = matches;
109
- if (_this.isCellSelected) {
110
- cursorOffset = _this.cell.editor.getOffsetAt((_this$cell$editor$get = (_this$cell$editor = _this.cell.editor) === null || _this$cell$editor === void 0 ? void 0 : _this$cell$editor.getCursorPosition()) !== null && _this$cell$editor$get !== void 0 ? _this$cell$editor$get : {
111
- column: 0,
112
- line: 0
113
- });
114
- index = matches.findIndex(function (item) {
115
- return item.position >= cursorOffset;
116
- });
112
+ if (!_this.isCellSelected) {
113
+ _context.next = 12;
114
+ break;
115
+ }
116
+ cursorOffset = (_this$cell$editor = _this.cell.editor) === null || _this$cell$editor === void 0 ? void 0 : _this$cell$editor.getOffsetAt((_this$cell$editor$get = (_this$cell$editor2 = _this.cell.editor) === null || _this$cell$editor2 === void 0 ? void 0 : _this$cell$editor2.getCursorPosition()) !== null && _this$cell$editor$get !== void 0 ? _this$cell$editor$get : {
117
+ column: 0,
118
+ line: 0
119
+ });
120
+ if (!(cursorOffset === undefined)) {
121
+ _context.next = 10;
122
+ break;
123
+ }
124
+ return _context.abrupt("return");
125
+ case 10:
126
+ index = matches.findIndex(function (item) {
127
+ return item.position + item.text.length >= cursorOffset;
128
+ });
129
+ if (index >= 0) {
117
130
  _this.currentIndex = index;
131
+ _this.editorHighlighter.currentIndex = index;
118
132
  }
119
- _context.next = 10;
133
+ case 12:
134
+ _context.next = 15;
120
135
  break;
121
- case 9:
136
+ case 14:
122
137
  _this.editorHighlighter.matches = [];
123
- case 10:
138
+ case 15:
124
139
  case "end":
125
140
  return _context.stop();
126
141
  }
@@ -133,24 +148,22 @@ export var CodeEditorCellSearchProvider = (_dec = transient(), _dec2 = prop(), _
133
148
  this.toDispose.push(this.stateChangedEmitter);
134
149
  this.editorHighlighter = this.highlighterFactory(this.cell.editor);
135
150
  this.toDispose.push(watch(this.cell.model, 'value', this.updateMatches));
136
- this.toDispose.push(watch(this.cell, 'editor', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
137
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
138
- while (1) switch (_context2.prev = _context2.next) {
139
- case 0:
140
- _context2.next = 2;
141
- return _this.cell.editorReady;
142
- case 2:
143
- if (_this.cell.hasInputHidden === true) {
144
- _this.endQuery();
145
- } else {
146
- _this.startQuery(_this.query, _this.filters);
147
- }
148
- case 3:
149
- case "end":
150
- return _context2.stop();
151
+ this.toDispose.push((_this$cell$editorView = (_this$cell$editorView2 = this.cell.editorView) === null || _this$cell$editorView2 === void 0 ? void 0 : _this$cell$editorView2.onEditorStatusChange(function (e) {
152
+ if (e.status === 'ready') {
153
+ var _this$cell$editorView3;
154
+ var editor = (_this$cell$editorView3 = _this.cell.editorView) === null || _this$cell$editorView3 === void 0 ? void 0 : _this$cell$editorView3.editor;
155
+ if (editor) {
156
+ _this.editorHighlighter.setEditor(editor);
157
+ }
158
+ if (e.prevState === 'init') {
159
+ if (_this.cell.hasInputHidden === true) {
160
+ _this.endQuery();
161
+ } else {
162
+ _this.startQuery(_this.query, _this.filters);
163
+ }
151
164
  }
152
- }, _callee2);
153
- }))));
165
+ }
166
+ })) !== null && _this$cell$editorView !== void 0 ? _this$cell$editorView : Disposable.NONE);
154
167
  }
155
168
 
156
169
  /**
@@ -176,21 +189,19 @@ export var CodeEditorCellSearchProvider = (_dec = transient(), _dec2 = prop(), _
176
189
  }, {
177
190
  key: "setEditor",
178
191
  value: function () {
179
- var _setEditor = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
180
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
181
- while (1) switch (_context3.prev = _context3.next) {
192
+ var _setEditor = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
193
+ var _this$cell$editorView4;
194
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
195
+ while (1) switch (_context2.prev = _context2.next) {
182
196
  case 0:
183
- _context3.next = 2;
184
- return this.cell.editorReady;
185
- case 2:
186
- if (this.cell.editor) {
197
+ if (this.cell.editor && ((_this$cell$editorView4 = this.cell.editorView) === null || _this$cell$editorView4 === void 0 ? void 0 : _this$cell$editorView4.editorStatus) === 'ready') {
187
198
  this.editorHighlighter.setEditor(this.cell.editor);
188
199
  }
189
- case 3:
200
+ case 1:
190
201
  case "end":
191
- return _context3.stop();
202
+ return _context2.stop();
192
203
  }
193
- }, _callee3, this);
204
+ }, _callee2, this);
194
205
  }));
195
206
  function setEditor() {
196
207
  return _setEditor.apply(this, arguments);
@@ -289,34 +300,34 @@ export var CodeEditorCellSearchProvider = (_dec = transient(), _dec2 = prop(), _
289
300
  }, {
290
301
  key: "setIsActive",
291
302
  value: (function () {
292
- var _setIsActive = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(v) {
293
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
294
- while (1) switch (_context4.prev = _context4.next) {
303
+ var _setIsActive = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(v) {
304
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
305
+ while (1) switch (_context3.prev = _context3.next) {
295
306
  case 0:
296
307
  if (this.isActive !== v) {
297
308
  this._isActive = v;
298
309
  }
299
310
  if (!this.isActive) {
300
- _context4.next = 7;
311
+ _context3.next = 7;
301
312
  break;
302
313
  }
303
314
  if (!(this.query !== null)) {
304
- _context4.next = 5;
315
+ _context3.next = 5;
305
316
  break;
306
317
  }
307
- _context4.next = 5;
318
+ _context3.next = 5;
308
319
  return this.startQuery(this.query, this.filters);
309
320
  case 5:
310
- _context4.next = 9;
321
+ _context3.next = 9;
311
322
  break;
312
323
  case 7:
313
- _context4.next = 9;
324
+ _context3.next = 9;
314
325
  return this.endQuery();
315
326
  case 9:
316
327
  case "end":
317
- return _context4.stop();
328
+ return _context3.stop();
318
329
  }
319
- }, _callee4, this);
330
+ }, _callee3, this);
320
331
  }));
321
332
  function setIsActive(_x) {
322
333
  return _setIsActive.apply(this, arguments);
@@ -334,28 +345,28 @@ export var CodeEditorCellSearchProvider = (_dec = transient(), _dec2 = prop(), _
334
345
  }, {
335
346
  key: "startQuery",
336
347
  value: (function () {
337
- var _startQuery = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(query, filters) {
338
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
339
- while (1) switch (_context5.prev = _context5.next) {
348
+ var _startQuery = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(query, filters) {
349
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
350
+ while (1) switch (_context4.prev = _context4.next) {
340
351
  case 0:
341
352
  this.query = query;
342
353
  this.filters = filters;
343
354
  if (!this.cell.hasInputHidden) {
344
- _context5.next = 4;
355
+ _context4.next = 4;
345
356
  break;
346
357
  }
347
- return _context5.abrupt("return");
358
+ return _context4.abrupt("return");
348
359
  case 4:
349
- _context5.next = 6;
360
+ _context4.next = 6;
350
361
  return this.setEditor();
351
362
  case 6:
352
- _context5.next = 8;
363
+ _context4.next = 8;
353
364
  return this.updateMatches();
354
365
  case 8:
355
366
  case "end":
356
- return _context5.stop();
367
+ return _context4.stop();
357
368
  }
358
- }, _callee5, this);
369
+ }, _callee4, this);
359
370
  }));
360
371
  function startQuery(_x2, _x3) {
361
372
  return _startQuery.apply(this, arguments);
@@ -369,19 +380,19 @@ export var CodeEditorCellSearchProvider = (_dec = transient(), _dec2 = prop(), _
369
380
  }, {
370
381
  key: "endQuery",
371
382
  value: (function () {
372
- var _endQuery = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
373
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
374
- while (1) switch (_context6.prev = _context6.next) {
383
+ var _endQuery = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
384
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
385
+ while (1) switch (_context5.prev = _context5.next) {
375
386
  case 0:
376
387
  this.currentIndex = undefined;
377
388
  this.query = null;
378
- _context6.next = 4;
389
+ _context5.next = 4;
379
390
  return this.editorHighlighter.endQuery();
380
391
  case 4:
381
392
  case "end":
382
- return _context6.stop();
393
+ return _context5.stop();
383
394
  }
384
- }, _callee6, this);
395
+ }, _callee5, this);
385
396
  }));
386
397
  function endQuery() {
387
398
  return _endQuery.apply(this, arguments);
@@ -397,42 +408,42 @@ export var CodeEditorCellSearchProvider = (_dec = transient(), _dec2 = prop(), _
397
408
  }, {
398
409
  key: "highlightNext",
399
410
  value: (function () {
400
- var _highlightNext = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
401
- var _this$cell$editor2, match;
402
- return _regeneratorRuntime().wrap(function _callee7$(_context7) {
403
- while (1) switch (_context7.prev = _context7.next) {
411
+ var _highlightNext = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
412
+ var _this$cell$editor3, match;
413
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
414
+ while (1) switch (_context6.prev = _context6.next) {
404
415
  case 0:
405
416
  if (!(this.matchesCount === 0 || !this.isActive)) {
406
- _context7.next = 4;
417
+ _context6.next = 4;
407
418
  break;
408
419
  }
409
420
  this.currentIndex = undefined;
410
- _context7.next = 10;
421
+ _context6.next = 10;
411
422
  break;
412
423
  case 4:
413
424
  if (this.lastReplacementPosition) {
414
- (_this$cell$editor2 = this.cell.editor) === null || _this$cell$editor2 === void 0 || _this$cell$editor2.setCursorPosition(this.lastReplacementPosition);
425
+ (_this$cell$editor3 = this.cell.editor) === null || _this$cell$editor3 === void 0 || _this$cell$editor3.setCursorPosition(this.lastReplacementPosition);
415
426
  this.lastReplacementPosition = null;
416
427
  }
417
428
 
418
429
  // This starts from the cursor position
419
- _context7.next = 7;
430
+ _context6.next = 7;
420
431
  return this.editorHighlighter.highlightNext();
421
432
  case 7:
422
- match = _context7.sent;
433
+ match = _context6.sent;
423
434
  if (match) {
424
435
  this.currentIndex = this.editorHighlighter.currentIndex;
425
436
  } else {
426
437
  this.currentIndex = undefined;
427
438
  }
428
- return _context7.abrupt("return", match);
439
+ return _context6.abrupt("return", match);
429
440
  case 10:
430
- return _context7.abrupt("return", Promise.resolve(this.getCurrentMatch()));
441
+ return _context6.abrupt("return", Promise.resolve(this.getCurrentMatch()));
431
442
  case 11:
432
443
  case "end":
433
- return _context7.stop();
444
+ return _context6.stop();
434
445
  }
435
- }, _callee7, this);
446
+ }, _callee6, this);
436
447
  }));
437
448
  function highlightNext() {
438
449
  return _highlightNext.apply(this, arguments);
@@ -448,36 +459,36 @@ export var CodeEditorCellSearchProvider = (_dec = transient(), _dec2 = prop(), _
448
459
  }, {
449
460
  key: "highlightPrevious",
450
461
  value: (function () {
451
- var _highlightPrevious = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
462
+ var _highlightPrevious = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
452
463
  var match;
453
- return _regeneratorRuntime().wrap(function _callee8$(_context8) {
454
- while (1) switch (_context8.prev = _context8.next) {
464
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
465
+ while (1) switch (_context7.prev = _context7.next) {
455
466
  case 0:
456
467
  if (!(this.matchesCount === 0 || !this.isActive)) {
457
- _context8.next = 4;
468
+ _context7.next = 4;
458
469
  break;
459
470
  }
460
471
  this.currentIndex = undefined;
461
- _context8.next = 9;
472
+ _context7.next = 9;
462
473
  break;
463
474
  case 4:
464
- _context8.next = 6;
475
+ _context7.next = 6;
465
476
  return this.editorHighlighter.highlightPrevious();
466
477
  case 6:
467
- match = _context8.sent;
478
+ match = _context7.sent;
468
479
  if (match) {
469
480
  this.currentIndex = this.editorHighlighter.currentIndex;
470
481
  } else {
471
482
  this.currentIndex = undefined;
472
483
  }
473
- return _context8.abrupt("return", match);
484
+ return _context7.abrupt("return", match);
474
485
  case 9:
475
- return _context8.abrupt("return", Promise.resolve(this.getCurrentMatch()));
486
+ return _context7.abrupt("return", Promise.resolve(this.getCurrentMatch()));
476
487
  case 10:
477
488
  case "end":
478
- return _context8.stop();
489
+ return _context7.stop();
479
490
  }
480
- }, _callee8, this);
491
+ }, _callee7, this);
481
492
  }));
482
493
  function highlightPrevious() {
483
494
  return _highlightPrevious.apply(this, arguments);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@difizen/libro-search-code-cell",
3
- "version": "0.1.14",
3
+ "version": "0.1.16",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "libro",
@@ -32,14 +32,14 @@
32
32
  "src"
33
33
  ],
34
34
  "dependencies": {
35
- "@difizen/libro-common": "^0.1.14",
36
- "@difizen/libro-code-editor": "^0.1.14",
37
- "@difizen/libro-code-cell": "^0.1.14",
38
- "@difizen/libro-search": "^0.1.14",
39
- "@difizen/libro-core": "^0.1.14",
35
+ "@difizen/libro-common": "^0.1.16",
36
+ "@difizen/libro-code-editor": "^0.1.16",
37
+ "@difizen/libro-code-cell": "^0.1.16",
38
+ "@difizen/libro-search": "^0.1.16",
39
+ "@difizen/libro-core": "^0.1.16",
40
40
  "@difizen/mana-app": "latest",
41
- "@codemirror/state": "^6.0.0",
42
- "@codemirror/view": "^6.2.2"
41
+ "@codemirror/state": "^6.4.0",
42
+ "@codemirror/view": "^6.23.0"
43
43
  },
44
44
  "scripts": {
45
45
  "setup": "father build",
@@ -33,9 +33,11 @@ export class CodeCellSearchProvider extends CodeEditorCellSearchProvider {
33
33
  this.currentProviderIndex = -1;
34
34
  this.outputsProvider = [];
35
35
  this.setupOutputProvider();
36
- this.cell.outputArea.onUpdate(() => {
37
- this.setupOutputProvider();
38
- });
36
+ this.toDispose.push(
37
+ this.cell.outputArea.onUpdate(() => {
38
+ this.setupOutputProvider();
39
+ }),
40
+ );
39
41
 
40
42
  this.toDispose.push(
41
43
  watch(this.cell.model, 'hasOutputHidden', async () => {
@@ -220,7 +222,7 @@ export class CodeCellSearchProvider extends CodeEditorCellSearchProvider {
220
222
  return this.genericSearchProviderFactory({ view: output });
221
223
  });
222
224
  if (this.isActive && this.query && this.filters?.searchCellOutput !== false) {
223
- this.refresh();
225
+ await this.refresh();
224
226
  }
225
227
  this.stateChangedEmitter.fire();
226
228
  };
@@ -3,6 +3,7 @@ import type { IPosition, SearchMatch } from '@difizen/libro-code-editor';
3
3
  import type { BaseSearchProvider, SearchFilters } from '@difizen/libro-search';
4
4
  import { searchText } from '@difizen/libro-search';
5
5
  import type { Event } from '@difizen/mana-app';
6
+ import { Disposable } from '@difizen/mana-app';
6
7
  import { prop } from '@difizen/mana-app';
7
8
  import { DisposableCollection, Emitter } from '@difizen/mana-app';
8
9
  import { watch } from '@difizen/mana-app';
@@ -17,7 +18,7 @@ import { CodeEditorSearchHighlighterFactory } from './code-cell-search-protocol.
17
18
  export class CodeEditorCellSearchProvider implements BaseSearchProvider {
18
19
  protected toDispose = new DisposableCollection();
19
20
  /**
20
- * CodeMirror search highlighter
21
+ * code editor search highlighter
21
22
  */
22
23
  @prop() protected editorHighlighter: CodeEditorSearchHighlighter;
23
24
  /**
@@ -58,14 +59,21 @@ export class CodeEditorCellSearchProvider implements BaseSearchProvider {
58
59
 
59
60
  this.toDispose.push(watch(this.cell.model, 'value', this.updateMatches));
60
61
  this.toDispose.push(
61
- watch(this.cell, 'editor', async () => {
62
- await this.cell.editorReady;
63
- if (this.cell.hasInputHidden === true) {
64
- this.endQuery();
65
- } else {
66
- this.startQuery(this.query, this.filters);
62
+ this.cell.editorView?.onEditorStatusChange((e) => {
63
+ if (e.status === 'ready') {
64
+ const editor = this.cell.editorView?.editor;
65
+ if (editor) {
66
+ this.editorHighlighter.setEditor(editor);
67
+ }
68
+ if (e.prevState === 'init') {
69
+ if (this.cell.hasInputHidden === true) {
70
+ this.endQuery();
71
+ } else {
72
+ this.startQuery(this.query, this.filters);
73
+ }
74
+ }
67
75
  }
68
- }),
76
+ }) ?? Disposable.NONE,
69
77
  );
70
78
  }
71
79
 
@@ -86,8 +94,7 @@ export class CodeEditorCellSearchProvider implements BaseSearchProvider {
86
94
  }
87
95
 
88
96
  protected async setEditor() {
89
- await this.cell.editorReady;
90
- if (this.cell.editor) {
97
+ if (this.cell.editor && this.cell.editorView?.editorStatus === 'ready') {
91
98
  this.editorHighlighter.setEditor(this.cell.editor);
92
99
  }
93
100
  }
@@ -363,11 +370,19 @@ export class CodeEditorCellSearchProvider implements BaseSearchProvider {
363
370
  const matches = await searchText(this.query, this.cell.model.value);
364
371
  this.editorHighlighter.matches = matches;
365
372
  if (this.isCellSelected) {
366
- const cursorOffset = this.cell.editor!.getOffsetAt(
373
+ const cursorOffset = this.cell.editor?.getOffsetAt(
367
374
  this.cell.editor?.getCursorPosition() ?? { column: 0, line: 0 },
368
375
  );
369
- const index = matches.findIndex((item) => item.position >= cursorOffset);
370
- this.currentIndex = index;
376
+ if (cursorOffset === undefined) {
377
+ return;
378
+ }
379
+ const index = matches.findIndex(
380
+ (item) => item.position + item.text.length >= cursorOffset,
381
+ );
382
+ if (index >= 0) {
383
+ this.currentIndex = index;
384
+ this.editorHighlighter.currentIndex = index;
385
+ }
371
386
  }
372
387
  } else {
373
388
  this.editorHighlighter.matches = [];