@univerjs/docs-find-replace 1.0.0-insiders.20260728-e98f416 → 1.0.0-insiders.20260729-84ae2bd

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.
package/lib/cjs/index.js CHANGED
@@ -9,7 +9,7 @@ let rxjs = require("rxjs");
9
9
 
10
10
  //#region package.json
11
11
  var name = "@univerjs/docs-find-replace";
12
- var version = "1.0.0-insiders.20260728-e98f416";
12
+ var version = "1.0.0-insiders.20260729-84ae2bd";
13
13
 
14
14
  //#endregion
15
15
  //#region src/config/config.ts
@@ -34,23 +34,32 @@ const defaultPluginConfig = {};
34
34
 
35
35
  //#endregion
36
36
  //#region src/controllers/utils.ts
37
- function findDocRanges(body, query, disabled) {
37
+ function findDocRanges(body, query, disabled, resolved = {
38
+ text: body.dataStream,
39
+ characters: Array.from({ length: body.dataStream.length }, (_value, index) => ({
40
+ startOffset: index,
41
+ endOffset: index + 1,
42
+ replaceable: true
43
+ }))
44
+ }) {
38
45
  if (!query.findString) return [];
39
46
  const expression = _univerjs_core.regexp.createLiteralRegExp(query.findString, query.caseSensitive ? "gu" : "giu");
40
- const wordRanges = query.matchesTheWholeWord ? new Set(Array.from(new Intl.Segmenter(void 0, { granularity: "word" }).segment(body.dataStream)).filter((item) => item.isWordLike).map((item) => `${item.index}:${item.index + item.segment.length}`)) : null;
41
- return Array.from(body.dataStream.matchAll(expression)).filter((match) => {
47
+ const wordRanges = query.matchesTheWholeWord ? new Set(Array.from(new Intl.Segmenter(void 0, { granularity: "word" }).segment(resolved.text)).filter((item) => item.isWordLike).map((item) => `${item.index}:${item.index + item.segment.length}`)) : null;
48
+ return Array.from(resolved.text.matchAll(expression)).filter((match) => {
42
49
  var _wordRanges$has;
43
50
  return (_wordRanges$has = wordRanges === null || wordRanges === void 0 ? void 0 : wordRanges.has(`${match.index}:${match.index + match[0].length}`)) !== null && _wordRanges$has !== void 0 ? _wordRanges$has : true;
44
- }).map((match) => {
51
+ }).flatMap((match) => {
45
52
  var _body$customRanges$so, _body$customRanges;
46
- const startOffset = match.index;
47
- const endOffset = startOffset + match[0].length;
53
+ const characters = resolved.characters.slice(match.index, match.index + match[0].length);
54
+ if (!characters.length) return [];
55
+ const startOffset = Math.min(...characters.map((character) => character.startOffset));
56
+ const endOffset = Math.max(...characters.map((character) => character.endOffset));
48
57
  const overlapsWholeEntity = (_body$customRanges$so = (_body$customRanges = body.customRanges) === null || _body$customRanges === void 0 ? void 0 : _body$customRanges.some((range) => range.wholeEntity && range.startIndex < endOffset && range.endIndex + 1 > startOffset)) !== null && _body$customRanges$so !== void 0 ? _body$customRanges$so : false;
49
- return {
58
+ return [{
50
59
  startOffset,
51
60
  endOffset,
52
- replaceable: !disabled && !overlapsWholeEntity
53
- };
61
+ replaceable: !disabled && !overlapsWholeEntity && characters.every((character) => character.replaceable)
62
+ }];
54
63
  });
55
64
  }
56
65
 
@@ -203,7 +212,7 @@ function __decorate(decorators, target, key, desc) {
203
212
  //#region src/models/docs-find.model.ts
204
213
  const DOCS_FIND_REPLACE_PROVIDER = "docs-find-replace-provider";
205
214
  let DocsFindModel = class DocsFindModel extends _univerjs_find_replace.FindModel {
206
- constructor(_doc, _skeletonManager, _selectionManager, _renderManagerService, _commandService, _themeService) {
215
+ constructor(_doc, _skeletonManager, _selectionManager, _renderManagerService, _commandService, _themeService, _textResolverService) {
207
216
  super();
208
217
  this._doc = _doc;
209
218
  this._skeletonManager = _skeletonManager;
@@ -211,6 +220,7 @@ let DocsFindModel = class DocsFindModel extends _univerjs_find_replace.FindModel
211
220
  this._renderManagerService = _renderManagerService;
212
221
  this._commandService = _commandService;
213
222
  this._themeService = _themeService;
223
+ this._textResolverService = _textResolverService;
214
224
  _defineProperty(this, "_matchesUpdate$", new rxjs.Subject());
215
225
  _defineProperty(this, "matchesUpdate$", this._matchesUpdate$.asObservable());
216
226
  _defineProperty(this, "_activelyChangingMatch$", new rxjs.Subject());
@@ -221,10 +231,7 @@ let DocsFindModel = class DocsFindModel extends _univerjs_find_replace.FindModel
221
231
  _defineProperty(this, "_highlights", []);
222
232
  _defineProperty(this, "unitId", void 0);
223
233
  this.unitId = _doc.getUnitId();
224
- this.disposeWithMe((0, _univerjs_core.toDisposable)((0, _univerjs_core.fromCallback)(this._commandService.onCommandExecuted.bind(this._commandService)).pipe((0, rxjs.filter)(([command]) => {
225
- var _command$params;
226
- return command.id === _univerjs_docs.RichTextEditingMutation.id && ((_command$params = command.params) === null || _command$params === void 0 ? void 0 : _command$params.unitId) === this.unitId;
227
- }), (0, rxjs.debounceTime)(220)).subscribe(() => this._scan(true))));
234
+ this.disposeWithMe((0, _univerjs_core.toDisposable)((0, rxjs.merge)((0, _univerjs_core.fromCallback)(this._commandService.onCommandExecuted.bind(this._commandService)).pipe((0, rxjs.filter)(([command]) => command.id === _univerjs_docs.RichTextEditingMutation.id && getUnitId(command.params) === this.unitId)), this._textResolverService.textChanged$.pipe((0, rxjs.filter)((unitId) => unitId === this.unitId))).pipe((0, rxjs.debounceTime)(220)).subscribe(() => this._scan(true))));
228
235
  this.disposeWithMe((0, _univerjs_core.toDisposable)(this._skeletonManager.currentSkeleton$.subscribe(() => this._refreshHighlights())));
229
236
  }
230
237
  get currentMatch() {
@@ -330,7 +337,7 @@ let DocsFindModel = class DocsFindModel extends _univerjs_find_replace.FindModel
330
337
  return;
331
338
  }
332
339
  const previousStart = (_this$currentMatch = this.currentMatch) === null || _this$currentMatch === void 0 ? void 0 : _this$currentMatch.range.startOffset;
333
- this._matches = findDocRanges(body, this._query, !!this._doc.getSnapshot().disabled).map((range) => ({
340
+ this._matches = findDocRanges(body, this._query, !!this._doc.getSnapshot().disabled, this._textResolverService.resolve(this.unitId, body)).map((range) => ({
334
341
  provider: DOCS_FIND_REPLACE_PROVIDER,
335
342
  unitId: this.unitId,
336
343
  range: {
@@ -397,8 +404,12 @@ DocsFindModel = __decorate([
397
404
  __decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_docs.DocSelectionManagerService)),
398
405
  __decorateParam(3, _univerjs_engine_render.IRenderManagerService),
399
406
  __decorateParam(4, _univerjs_core.ICommandService),
400
- __decorateParam(5, (0, _univerjs_core.Inject)(_univerjs_core.ThemeService))
407
+ __decorateParam(5, (0, _univerjs_core.Inject)(_univerjs_core.ThemeService)),
408
+ __decorateParam(6, (0, _univerjs_core.Inject)(_univerjs_docs.DocTextResolverService))
401
409
  ], DocsFindModel);
410
+ function getUnitId(params) {
411
+ return params != null && typeof params === "object" && "unitId" in params && typeof params.unitId === "string" ? params.unitId : void 0;
412
+ }
402
413
 
403
414
  //#endregion
404
415
  //#region src/services/docs-find-replace.provider.ts
package/lib/es/index.js CHANGED
@@ -1,14 +1,14 @@
1
1
  import { BuildTextUtils, ColorKit, CommandType, DependentOn, Disposable, FOCUSING_DOC, ICommandService, IConfigService, IContextService, IUniverInstanceService, Inject, Injector, JSONX, MemoryCursor, Plugin, TextX, ThemeService, UniverInstanceType, fromCallback, getRichTextEditPath, merge, regexp, toDisposable } from "@univerjs/core";
2
- import { DocSelectionManagerService, DocSkeletonManagerService, RichTextEditingMutation, UniverDocsPlugin } from "@univerjs/docs";
2
+ import { DocSelectionManagerService, DocSkeletonManagerService, DocTextResolverService, RichTextEditingMutation, UniverDocsPlugin } from "@univerjs/docs";
3
3
  import { DocBackScrollRenderController, UniverDocsUIPlugin, getTextRangeFromCharIndex } from "@univerjs/docs-ui";
4
4
  import { IRenderManagerService, UniverRenderEnginePlugin } from "@univerjs/engine-render";
5
5
  import { FindModel, IFindReplaceService, OpenFindDialogOperation, UniverFindReplacePlugin } from "@univerjs/find-replace";
6
6
  import { IMenuManagerService, MenuItemType, RibbonStartGroup } from "@univerjs/ui";
7
- import { Subject, debounceTime, filter, map } from "rxjs";
7
+ import { Subject, debounceTime, filter, map, merge as merge$1 } from "rxjs";
8
8
 
9
9
  //#region package.json
10
10
  var name = "@univerjs/docs-find-replace";
11
- var version = "1.0.0-insiders.20260728-e98f416";
11
+ var version = "1.0.0-insiders.20260729-84ae2bd";
12
12
 
13
13
  //#endregion
14
14
  //#region src/config/config.ts
@@ -33,23 +33,32 @@ const defaultPluginConfig = {};
33
33
 
34
34
  //#endregion
35
35
  //#region src/controllers/utils.ts
36
- function findDocRanges(body, query, disabled) {
36
+ function findDocRanges(body, query, disabled, resolved = {
37
+ text: body.dataStream,
38
+ characters: Array.from({ length: body.dataStream.length }, (_value, index) => ({
39
+ startOffset: index,
40
+ endOffset: index + 1,
41
+ replaceable: true
42
+ }))
43
+ }) {
37
44
  if (!query.findString) return [];
38
45
  const expression = regexp.createLiteralRegExp(query.findString, query.caseSensitive ? "gu" : "giu");
39
- const wordRanges = query.matchesTheWholeWord ? new Set(Array.from(new Intl.Segmenter(void 0, { granularity: "word" }).segment(body.dataStream)).filter((item) => item.isWordLike).map((item) => `${item.index}:${item.index + item.segment.length}`)) : null;
40
- return Array.from(body.dataStream.matchAll(expression)).filter((match) => {
46
+ const wordRanges = query.matchesTheWholeWord ? new Set(Array.from(new Intl.Segmenter(void 0, { granularity: "word" }).segment(resolved.text)).filter((item) => item.isWordLike).map((item) => `${item.index}:${item.index + item.segment.length}`)) : null;
47
+ return Array.from(resolved.text.matchAll(expression)).filter((match) => {
41
48
  var _wordRanges$has;
42
49
  return (_wordRanges$has = wordRanges === null || wordRanges === void 0 ? void 0 : wordRanges.has(`${match.index}:${match.index + match[0].length}`)) !== null && _wordRanges$has !== void 0 ? _wordRanges$has : true;
43
- }).map((match) => {
50
+ }).flatMap((match) => {
44
51
  var _body$customRanges$so, _body$customRanges;
45
- const startOffset = match.index;
46
- const endOffset = startOffset + match[0].length;
52
+ const characters = resolved.characters.slice(match.index, match.index + match[0].length);
53
+ if (!characters.length) return [];
54
+ const startOffset = Math.min(...characters.map((character) => character.startOffset));
55
+ const endOffset = Math.max(...characters.map((character) => character.endOffset));
47
56
  const overlapsWholeEntity = (_body$customRanges$so = (_body$customRanges = body.customRanges) === null || _body$customRanges === void 0 ? void 0 : _body$customRanges.some((range) => range.wholeEntity && range.startIndex < endOffset && range.endIndex + 1 > startOffset)) !== null && _body$customRanges$so !== void 0 ? _body$customRanges$so : false;
48
- return {
57
+ return [{
49
58
  startOffset,
50
59
  endOffset,
51
- replaceable: !disabled && !overlapsWholeEntity
52
- };
60
+ replaceable: !disabled && !overlapsWholeEntity && characters.every((character) => character.replaceable)
61
+ }];
53
62
  });
54
63
  }
55
64
 
@@ -202,7 +211,7 @@ function __decorate(decorators, target, key, desc) {
202
211
  //#region src/models/docs-find.model.ts
203
212
  const DOCS_FIND_REPLACE_PROVIDER = "docs-find-replace-provider";
204
213
  let DocsFindModel = class DocsFindModel extends FindModel {
205
- constructor(_doc, _skeletonManager, _selectionManager, _renderManagerService, _commandService, _themeService) {
214
+ constructor(_doc, _skeletonManager, _selectionManager, _renderManagerService, _commandService, _themeService, _textResolverService) {
206
215
  super();
207
216
  this._doc = _doc;
208
217
  this._skeletonManager = _skeletonManager;
@@ -210,6 +219,7 @@ let DocsFindModel = class DocsFindModel extends FindModel {
210
219
  this._renderManagerService = _renderManagerService;
211
220
  this._commandService = _commandService;
212
221
  this._themeService = _themeService;
222
+ this._textResolverService = _textResolverService;
213
223
  _defineProperty(this, "_matchesUpdate$", new Subject());
214
224
  _defineProperty(this, "matchesUpdate$", this._matchesUpdate$.asObservable());
215
225
  _defineProperty(this, "_activelyChangingMatch$", new Subject());
@@ -220,10 +230,7 @@ let DocsFindModel = class DocsFindModel extends FindModel {
220
230
  _defineProperty(this, "_highlights", []);
221
231
  _defineProperty(this, "unitId", void 0);
222
232
  this.unitId = _doc.getUnitId();
223
- this.disposeWithMe(toDisposable(fromCallback(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(filter(([command]) => {
224
- var _command$params;
225
- return command.id === RichTextEditingMutation.id && ((_command$params = command.params) === null || _command$params === void 0 ? void 0 : _command$params.unitId) === this.unitId;
226
- }), debounceTime(220)).subscribe(() => this._scan(true))));
233
+ this.disposeWithMe(toDisposable(merge$1(fromCallback(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(filter(([command]) => command.id === RichTextEditingMutation.id && getUnitId(command.params) === this.unitId)), this._textResolverService.textChanged$.pipe(filter((unitId) => unitId === this.unitId))).pipe(debounceTime(220)).subscribe(() => this._scan(true))));
227
234
  this.disposeWithMe(toDisposable(this._skeletonManager.currentSkeleton$.subscribe(() => this._refreshHighlights())));
228
235
  }
229
236
  get currentMatch() {
@@ -329,7 +336,7 @@ let DocsFindModel = class DocsFindModel extends FindModel {
329
336
  return;
330
337
  }
331
338
  const previousStart = (_this$currentMatch = this.currentMatch) === null || _this$currentMatch === void 0 ? void 0 : _this$currentMatch.range.startOffset;
332
- this._matches = findDocRanges(body, this._query, !!this._doc.getSnapshot().disabled).map((range) => ({
339
+ this._matches = findDocRanges(body, this._query, !!this._doc.getSnapshot().disabled, this._textResolverService.resolve(this.unitId, body)).map((range) => ({
333
340
  provider: DOCS_FIND_REPLACE_PROVIDER,
334
341
  unitId: this.unitId,
335
342
  range: {
@@ -396,8 +403,12 @@ DocsFindModel = __decorate([
396
403
  __decorateParam(2, Inject(DocSelectionManagerService)),
397
404
  __decorateParam(3, IRenderManagerService),
398
405
  __decorateParam(4, ICommandService),
399
- __decorateParam(5, Inject(ThemeService))
406
+ __decorateParam(5, Inject(ThemeService)),
407
+ __decorateParam(6, Inject(DocTextResolverService))
400
408
  ], DocsFindModel);
409
+ function getUnitId(params) {
410
+ return params != null && typeof params === "object" && "unitId" in params && typeof params.unitId === "string" ? params.unitId : void 0;
411
+ }
401
412
 
402
413
  //#endregion
403
414
  //#region src/services/docs-find-replace.provider.ts
package/lib/index.js CHANGED
@@ -1,14 +1,14 @@
1
1
  import { BuildTextUtils, ColorKit, CommandType, DependentOn, Disposable, FOCUSING_DOC, ICommandService, IConfigService, IContextService, IUniverInstanceService, Inject, Injector, JSONX, MemoryCursor, Plugin, TextX, ThemeService, UniverInstanceType, fromCallback, getRichTextEditPath, merge, regexp, toDisposable } from "@univerjs/core";
2
- import { DocSelectionManagerService, DocSkeletonManagerService, RichTextEditingMutation, UniverDocsPlugin } from "@univerjs/docs";
2
+ import { DocSelectionManagerService, DocSkeletonManagerService, DocTextResolverService, RichTextEditingMutation, UniverDocsPlugin } from "@univerjs/docs";
3
3
  import { DocBackScrollRenderController, UniverDocsUIPlugin, getTextRangeFromCharIndex } from "@univerjs/docs-ui";
4
4
  import { IRenderManagerService, UniverRenderEnginePlugin } from "@univerjs/engine-render";
5
5
  import { FindModel, IFindReplaceService, OpenFindDialogOperation, UniverFindReplacePlugin } from "@univerjs/find-replace";
6
6
  import { IMenuManagerService, MenuItemType, RibbonStartGroup } from "@univerjs/ui";
7
- import { Subject, debounceTime, filter, map } from "rxjs";
7
+ import { Subject, debounceTime, filter, map, merge as merge$1 } from "rxjs";
8
8
 
9
9
  //#region package.json
10
10
  var name = "@univerjs/docs-find-replace";
11
- var version = "1.0.0-insiders.20260728-e98f416";
11
+ var version = "1.0.0-insiders.20260729-84ae2bd";
12
12
 
13
13
  //#endregion
14
14
  //#region src/config/config.ts
@@ -33,23 +33,32 @@ const defaultPluginConfig = {};
33
33
 
34
34
  //#endregion
35
35
  //#region src/controllers/utils.ts
36
- function findDocRanges(body, query, disabled) {
36
+ function findDocRanges(body, query, disabled, resolved = {
37
+ text: body.dataStream,
38
+ characters: Array.from({ length: body.dataStream.length }, (_value, index) => ({
39
+ startOffset: index,
40
+ endOffset: index + 1,
41
+ replaceable: true
42
+ }))
43
+ }) {
37
44
  if (!query.findString) return [];
38
45
  const expression = regexp.createLiteralRegExp(query.findString, query.caseSensitive ? "gu" : "giu");
39
- const wordRanges = query.matchesTheWholeWord ? new Set(Array.from(new Intl.Segmenter(void 0, { granularity: "word" }).segment(body.dataStream)).filter((item) => item.isWordLike).map((item) => `${item.index}:${item.index + item.segment.length}`)) : null;
40
- return Array.from(body.dataStream.matchAll(expression)).filter((match) => {
46
+ const wordRanges = query.matchesTheWholeWord ? new Set(Array.from(new Intl.Segmenter(void 0, { granularity: "word" }).segment(resolved.text)).filter((item) => item.isWordLike).map((item) => `${item.index}:${item.index + item.segment.length}`)) : null;
47
+ return Array.from(resolved.text.matchAll(expression)).filter((match) => {
41
48
  var _wordRanges$has;
42
49
  return (_wordRanges$has = wordRanges === null || wordRanges === void 0 ? void 0 : wordRanges.has(`${match.index}:${match.index + match[0].length}`)) !== null && _wordRanges$has !== void 0 ? _wordRanges$has : true;
43
- }).map((match) => {
50
+ }).flatMap((match) => {
44
51
  var _body$customRanges$so, _body$customRanges;
45
- const startOffset = match.index;
46
- const endOffset = startOffset + match[0].length;
52
+ const characters = resolved.characters.slice(match.index, match.index + match[0].length);
53
+ if (!characters.length) return [];
54
+ const startOffset = Math.min(...characters.map((character) => character.startOffset));
55
+ const endOffset = Math.max(...characters.map((character) => character.endOffset));
47
56
  const overlapsWholeEntity = (_body$customRanges$so = (_body$customRanges = body.customRanges) === null || _body$customRanges === void 0 ? void 0 : _body$customRanges.some((range) => range.wholeEntity && range.startIndex < endOffset && range.endIndex + 1 > startOffset)) !== null && _body$customRanges$so !== void 0 ? _body$customRanges$so : false;
48
- return {
57
+ return [{
49
58
  startOffset,
50
59
  endOffset,
51
- replaceable: !disabled && !overlapsWholeEntity
52
- };
60
+ replaceable: !disabled && !overlapsWholeEntity && characters.every((character) => character.replaceable)
61
+ }];
53
62
  });
54
63
  }
55
64
 
@@ -202,7 +211,7 @@ function __decorate(decorators, target, key, desc) {
202
211
  //#region src/models/docs-find.model.ts
203
212
  const DOCS_FIND_REPLACE_PROVIDER = "docs-find-replace-provider";
204
213
  let DocsFindModel = class DocsFindModel extends FindModel {
205
- constructor(_doc, _skeletonManager, _selectionManager, _renderManagerService, _commandService, _themeService) {
214
+ constructor(_doc, _skeletonManager, _selectionManager, _renderManagerService, _commandService, _themeService, _textResolverService) {
206
215
  super();
207
216
  this._doc = _doc;
208
217
  this._skeletonManager = _skeletonManager;
@@ -210,6 +219,7 @@ let DocsFindModel = class DocsFindModel extends FindModel {
210
219
  this._renderManagerService = _renderManagerService;
211
220
  this._commandService = _commandService;
212
221
  this._themeService = _themeService;
222
+ this._textResolverService = _textResolverService;
213
223
  _defineProperty(this, "_matchesUpdate$", new Subject());
214
224
  _defineProperty(this, "matchesUpdate$", this._matchesUpdate$.asObservable());
215
225
  _defineProperty(this, "_activelyChangingMatch$", new Subject());
@@ -220,10 +230,7 @@ let DocsFindModel = class DocsFindModel extends FindModel {
220
230
  _defineProperty(this, "_highlights", []);
221
231
  _defineProperty(this, "unitId", void 0);
222
232
  this.unitId = _doc.getUnitId();
223
- this.disposeWithMe(toDisposable(fromCallback(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(filter(([command]) => {
224
- var _command$params;
225
- return command.id === RichTextEditingMutation.id && ((_command$params = command.params) === null || _command$params === void 0 ? void 0 : _command$params.unitId) === this.unitId;
226
- }), debounceTime(220)).subscribe(() => this._scan(true))));
233
+ this.disposeWithMe(toDisposable(merge$1(fromCallback(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(filter(([command]) => command.id === RichTextEditingMutation.id && getUnitId(command.params) === this.unitId)), this._textResolverService.textChanged$.pipe(filter((unitId) => unitId === this.unitId))).pipe(debounceTime(220)).subscribe(() => this._scan(true))));
227
234
  this.disposeWithMe(toDisposable(this._skeletonManager.currentSkeleton$.subscribe(() => this._refreshHighlights())));
228
235
  }
229
236
  get currentMatch() {
@@ -329,7 +336,7 @@ let DocsFindModel = class DocsFindModel extends FindModel {
329
336
  return;
330
337
  }
331
338
  const previousStart = (_this$currentMatch = this.currentMatch) === null || _this$currentMatch === void 0 ? void 0 : _this$currentMatch.range.startOffset;
332
- this._matches = findDocRanges(body, this._query, !!this._doc.getSnapshot().disabled).map((range) => ({
339
+ this._matches = findDocRanges(body, this._query, !!this._doc.getSnapshot().disabled, this._textResolverService.resolve(this.unitId, body)).map((range) => ({
333
340
  provider: DOCS_FIND_REPLACE_PROVIDER,
334
341
  unitId: this.unitId,
335
342
  range: {
@@ -396,8 +403,12 @@ DocsFindModel = __decorate([
396
403
  __decorateParam(2, Inject(DocSelectionManagerService)),
397
404
  __decorateParam(3, IRenderManagerService),
398
405
  __decorateParam(4, ICommandService),
399
- __decorateParam(5, Inject(ThemeService))
406
+ __decorateParam(5, Inject(ThemeService)),
407
+ __decorateParam(6, Inject(DocTextResolverService))
400
408
  ], DocsFindModel);
409
+ function getUnitId(params) {
410
+ return params != null && typeof params === "object" && "unitId" in params && typeof params.unitId === "string" ? params.unitId : void 0;
411
+ }
401
412
 
402
413
  //#endregion
403
414
  //#region src/services/docs-find-replace.provider.ts
@@ -14,10 +14,11 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  import type { IDocumentBody } from '@univerjs/core';
17
+ import type { IResolvedDocText } from '@univerjs/docs';
17
18
  import type { IFindQuery } from '@univerjs/find-replace';
18
19
  export interface IDocFindRange {
19
20
  startOffset: number;
20
21
  endOffset: number;
21
22
  replaceable: boolean;
22
23
  }
23
- export declare function findDocRanges(body: IDocumentBody, query: IFindQuery, disabled: boolean): IDocFindRange[];
24
+ export declare function findDocRanges(body: IDocumentBody, query: IFindQuery, disabled: boolean, resolved?: IResolvedDocText): IDocFindRange[];
@@ -17,7 +17,7 @@ import type { DocumentDataModel, ITextRange, Nullable } from '@univerjs/core';
17
17
  import type { DocSkeletonManagerService } from '@univerjs/docs';
18
18
  import type { IFindMatch, IFindMoveParams, IFindQuery, IReplaceAllResult } from '@univerjs/find-replace';
19
19
  import { ICommandService, ThemeService } from '@univerjs/core';
20
- import { DocSelectionManagerService } from '@univerjs/docs';
20
+ import { DocSelectionManagerService, DocTextResolverService } from '@univerjs/docs';
21
21
  import { IRenderManagerService } from '@univerjs/engine-render';
22
22
  import { FindModel } from '@univerjs/find-replace';
23
23
  export declare const DOCS_FIND_REPLACE_PROVIDER = "docs-find-replace-provider";
@@ -33,6 +33,7 @@ export declare class DocsFindModel extends FindModel {
33
33
  private readonly _renderManagerService;
34
34
  private readonly _commandService;
35
35
  private readonly _themeService;
36
+ private readonly _textResolverService;
36
37
  private readonly _matchesUpdate$;
37
38
  readonly matchesUpdate$: import("rxjs").Observable<IDocFindMatch[]>;
38
39
  private readonly _activelyChangingMatch$;
@@ -42,7 +43,7 @@ export declare class DocsFindModel extends FindModel {
42
43
  private _query;
43
44
  private _highlights;
44
45
  readonly unitId: string;
45
- constructor(_doc: DocumentDataModel, _skeletonManager: DocSkeletonManagerService, _selectionManager: DocSelectionManagerService, _renderManagerService: IRenderManagerService, _commandService: ICommandService, _themeService: ThemeService);
46
+ constructor(_doc: DocumentDataModel, _skeletonManager: DocSkeletonManagerService, _selectionManager: DocSelectionManagerService, _renderManagerService: IRenderManagerService, _commandService: ICommandService, _themeService: ThemeService, _textResolverService: DocTextResolverService);
46
47
  get currentMatch(): Nullable<IDocFindMatch>;
47
48
  dispose(): void;
48
49
  getMatches(): IDocFindMatch[];
package/lib/umd/index.js CHANGED
@@ -1 +1 @@
1
- (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@univerjs/core"),require("@univerjs/docs"),require("@univerjs/docs-ui"),require("@univerjs/engine-render"),require("@univerjs/find-replace"),require("@univerjs/ui"),require("rxjs")):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/docs`,`@univerjs/docs-ui`,`@univerjs/engine-render`,`@univerjs/find-replace`,`@univerjs/ui`,`rxjs`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverDocsFindReplace={},e.UniverCore,e.UniverDocs,e.UniverDocsUi,e.UniverEngineRender,e.UniverFindReplace,e.UniverUi,e.rxjs))})(this,function(e,t,n,r,i,a,o,s){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var c=`@univerjs/docs-find-replace`,l=`1.0.0-insiders.20260728-e98f416`;let u={};function d(e,n,r){if(!n.findString)return[];let i=t.regexp.createLiteralRegExp(n.findString,n.caseSensitive?`gu`:`giu`),a=n.matchesTheWholeWord?new Set(Array.from(new Intl.Segmenter(void 0,{granularity:`word`}).segment(e.dataStream)).filter(e=>e.isWordLike).map(e=>`${e.index}:${e.index+e.segment.length}`)):null;return Array.from(e.dataStream.matchAll(i)).filter(e=>{var t;return(t=a==null?void 0:a.has(`${e.index}:${e.index+e[0].length}`))==null||t}).map(t=>{var n,i;let a=t.index,o=a+t[0].length,s=(n=(i=e.customRanges)==null?void 0:i.some(e=>e.wholeEntity&&e.startIndex<o&&e.endIndex+1>a))!=null&&n;return{startOffset:a,endOffset:o,replaceable:!r&&!s}})}let f={id:`docs.command.replace`,type:t.CommandType.COMMAND,handler:(e,r)=>{if(!r)return{success:0,failure:0};let i=e.get(t.IUniverInstanceService),a=e.get(t.ICommandService),o=i.getUnit(r.unitId,t.UniverInstanceType.UNIVER_DOC),s=o==null?void 0:o.getBody();if(!o||!s)return{success:0,failure:+!!r.range};let c=d(s,r.query,!!o.getSnapshot().disabled),l=r.range?c.filter(e=>e.startOffset===r.range.startOffset&&e.endOffset===r.range.endOffset):c,u=l.filter(e=>e.replaceable),f=(r.range&&l.length===0?1:l.length)-u.length;if(!u.length)return{success:0,failure:f};let p=new t.TextX,m=new t.MemoryCursor;for(let e of u){var h,g;let n=o.sliceBody(e.startOffset,e.endOffset),i=r.replaceString?{dataStream:r.replaceString,textRuns:n!=null&&(h=n.textRuns)!=null&&h.length?[{...n.textRuns[0],st:0,ed:r.replaceString.length}]:void 0,customRanges:n!=null&&(g=n.customRanges)!=null&&g.length?[{...n.customRanges[0],startIndex:0,endIndex:r.replaceString.length-1}]:void 0}:null;p.push(...t.BuildTextUtils.selection.delete([{startOffset:e.startOffset,endOffset:e.endOffset,collapsed:!1}],s,m.cursor,i,!1)),m.moveCursorTo(e.endOffset)}let _=t.JSONX.getInstance().editOp(p.serialize(),(0,t.getRichTextEditPath)(o));return a.syncExecuteCommand(n.RichTextEditingMutation.id,{unitId:r.unitId,actions:_,textRanges:[]})?{success:u.length,failure:f}:{success:0,failure:f+u.length}}};function p(e){let n=e.get(t.IContextService);return{id:a.OpenFindDialogOperation.id,icon:`SearchIcon`,tooltip:`find-replace.toolbar`,type:o.MenuItemType.BUTTON,disabled$:n.subscribeContextValue$(t.FOCUSING_DOC).pipe((0,s.map)(e=>!e))}}let m={[o.RibbonStartGroup.OTHERS]:{[a.OpenFindDialogOperation.id]:{order:3,menuItemFactory:p}}};function h(e){"@babel/helpers - typeof";return h=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},h(e)}function g(e,t){if(h(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(h(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function _(e){var t=g(e,`string`);return h(t)==`symbol`?t:t+``}function v(e,t,n){return(t=_(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function y(e,t){return function(n,r){t(n,r,e)}}function b(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let x=class extends a.FindModel{constructor(e,r,i,a,o,c){super(),this._doc=e,this._skeletonManager=r,this._selectionManager=i,this._renderManagerService=a,this._commandService=o,this._themeService=c,v(this,`_matchesUpdate$`,new s.Subject),v(this,`matchesUpdate$`,this._matchesUpdate$.asObservable()),v(this,`_activelyChangingMatch$`,new s.Subject),v(this,`activelyChangingMatch$`,this._activelyChangingMatch$.asObservable()),v(this,`_matches`,[]),v(this,`_position`,-1),v(this,`_query`,null),v(this,`_highlights`,[]),v(this,`unitId`,void 0),this.unitId=e.getUnitId(),this.disposeWithMe((0,t.toDisposable)((0,t.fromCallback)(this._commandService.onCommandExecuted.bind(this._commandService)).pipe((0,s.filter)(([e])=>{var t;return e.id===n.RichTextEditingMutation.id&&((t=e.params)==null?void 0:t.unitId)===this.unitId}),(0,s.debounceTime)(220)).subscribe(()=>this._scan(!0)))),this.disposeWithMe((0,t.toDisposable)(this._skeletonManager.currentSkeleton$.subscribe(()=>this._refreshHighlights())))}get currentMatch(){var e;return this._position<0||(e=this._matches[this._position])==null?null:e}dispose(){super.dispose(),this._disposeHighlights(),this._matchesUpdate$.complete(),this._activelyChangingMatch$.complete()}getMatches(){return this._matches}start(e){this._query=e,this._position=-1,this._scan(!1)}moveToNextMatch(e){if(!this._matches.length)return null;if(e!=null&&e.stayIfOnMatch&&this.currentMatch)return this._activate(this._position,e.noFocus);let t;if(e!=null&&e.ignoreSelection)t=0;else if(this._position>=0)t=this._position+1;else{let n=this._selectionManager.getActiveTextRange(),r=e!=null&&e.stayIfOnMatch?this._selectionMatchIndex():-1;t=r>=0?r:this._matches.findIndex(e=>{var t;return e.range.startOffset>=((t=n==null?void 0:n.endOffset)==null?0:t)})}return(t<0||t>=this._matches.length)&&(t=e!=null&&e.loop?0:-1),t<0?(this._position=-1,this._refreshHighlights(),null):this._activate(t,e==null?void 0:e.noFocus)}moveToPreviousMatch(e){if(!this._matches.length)return null;if(e!=null&&e.stayIfOnMatch&&this.currentMatch)return this._activate(this._position,e.noFocus);let t;if(e!=null&&e.ignoreSelection)t=this._matches.length-1;else if(this._position>=0)t=this._position-1;else{let n=this._selectionManager.getActiveTextRange(),r=e!=null&&e.stayIfOnMatch?this._selectionMatchIndex():-1;t=r>=0?r:this._matches.findLastIndex(e=>{var t;return e.range.endOffset<=((t=n==null?void 0:n.startOffset)==null?0:t)})}return t<0&&(t=e!=null&&e.loop?this._matches.length-1:-1),t<0?(this._position=-1,this._refreshHighlights(),null):this._activate(t,e==null?void 0:e.noFocus)}async replace(e){let t=this.currentMatch;if(!(t!=null&&t.replaceable)||!this._query)return!1;let n=await this._commandService.executeCommand(f.id,{unitId:this.unitId,query:this._query,replaceString:e,range:t.range});return(n==null?void 0:n.success)===1}async replaceAll(e){var t;return this._query?(t=await this._commandService.executeCommand(f.id,{unitId:this.unitId,query:this._query,replaceString:e}))==null?{success:0,failure:this._matches.length}:t:{success:0,failure:0}}focusSelection(){this.currentMatch&&this._focusMatch(this.currentMatch)}_scan(e){var t;if(!this._query)return;let n=this._doc.getBody();if(!n){this._matches=[],this._position=-1,this._disposeHighlights(),e&&this._matchesUpdate$.next([]);return}let r=(t=this.currentMatch)==null?void 0:t.range.startOffset;this._matches=d(n,this._query,!!this._doc.getSnapshot().disabled).map(e=>({provider:`docs-find-replace-provider`,unitId:this.unitId,range:{...e,collapsed:!1},replaceable:e.replaceable})),this._position=r==null?-1:this._matches.findIndex(e=>e.range.startOffset>=r),this._refreshHighlights(),e&&this._matchesUpdate$.next(this._matches)}_selectionMatchIndex(){let e=this._selectionManager.getActiveTextRange();return e?this._matches.findIndex(t=>t.range.startOffset<=e.startOffset&&t.range.endOffset>=e.endOffset):-1}_activate(e,t=!1){let n=this._matches[e];return n?(this._position=e,t?this._refreshHighlights():this._focusMatch(n),n):null}_focusMatch(e){var t;this._selectionManager.replaceDocRanges([e.range],{unitId:this.unitId,subUnitId:this.unitId},!0,{shouldFocus:!1}),(t=this._renderManagerService.getRenderUnitById(this.unitId))==null||t.with(r.DocBackScrollRenderController).scrollToRange(e.range),this._activelyChangingMatch$.next(e),this._refreshHighlights()}_refreshHighlights(){this._disposeHighlights();let e=this._renderManagerService.getRenderUnitById(this.unitId),n=this._skeletonManager.getSkeleton(),i=e==null?void 0:e.mainComponent;if(!e||!n||!i)return;let a=this._themeService.getColorFromTheme(`yellow.400`),o={strokeWidth:0,stroke:`rgba(0,0,0,0)`,strokeActive:`rgba(0,0,0,0)`,fill:new t.ColorKit(a).setAlpha(.3).toRgbString()},s={...o,fill:new t.ColorKit(a).setAlpha(.65).toRgbString()};this._matches.forEach((t,a)=>{let c=(0,r.getTextRangeFromCharIndex)(t.range.startOffset,t.range.endOffset,e.scene,i,n,a===this._position?s:o,``,-1);c&&this._highlights.push(c)})}_disposeHighlights(){this._highlights.forEach(e=>e.dispose()),this._highlights=[]}};x=b([y(2,(0,t.Inject)(n.DocSelectionManagerService)),y(3,i.IRenderManagerService),y(4,t.ICommandService),y(5,(0,t.Inject)(t.ThemeService))],x);let S=class extends t.Disposable{constructor(e,t,n){super(),this._instanceService=e,this._renderManagerService=t,this._injector=n,v(this,`capabilities`,{caseSensitive:!0,matchesTheWholeWord:!0,matchesTheWholeCell:!1,findDirection:!1,findScope:!1,findBy:!1}),v(this,`_model`,null)}isSupported(e){return e.type===t.UniverInstanceType.UNIVER_DOC}async find(e){var r;this.terminate();let i=this._instanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_DOC);if(!i)return[];let a=(r=this._renderManagerService.getRenderUnitById(i.getUnitId()))==null?void 0:r.with(n.DocSkeletonManagerService);return a?(this._model=this._injector.createInstance(x,i,a),this._model.start(e),[this._model]):[]}terminate(){var e;(e=this._model)==null||e.dispose(),this._model=null}dispose(){this.terminate(),super.dispose()}};S=b([y(0,t.IUniverInstanceService),y(1,i.IRenderManagerService),y(2,(0,t.Inject)(t.Injector))],S);let C=class extends t.Disposable{constructor(e,t,n,r){super(),this.disposeWithMe(e),this.disposeWithMe(t.registerFindReplaceProvider(e)),this.disposeWithMe(n.registerCommand(f)),r.mergeMenu(m)}};C=b([y(0,(0,t.Inject)(S)),y(1,a.IFindReplaceService),y(2,t.ICommandService),y(3,o.IMenuManagerService)],C);let w=class extends t.Plugin{constructor(e=u,n,r){super(),this._config=e,this._injector=n,this._configService=r;let{...i}=(0,t.merge)({},u,this._config);this._configService.setConfig(`docs-find-replace.config`,i)}onStarting(){this._injector.add([S]),this._injector.add([C])}onSteady(){this._injector.get(C)}};v(w,`pluginName`,`DOCS_FIND_REPLACE_PLUGIN`),v(w,`packageName`,c),v(w,`version`,l),v(w,`type`,t.UniverInstanceType.UNIVER_DOC),w=b([(0,t.DependentOn)(n.UniverDocsPlugin,i.UniverRenderEnginePlugin,r.UniverDocsUIPlugin,a.UniverFindReplacePlugin),y(1,(0,t.Inject)(t.Injector)),y(2,t.IConfigService)],w),Object.defineProperty(e,"UniverDocsFindReplacePlugin",{enumerable:!0,get:function(){return w}})});
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@univerjs/core"),require("@univerjs/docs"),require("@univerjs/docs-ui"),require("@univerjs/engine-render"),require("@univerjs/find-replace"),require("@univerjs/ui"),require("rxjs")):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/docs`,`@univerjs/docs-ui`,`@univerjs/engine-render`,`@univerjs/find-replace`,`@univerjs/ui`,`rxjs`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverDocsFindReplace={},e.UniverCore,e.UniverDocs,e.UniverDocsUi,e.UniverEngineRender,e.UniverFindReplace,e.UniverUi,e.rxjs))})(this,function(e,t,n,r,i,a,o,s){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var c=`@univerjs/docs-find-replace`,l=`1.0.0-insiders.20260729-84ae2bd`;let u={};function d(e,n,r,i={text:e.dataStream,characters:Array.from({length:e.dataStream.length},(e,t)=>({startOffset:t,endOffset:t+1,replaceable:!0}))}){if(!n.findString)return[];let a=t.regexp.createLiteralRegExp(n.findString,n.caseSensitive?`gu`:`giu`),o=n.matchesTheWholeWord?new Set(Array.from(new Intl.Segmenter(void 0,{granularity:`word`}).segment(i.text)).filter(e=>e.isWordLike).map(e=>`${e.index}:${e.index+e.segment.length}`)):null;return Array.from(i.text.matchAll(a)).filter(e=>{var t;return(t=o==null?void 0:o.has(`${e.index}:${e.index+e[0].length}`))==null||t}).flatMap(t=>{var n,a;let o=i.characters.slice(t.index,t.index+t[0].length);if(!o.length)return[];let s=Math.min(...o.map(e=>e.startOffset)),c=Math.max(...o.map(e=>e.endOffset)),l=(n=(a=e.customRanges)==null?void 0:a.some(e=>e.wholeEntity&&e.startIndex<c&&e.endIndex+1>s))!=null&&n;return[{startOffset:s,endOffset:c,replaceable:!r&&!l&&o.every(e=>e.replaceable)}]})}let f={id:`docs.command.replace`,type:t.CommandType.COMMAND,handler:(e,r)=>{if(!r)return{success:0,failure:0};let i=e.get(t.IUniverInstanceService),a=e.get(t.ICommandService),o=i.getUnit(r.unitId,t.UniverInstanceType.UNIVER_DOC),s=o==null?void 0:o.getBody();if(!o||!s)return{success:0,failure:+!!r.range};let c=d(s,r.query,!!o.getSnapshot().disabled),l=r.range?c.filter(e=>e.startOffset===r.range.startOffset&&e.endOffset===r.range.endOffset):c,u=l.filter(e=>e.replaceable),f=(r.range&&l.length===0?1:l.length)-u.length;if(!u.length)return{success:0,failure:f};let p=new t.TextX,m=new t.MemoryCursor;for(let e of u){var h,g;let n=o.sliceBody(e.startOffset,e.endOffset),i=r.replaceString?{dataStream:r.replaceString,textRuns:n!=null&&(h=n.textRuns)!=null&&h.length?[{...n.textRuns[0],st:0,ed:r.replaceString.length}]:void 0,customRanges:n!=null&&(g=n.customRanges)!=null&&g.length?[{...n.customRanges[0],startIndex:0,endIndex:r.replaceString.length-1}]:void 0}:null;p.push(...t.BuildTextUtils.selection.delete([{startOffset:e.startOffset,endOffset:e.endOffset,collapsed:!1}],s,m.cursor,i,!1)),m.moveCursorTo(e.endOffset)}let _=t.JSONX.getInstance().editOp(p.serialize(),(0,t.getRichTextEditPath)(o));return a.syncExecuteCommand(n.RichTextEditingMutation.id,{unitId:r.unitId,actions:_,textRanges:[]})?{success:u.length,failure:f}:{success:0,failure:f+u.length}}};function p(e){let n=e.get(t.IContextService);return{id:a.OpenFindDialogOperation.id,icon:`SearchIcon`,tooltip:`find-replace.toolbar`,type:o.MenuItemType.BUTTON,disabled$:n.subscribeContextValue$(t.FOCUSING_DOC).pipe((0,s.map)(e=>!e))}}let m={[o.RibbonStartGroup.OTHERS]:{[a.OpenFindDialogOperation.id]:{order:3,menuItemFactory:p}}};function h(e){"@babel/helpers - typeof";return h=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},h(e)}function g(e,t){if(h(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(h(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function _(e){var t=g(e,`string`);return h(t)==`symbol`?t:t+``}function v(e,t,n){return(t=_(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function y(e,t){return function(n,r){t(n,r,e)}}function b(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let x=class extends a.FindModel{constructor(e,r,i,a,o,c,l){super(),this._doc=e,this._skeletonManager=r,this._selectionManager=i,this._renderManagerService=a,this._commandService=o,this._themeService=c,this._textResolverService=l,v(this,`_matchesUpdate$`,new s.Subject),v(this,`matchesUpdate$`,this._matchesUpdate$.asObservable()),v(this,`_activelyChangingMatch$`,new s.Subject),v(this,`activelyChangingMatch$`,this._activelyChangingMatch$.asObservable()),v(this,`_matches`,[]),v(this,`_position`,-1),v(this,`_query`,null),v(this,`_highlights`,[]),v(this,`unitId`,void 0),this.unitId=e.getUnitId(),this.disposeWithMe((0,t.toDisposable)((0,s.merge)((0,t.fromCallback)(this._commandService.onCommandExecuted.bind(this._commandService)).pipe((0,s.filter)(([e])=>e.id===n.RichTextEditingMutation.id&&S(e.params)===this.unitId)),this._textResolverService.textChanged$.pipe((0,s.filter)(e=>e===this.unitId))).pipe((0,s.debounceTime)(220)).subscribe(()=>this._scan(!0)))),this.disposeWithMe((0,t.toDisposable)(this._skeletonManager.currentSkeleton$.subscribe(()=>this._refreshHighlights())))}get currentMatch(){var e;return this._position<0||(e=this._matches[this._position])==null?null:e}dispose(){super.dispose(),this._disposeHighlights(),this._matchesUpdate$.complete(),this._activelyChangingMatch$.complete()}getMatches(){return this._matches}start(e){this._query=e,this._position=-1,this._scan(!1)}moveToNextMatch(e){if(!this._matches.length)return null;if(e!=null&&e.stayIfOnMatch&&this.currentMatch)return this._activate(this._position,e.noFocus);let t;if(e!=null&&e.ignoreSelection)t=0;else if(this._position>=0)t=this._position+1;else{let n=this._selectionManager.getActiveTextRange(),r=e!=null&&e.stayIfOnMatch?this._selectionMatchIndex():-1;t=r>=0?r:this._matches.findIndex(e=>{var t;return e.range.startOffset>=((t=n==null?void 0:n.endOffset)==null?0:t)})}return(t<0||t>=this._matches.length)&&(t=e!=null&&e.loop?0:-1),t<0?(this._position=-1,this._refreshHighlights(),null):this._activate(t,e==null?void 0:e.noFocus)}moveToPreviousMatch(e){if(!this._matches.length)return null;if(e!=null&&e.stayIfOnMatch&&this.currentMatch)return this._activate(this._position,e.noFocus);let t;if(e!=null&&e.ignoreSelection)t=this._matches.length-1;else if(this._position>=0)t=this._position-1;else{let n=this._selectionManager.getActiveTextRange(),r=e!=null&&e.stayIfOnMatch?this._selectionMatchIndex():-1;t=r>=0?r:this._matches.findLastIndex(e=>{var t;return e.range.endOffset<=((t=n==null?void 0:n.startOffset)==null?0:t)})}return t<0&&(t=e!=null&&e.loop?this._matches.length-1:-1),t<0?(this._position=-1,this._refreshHighlights(),null):this._activate(t,e==null?void 0:e.noFocus)}async replace(e){let t=this.currentMatch;if(!(t!=null&&t.replaceable)||!this._query)return!1;let n=await this._commandService.executeCommand(f.id,{unitId:this.unitId,query:this._query,replaceString:e,range:t.range});return(n==null?void 0:n.success)===1}async replaceAll(e){var t;return this._query?(t=await this._commandService.executeCommand(f.id,{unitId:this.unitId,query:this._query,replaceString:e}))==null?{success:0,failure:this._matches.length}:t:{success:0,failure:0}}focusSelection(){this.currentMatch&&this._focusMatch(this.currentMatch)}_scan(e){var t;if(!this._query)return;let n=this._doc.getBody();if(!n){this._matches=[],this._position=-1,this._disposeHighlights(),e&&this._matchesUpdate$.next([]);return}let r=(t=this.currentMatch)==null?void 0:t.range.startOffset;this._matches=d(n,this._query,!!this._doc.getSnapshot().disabled,this._textResolverService.resolve(this.unitId,n)).map(e=>({provider:`docs-find-replace-provider`,unitId:this.unitId,range:{...e,collapsed:!1},replaceable:e.replaceable})),this._position=r==null?-1:this._matches.findIndex(e=>e.range.startOffset>=r),this._refreshHighlights(),e&&this._matchesUpdate$.next(this._matches)}_selectionMatchIndex(){let e=this._selectionManager.getActiveTextRange();return e?this._matches.findIndex(t=>t.range.startOffset<=e.startOffset&&t.range.endOffset>=e.endOffset):-1}_activate(e,t=!1){let n=this._matches[e];return n?(this._position=e,t?this._refreshHighlights():this._focusMatch(n),n):null}_focusMatch(e){var t;this._selectionManager.replaceDocRanges([e.range],{unitId:this.unitId,subUnitId:this.unitId},!0,{shouldFocus:!1}),(t=this._renderManagerService.getRenderUnitById(this.unitId))==null||t.with(r.DocBackScrollRenderController).scrollToRange(e.range),this._activelyChangingMatch$.next(e),this._refreshHighlights()}_refreshHighlights(){this._disposeHighlights();let e=this._renderManagerService.getRenderUnitById(this.unitId),n=this._skeletonManager.getSkeleton(),i=e==null?void 0:e.mainComponent;if(!e||!n||!i)return;let a=this._themeService.getColorFromTheme(`yellow.400`),o={strokeWidth:0,stroke:`rgba(0,0,0,0)`,strokeActive:`rgba(0,0,0,0)`,fill:new t.ColorKit(a).setAlpha(.3).toRgbString()},s={...o,fill:new t.ColorKit(a).setAlpha(.65).toRgbString()};this._matches.forEach((t,a)=>{let c=(0,r.getTextRangeFromCharIndex)(t.range.startOffset,t.range.endOffset,e.scene,i,n,a===this._position?s:o,``,-1);c&&this._highlights.push(c)})}_disposeHighlights(){this._highlights.forEach(e=>e.dispose()),this._highlights=[]}};x=b([y(2,(0,t.Inject)(n.DocSelectionManagerService)),y(3,i.IRenderManagerService),y(4,t.ICommandService),y(5,(0,t.Inject)(t.ThemeService)),y(6,(0,t.Inject)(n.DocTextResolverService))],x);function S(e){return typeof e==`object`&&e&&`unitId`in e&&typeof e.unitId==`string`?e.unitId:void 0}let C=class extends t.Disposable{constructor(e,t,n){super(),this._instanceService=e,this._renderManagerService=t,this._injector=n,v(this,`capabilities`,{caseSensitive:!0,matchesTheWholeWord:!0,matchesTheWholeCell:!1,findDirection:!1,findScope:!1,findBy:!1}),v(this,`_model`,null)}isSupported(e){return e.type===t.UniverInstanceType.UNIVER_DOC}async find(e){var r;this.terminate();let i=this._instanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_DOC);if(!i)return[];let a=(r=this._renderManagerService.getRenderUnitById(i.getUnitId()))==null?void 0:r.with(n.DocSkeletonManagerService);return a?(this._model=this._injector.createInstance(x,i,a),this._model.start(e),[this._model]):[]}terminate(){var e;(e=this._model)==null||e.dispose(),this._model=null}dispose(){this.terminate(),super.dispose()}};C=b([y(0,t.IUniverInstanceService),y(1,i.IRenderManagerService),y(2,(0,t.Inject)(t.Injector))],C);let w=class extends t.Disposable{constructor(e,t,n,r){super(),this.disposeWithMe(e),this.disposeWithMe(t.registerFindReplaceProvider(e)),this.disposeWithMe(n.registerCommand(f)),r.mergeMenu(m)}};w=b([y(0,(0,t.Inject)(C)),y(1,a.IFindReplaceService),y(2,t.ICommandService),y(3,o.IMenuManagerService)],w);let T=class extends t.Plugin{constructor(e=u,n,r){super(),this._config=e,this._injector=n,this._configService=r;let{...i}=(0,t.merge)({},u,this._config);this._configService.setConfig(`docs-find-replace.config`,i)}onStarting(){this._injector.add([C]),this._injector.add([w])}onSteady(){this._injector.get(w)}};v(T,`pluginName`,`DOCS_FIND_REPLACE_PLUGIN`),v(T,`packageName`,c),v(T,`version`,l),v(T,`type`,t.UniverInstanceType.UNIVER_DOC),T=b([(0,t.DependentOn)(n.UniverDocsPlugin,i.UniverRenderEnginePlugin,r.UniverDocsUIPlugin,a.UniverFindReplacePlugin),y(1,(0,t.Inject)(t.Injector)),y(2,t.IConfigService)],T),Object.defineProperty(e,"UniverDocsFindReplacePlugin",{enumerable:!0,get:function(){return T}})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/docs-find-replace",
3
- "version": "1.0.0-insiders.20260728-e98f416",
3
+ "version": "1.0.0-insiders.20260729-84ae2bd",
4
4
  "private": false,
5
5
  "description": "Find and replace support for Univer Docs.",
6
6
  "author": "DreamNum Co., Ltd. <developer@univer.ai>",
@@ -52,12 +52,12 @@
52
52
  "rxjs": ">=7.0.0"
53
53
  },
54
54
  "dependencies": {
55
- "@univerjs/docs": "1.0.0-insiders.20260728-e98f416",
56
- "@univerjs/engine-render": "1.0.0-insiders.20260728-e98f416",
57
- "@univerjs/core": "1.0.0-insiders.20260728-e98f416",
58
- "@univerjs/docs-ui": "1.0.0-insiders.20260728-e98f416",
59
- "@univerjs/ui": "1.0.0-insiders.20260728-e98f416",
60
- "@univerjs/find-replace": "1.0.0-insiders.20260728-e98f416"
55
+ "@univerjs/core": "1.0.0-insiders.20260729-84ae2bd",
56
+ "@univerjs/docs": "1.0.0-insiders.20260729-84ae2bd",
57
+ "@univerjs/docs-ui": "1.0.0-insiders.20260729-84ae2bd",
58
+ "@univerjs/engine-render": "1.0.0-insiders.20260729-84ae2bd",
59
+ "@univerjs/ui": "1.0.0-insiders.20260729-84ae2bd",
60
+ "@univerjs/find-replace": "1.0.0-insiders.20260729-84ae2bd"
61
61
  },
62
62
  "devDependencies": {
63
63
  "react": "18.3.1",