@univerjs/sheets-find-replace 0.2.4 → 0.2.6
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 +1 -1
- package/lib/es/index.js +433 -416
- package/lib/types/controllers/sheet-find-replace.controller.d.ts +1 -2
- package/lib/types/plugin.d.ts +2 -3
- package/lib/umd/index.js +1 -1
- package/package.json +16 -18
package/lib/es/index.js
CHANGED
|
@@ -1,131 +1,141 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
import { FindReplaceController
|
|
7
|
-
import { SetRangeValuesCommand
|
|
8
|
-
import { Shape
|
|
9
|
-
import { SheetSkeletonManagerService
|
|
10
|
-
import { filter
|
|
11
|
-
class
|
|
12
|
-
constructor(
|
|
13
|
-
super(
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
setShapeProps(
|
|
20
|
-
this._activated = !!
|
|
21
|
-
width:
|
|
22
|
-
height:
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value;
|
|
3
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: !0 });
|
|
4
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key != "symbol" ? key + "" : key, value);
|
|
5
|
+
import { CommandType, IUndoRedoService, ICommandService, Rectangle, OnLifecycle, LifecycleStages, Inject, Injector, ThemeService, Disposable, EDITOR_ACTIVATED, IContextService, IUniverInstanceService, UniverInstanceType, fromCallback, ColorKit, rotate, groupBy, ObjectMatrix, Tools, replaceInDocumentBody, DependentOn, Plugin } from "@univerjs/core";
|
|
6
|
+
import { FindReplaceController, IFindReplaceService, FindModel, FindBy, FindScope, FindDirection, UniverFindReplacePlugin } from "@univerjs/find-replace";
|
|
7
|
+
import { SetRangeValuesCommand, SheetsSelectionsService, SetWorksheetActiveOperation, SetSelectionsOperation, SetWorksheetActivateCommand, UniverSheetsPlugin } from "@univerjs/sheets";
|
|
8
|
+
import { Shape, Rect, IRenderManagerService, RENDER_RAW_FORMULA_KEY } from "@univerjs/engine-render";
|
|
9
|
+
import { SheetSkeletonManagerService, getCoordByCell, getSheetObject, ScrollToCellCommand } from "@univerjs/sheets-ui";
|
|
10
|
+
import { filter, Subject, throttleTime, merge, skip, debounceTime } from "rxjs";
|
|
11
|
+
const _SheetFindReplaceHighlightShape = class _SheetFindReplaceHighlightShape extends Shape {
|
|
12
|
+
constructor(key, props) {
|
|
13
|
+
super(key, props);
|
|
14
|
+
__publicField(this, "_activated", !1);
|
|
15
|
+
__publicField(this, "_inHiddenRange", !1);
|
|
16
|
+
__publicField(this, "_color");
|
|
17
|
+
props && this.setShapeProps(props);
|
|
18
|
+
}
|
|
19
|
+
setShapeProps(props) {
|
|
20
|
+
this._activated = !!props.activated, typeof props.inHiddenRange < "u" && (this._inHiddenRange = props.inHiddenRange), typeof props.color < "u" && (this._color = props.color), this.transformByState({
|
|
21
|
+
width: props.width,
|
|
22
|
+
height: props.height
|
|
23
23
|
});
|
|
24
24
|
}
|
|
25
|
-
_draw(
|
|
26
|
-
const
|
|
27
|
-
|
|
25
|
+
_draw(ctx) {
|
|
26
|
+
const activated = this._activated, color = `rgba(${this._color.r}, ${this._color.g}, ${this._color.b}, 0.35)`, borderColor = `rgb(${this._color.r}, ${this._color.g}, ${this._color.b})`;
|
|
27
|
+
Rect.drawWith(ctx, {
|
|
28
28
|
width: this.width,
|
|
29
29
|
height: this.height,
|
|
30
|
-
fill:
|
|
31
|
-
stroke:
|
|
32
|
-
strokeWidth:
|
|
30
|
+
fill: color,
|
|
31
|
+
stroke: activated ? borderColor : void 0,
|
|
32
|
+
strokeWidth: activated ? 2 : 0,
|
|
33
33
|
evented: !1
|
|
34
34
|
});
|
|
35
35
|
}
|
|
36
|
-
}
|
|
37
|
-
|
|
36
|
+
};
|
|
37
|
+
__name(_SheetFindReplaceHighlightShape, "SheetFindReplaceHighlightShape");
|
|
38
|
+
let SheetFindReplaceHighlightShape = _SheetFindReplaceHighlightShape;
|
|
39
|
+
const SheetReplaceCommand = {
|
|
38
40
|
id: "sheet.command.replace",
|
|
39
|
-
type:
|
|
40
|
-
handler: async (
|
|
41
|
-
const
|
|
42
|
-
unitId
|
|
43
|
-
subUnitId:
|
|
44
|
-
value:
|
|
41
|
+
type: CommandType.COMMAND,
|
|
42
|
+
handler: /* @__PURE__ */ __name(async (accessor, params) => {
|
|
43
|
+
const undoRedoService = accessor.get(IUndoRedoService), commandService = accessor.get(ICommandService), { unitId, replacements } = params, disposeBatchingHandler = undoRedoService.__tempBatchingUndoRedo(unitId), results = await Promise.all(replacements.map((replacement) => commandService.executeCommand(SetRangeValuesCommand.id, {
|
|
44
|
+
unitId,
|
|
45
|
+
subUnitId: replacement.subUnitId,
|
|
46
|
+
value: replacement.value
|
|
45
47
|
})));
|
|
46
|
-
return
|
|
47
|
-
}
|
|
48
|
+
return disposeBatchingHandler.dispose(), getReplaceAllResult(results, replacements);
|
|
49
|
+
}, "handler")
|
|
48
50
|
};
|
|
49
|
-
function
|
|
50
|
-
let
|
|
51
|
-
return
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
}), { success
|
|
51
|
+
function getReplaceAllResult(results, replacements) {
|
|
52
|
+
let success = 0, failure = 0;
|
|
53
|
+
return results.forEach((r, index) => {
|
|
54
|
+
const count = replacements[index].count;
|
|
55
|
+
r ? success += count : failure += count;
|
|
56
|
+
}), { success, failure };
|
|
55
57
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
+
__name(getReplaceAllResult, "getReplaceAllResult");
|
|
59
|
+
function isSamePosition(range1, range2) {
|
|
60
|
+
return range1.startRow === range2.startRow && range1.startColumn === range2.startColumn;
|
|
58
61
|
}
|
|
59
|
-
|
|
60
|
-
|
|
62
|
+
__name(isSamePosition, "isSamePosition");
|
|
63
|
+
function isBehindPositionWithRowPriority(range1, range2) {
|
|
64
|
+
return range1.startRow < range2.startRow || range1.startRow === range2.startRow && range1.startColumn <= range2.startColumn;
|
|
61
65
|
}
|
|
62
|
-
|
|
63
|
-
|
|
66
|
+
__name(isBehindPositionWithRowPriority, "isBehindPositionWithRowPriority");
|
|
67
|
+
function isBehindPositionWithColumnPriority(range1, range2) {
|
|
68
|
+
return range1.startColumn < range2.startColumn || range1.startColumn === range2.startColumn && range1.startRow <= range2.startRow;
|
|
64
69
|
}
|
|
65
|
-
|
|
66
|
-
|
|
70
|
+
__name(isBehindPositionWithColumnPriority, "isBehindPositionWithColumnPriority");
|
|
71
|
+
function isBeforePositionWithRowPriority(range1, range2) {
|
|
72
|
+
return range1.startRow > range2.startRow || range1.startRow === range2.startRow && range1.startColumn >= range2.startColumn;
|
|
67
73
|
}
|
|
68
|
-
|
|
69
|
-
|
|
74
|
+
__name(isBeforePositionWithRowPriority, "isBeforePositionWithRowPriority");
|
|
75
|
+
function isBeforePositionWithColumnPriority(range1, range2) {
|
|
76
|
+
return range1.startColumn > range2.startColumn || range1.startColumn === range2.startColumn && range1.startRow >= range2.startRow;
|
|
70
77
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
78
|
+
__name(isBeforePositionWithColumnPriority, "isBeforePositionWithColumnPriority");
|
|
79
|
+
function isSelectionSingleCell(selection, worksheet) {
|
|
80
|
+
const { range } = selection, { startRow, startColumn } = range, hasMergedCell = worksheet.getMergedCell(startRow, startColumn);
|
|
81
|
+
return hasMergedCell ? Rectangle.equals(range, hasMergedCell) : range.endRow === range.startRow && range.endColumn === range.startColumn;
|
|
74
82
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
83
|
+
__name(isSelectionSingleCell, "isSelectionSingleCell");
|
|
84
|
+
var __defProp$1 = Object.defineProperty, __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor, __decorateClass$1 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
85
|
+
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$1(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
86
|
+
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
87
|
+
return kind && result && __defProp$1(target, key, result), result;
|
|
88
|
+
}, "__decorateClass$1"), __decorateParam$1 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$1"), _a;
|
|
89
|
+
let SheetsFindReplaceController = (_a = class extends Disposable {
|
|
90
|
+
constructor(_injector, _findReplaceController, _contextService, _findReplaceService, _commandService) {
|
|
82
91
|
super();
|
|
83
|
-
|
|
84
|
-
this._injector =
|
|
92
|
+
__publicField(this, "_provider");
|
|
93
|
+
this._injector = _injector, this._findReplaceController = _findReplaceController, this._contextService = _contextService, this._findReplaceService = _findReplaceService, this._commandService = _commandService, this._init(), this._initCommands();
|
|
85
94
|
}
|
|
86
95
|
dispose() {
|
|
87
96
|
super.dispose(), this._findReplaceController.closePanel(), this._provider.dispose();
|
|
88
97
|
}
|
|
89
98
|
_init() {
|
|
90
|
-
const
|
|
91
|
-
this._provider =
|
|
92
|
-
this._contextService.subscribeContextValue$(
|
|
99
|
+
const provider = this._injector.createInstance(SheetsFindReplaceProvider);
|
|
100
|
+
this._provider = provider, this.disposeWithMe(this._findReplaceService.registerFindReplaceProvider(provider)), this.disposeWithMe(
|
|
101
|
+
this._contextService.subscribeContextValue$(EDITOR_ACTIVATED).pipe(filter((v) => !!v)).subscribe(() => this._findReplaceController.closePanel())
|
|
93
102
|
);
|
|
94
103
|
}
|
|
95
104
|
_initCommands() {
|
|
96
|
-
[
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
],
|
|
107
|
-
const
|
|
108
|
-
|
|
109
|
-
|
|
105
|
+
[SheetReplaceCommand].forEach((command) => this.disposeWithMe(this._commandService.registerCommand(command)));
|
|
106
|
+
}
|
|
107
|
+
}, __name(_a, "SheetsFindReplaceController"), _a);
|
|
108
|
+
SheetsFindReplaceController = __decorateClass$1([
|
|
109
|
+
OnLifecycle(LifecycleStages.Steady, SheetsFindReplaceController),
|
|
110
|
+
__decorateParam$1(0, Inject(Injector)),
|
|
111
|
+
__decorateParam$1(1, Inject(FindReplaceController)),
|
|
112
|
+
__decorateParam$1(2, IContextService),
|
|
113
|
+
__decorateParam$1(3, IFindReplaceService),
|
|
114
|
+
__decorateParam$1(4, ICommandService)
|
|
115
|
+
], SheetsFindReplaceController);
|
|
116
|
+
const SHEETS_FIND_REPLACE_PROVIDER_NAME = "sheets-find-replace-provider", FIND_REPLACE_Z_INDEX = 1e4;
|
|
117
|
+
var _a2;
|
|
118
|
+
let SheetFindModel = (_a2 = class extends FindModel {
|
|
119
|
+
constructor(_workbook, _sheetSkeletonManagerService, _univerInstanceService, _renderManagerService, _commandService, _contextService, _themeService, _selectionManagerService) {
|
|
110
120
|
super();
|
|
111
121
|
// We can directly inject the `FindReplaceService` here, and call its methods instead of using the observables.
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
122
|
+
__publicField(this, "_matchesUpdate$", new Subject());
|
|
123
|
+
__publicField(this, "matchesUpdate$", this._matchesUpdate$.asObservable());
|
|
124
|
+
__publicField(this, "_activelyChangingMatch$", new Subject());
|
|
125
|
+
__publicField(this, "activelyChangingMatch$", this._activelyChangingMatch$.asObservable());
|
|
116
126
|
/** Hold matches by the worksheet they are in. Make it easier to track the next (or previous) match when searching in the whole workbook. */
|
|
117
|
-
|
|
127
|
+
__publicField(this, "_matchesByWorksheet", /* @__PURE__ */ new Map());
|
|
118
128
|
/** Hold all matches in the currently searching scope. */
|
|
119
|
-
|
|
129
|
+
__publicField(this, "_matches", []);
|
|
120
130
|
/** Position of the current focused ISheetCellMatch, starting from 1. */
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
131
|
+
__publicField(this, "_matchesPosition", 0);
|
|
132
|
+
__publicField(this, "_activeHighlightIndex", -1);
|
|
133
|
+
__publicField(this, "_highlightShapes", []);
|
|
134
|
+
__publicField(this, "_currentHighlightShape", null);
|
|
125
135
|
/** This properties holds the query params during this searching session. */
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
this._workbook =
|
|
136
|
+
__publicField(this, "_query", null);
|
|
137
|
+
__publicField(this, "_workbookSelections");
|
|
138
|
+
this._workbook = _workbook, this._sheetSkeletonManagerService = _sheetSkeletonManagerService, this._univerInstanceService = _univerInstanceService, this._renderManagerService = _renderManagerService, this._commandService = _commandService, this._contextService = _contextService, this._themeService = _themeService, this._workbookSelections = _selectionManagerService.getWorkbookSelections(this.unitId);
|
|
129
139
|
}
|
|
130
140
|
get _matchesCount() {
|
|
131
141
|
return this._matches.length;
|
|
@@ -148,466 +158,473 @@ let W = class extends ye {
|
|
|
148
158
|
getMatches() {
|
|
149
159
|
return this._matches;
|
|
150
160
|
}
|
|
151
|
-
start(
|
|
152
|
-
switch (this._query =
|
|
153
|
-
case
|
|
154
|
-
this.findInWorkbook(
|
|
161
|
+
start(query) {
|
|
162
|
+
switch (this._query = query, query.findBy === FindBy.FORMULA ? this._toggleDisplayRawFormula(!0) : this._toggleDisplayRawFormula(!1), query.findScope) {
|
|
163
|
+
case FindScope.UNIT:
|
|
164
|
+
this.findInWorkbook(query);
|
|
155
165
|
break;
|
|
156
|
-
case
|
|
166
|
+
case FindScope.SUBUNIT:
|
|
157
167
|
default:
|
|
158
|
-
this.findInActiveWorksheet(
|
|
168
|
+
this.findInActiveWorksheet(query);
|
|
159
169
|
break;
|
|
160
170
|
}
|
|
161
171
|
}
|
|
162
|
-
_toggleDisplayRawFormula(
|
|
163
|
-
this._contextService.setContextValue(
|
|
172
|
+
_toggleDisplayRawFormula(force) {
|
|
173
|
+
this._contextService.setContextValue(RENDER_RAW_FORMULA_KEY, force);
|
|
164
174
|
}
|
|
165
175
|
/**
|
|
166
176
|
* Find all matches in the current workbook no matter which worksheet is activated.
|
|
167
177
|
* @param query the query object
|
|
168
178
|
* @returns the query complete event
|
|
169
179
|
*/
|
|
170
|
-
findInWorkbook(
|
|
171
|
-
const
|
|
172
|
-
let
|
|
173
|
-
const
|
|
174
|
-
const
|
|
175
|
-
const
|
|
176
|
-
return
|
|
180
|
+
findInWorkbook(query) {
|
|
181
|
+
const unitId = this._workbook.getUnitId();
|
|
182
|
+
let complete, firstSearch = !0;
|
|
183
|
+
const findInWorkbook = /* @__PURE__ */ __name(() => {
|
|
184
|
+
const allCompletes = this._workbook.getSheets().filter((worksheet) => !worksheet.isSheetHidden()).map((worksheet) => {
|
|
185
|
+
const complete2 = this._findInWorksheet(worksheet, query, unitId), sheetId = worksheet.getSheetId(), { results } = complete2;
|
|
186
|
+
return results.length ? this._matchesByWorksheet.set(sheetId, complete2.results) : this._matchesByWorksheet.delete(sheetId), complete2;
|
|
177
187
|
});
|
|
178
|
-
this._matches =
|
|
179
|
-
};
|
|
188
|
+
this._matches = allCompletes.map((c) => c.results).flat(), this._updateFindHighlight(), firstSearch ? (complete = { results: this._matches }, firstSearch = !1) : this._matchesUpdate$.next(this._matches);
|
|
189
|
+
}, "findInWorkbook");
|
|
180
190
|
return this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(() => {
|
|
181
191
|
this._updateFindHighlight(), this._updateCurrentHighlightShape(this._activeHighlightIndex);
|
|
182
192
|
})), this.disposeWithMe(
|
|
183
|
-
|
|
184
|
-
|
|
193
|
+
fromCallback(this._commandService.onCommandExecuted.bind(this._commandService.onCommandExecuted)).pipe(
|
|
194
|
+
filter(([command, options]) => command.id === SetWorksheetActiveOperation.id && !(options != null && options.fromFindReplace))
|
|
185
195
|
).subscribe(() => {
|
|
186
|
-
const
|
|
187
|
-
if (!
|
|
196
|
+
const activeSheet = this._workbook.getActiveSheet();
|
|
197
|
+
if (!activeSheet)
|
|
188
198
|
return;
|
|
189
|
-
const
|
|
190
|
-
this._matchesByWorksheet.has(
|
|
199
|
+
const activeSheetId = activeSheet.getSheetId();
|
|
200
|
+
this._matchesByWorksheet.has(activeSheetId) && this._findNextMatchOnActiveSheetChange(activeSheet);
|
|
191
201
|
})
|
|
192
202
|
), this.disposeWithMe(
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
([
|
|
203
|
+
fromCallback(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(
|
|
204
|
+
filter(
|
|
205
|
+
([command]) => command.type === CommandType.MUTATION && command.params.unitId === this._workbook.getUnitId()
|
|
196
206
|
),
|
|
197
|
-
|
|
198
|
-
).subscribe(() =>
|
|
199
|
-
),
|
|
207
|
+
throttleTime(600, void 0, { leading: !1, trailing: !0 })
|
|
208
|
+
).subscribe(() => findInWorkbook())
|
|
209
|
+
), findInWorkbook(), complete;
|
|
200
210
|
}
|
|
201
211
|
/**
|
|
202
212
|
* This method is used in `findInWorkbook`. When the active sheet changes, this method helps to find the next match
|
|
203
213
|
* in the new worksheet.
|
|
204
214
|
*/
|
|
205
|
-
_findNextMatchOnActiveSheetChange(
|
|
206
|
-
let
|
|
207
|
-
const
|
|
208
|
-
|
|
215
|
+
_findNextMatchOnActiveSheetChange(activeSheet) {
|
|
216
|
+
let match, index, globalIndex = 0;
|
|
217
|
+
const matchesByWorksheet = this._matchesByWorksheet.get(activeSheet.getSheetId()), selections = this._workbookSelections.getCurrentSelections();
|
|
218
|
+
selections != null && selections.length ? ([match, globalIndex] = this._findNextMatchByRange(matchesByWorksheet, selections[0].range), index = matchesByWorksheet.findIndex((m) => m === match)) : (match = matchesByWorksheet[0], index = 0, globalIndex = this._matches.findIndex((m) => m === match)), this._matchesPosition = globalIndex + 1, this._activelyChangingMatch$.next(match), this._activeHighlightIndex = index, this._updateFindHighlight(), this._updateCurrentHighlightShape(index);
|
|
209
219
|
}
|
|
210
220
|
/**
|
|
211
221
|
* Find all matches (only) in the currently activated worksheet.
|
|
212
222
|
* @param query the query object
|
|
213
223
|
* @returns the query complete event
|
|
214
224
|
*/
|
|
215
|
-
findInActiveWorksheet(
|
|
216
|
-
const
|
|
217
|
-
var
|
|
218
|
-
const
|
|
219
|
-
if (!
|
|
220
|
-
const
|
|
221
|
-
return (
|
|
222
|
-
};
|
|
223
|
-
let
|
|
224
|
-
const
|
|
225
|
-
const
|
|
226
|
-
if (!
|
|
227
|
-
const
|
|
228
|
-
|
|
229
|
-
const
|
|
230
|
-
return this._matches =
|
|
231
|
-
};
|
|
225
|
+
findInActiveWorksheet(query) {
|
|
226
|
+
const unitId = this._workbook.getUnitId(), checkShouldFindInSelections = /* @__PURE__ */ __name(() => {
|
|
227
|
+
var _a5;
|
|
228
|
+
const currentWorksheet = this._workbook.getActiveSheet();
|
|
229
|
+
if (!currentWorksheet) return !1;
|
|
230
|
+
const currentSelections = this._workbookSelections.getCurrentSelections();
|
|
231
|
+
return (_a5 = currentSelections == null ? void 0 : currentSelections.some((selection) => !isSelectionSingleCell(selection, currentWorksheet))) != null ? _a5 : !1;
|
|
232
|
+
}, "checkShouldFindInSelections");
|
|
233
|
+
let complete, firstSearch = !0, findBySelections = !1;
|
|
234
|
+
const performFindInWorksheet = /* @__PURE__ */ __name(() => {
|
|
235
|
+
const currentWorksheet = this._workbook.getActiveSheet();
|
|
236
|
+
if (!currentWorksheet) return { results: [] };
|
|
237
|
+
const lastMatch = this.currentMatch;
|
|
238
|
+
findBySelections = checkShouldFindInSelections();
|
|
239
|
+
const currentSelections = this._workbookSelections.getCurrentSelections(), newComplete = findBySelections ? this._findInSelections(currentWorksheet, currentSelections, query, unitId) : this._findInWorksheet(currentWorksheet, query, unitId);
|
|
240
|
+
return this._matches = newComplete.results, this._matchesPosition = this._tryRestoreLastMatchesPosition(lastMatch, this._matches), firstSearch ? (complete = newComplete, firstSearch = !1) : this._matchesUpdate$.next(this._matches), this._updateFindHighlight(), newComplete;
|
|
241
|
+
}, "performFindInWorksheet");
|
|
232
242
|
return this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(() => this._updateFindHighlight())), this.disposeWithMe(
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
if (
|
|
243
|
+
merge(
|
|
244
|
+
fromCallback(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(
|
|
245
|
+
filter(([command]) => {
|
|
246
|
+
if (command.type === CommandType.MUTATION && command.params.unitId === this._workbook.getUnitId())
|
|
237
247
|
return !0;
|
|
238
|
-
if (
|
|
239
|
-
const
|
|
240
|
-
return
|
|
248
|
+
if (command.id === SetSelectionsOperation.id && command.params.unitId === unitId) {
|
|
249
|
+
const shouldFindBySelections = checkShouldFindInSelections();
|
|
250
|
+
return shouldFindBySelections === !1 && findBySelections === !1 ? !1 : (findBySelections = shouldFindBySelections, !0);
|
|
241
251
|
}
|
|
242
252
|
return !1;
|
|
243
253
|
})
|
|
244
254
|
),
|
|
245
255
|
// activeSheet$ is a BehaviorSubject, so we need to skip the first
|
|
246
|
-
this._workbook.activeSheet$.pipe(
|
|
247
|
-
).pipe(
|
|
248
|
-
),
|
|
249
|
-
}
|
|
250
|
-
_findInRange(
|
|
251
|
-
const
|
|
252
|
-
for (const
|
|
253
|
-
const { row
|
|
254
|
-
if (
|
|
256
|
+
this._workbook.activeSheet$.pipe(skip(1))
|
|
257
|
+
).pipe(debounceTime(200)).subscribe(() => performFindInWorksheet())
|
|
258
|
+
), performFindInWorksheet(), complete;
|
|
259
|
+
}
|
|
260
|
+
_findInRange(worksheet, query, range, unitId, dedupeFn) {
|
|
261
|
+
const results = [], subUnitId = worksheet.getSheetId(), iter = (query.findDirection === FindDirection.COLUMN ? worksheet.iterateByColumn : worksheet.iterateByRow).bind(worksheet)(range);
|
|
262
|
+
for (const value of iter) {
|
|
263
|
+
const { row, col, colSpan, rowSpan, value: cellData } = value;
|
|
264
|
+
if (dedupeFn != null && dedupeFn(row, col) || !cellData || worksheet.getRowFiltered(row))
|
|
255
265
|
continue;
|
|
256
|
-
const { hit
|
|
257
|
-
if (
|
|
258
|
-
const
|
|
259
|
-
provider:
|
|
260
|
-
unitId
|
|
261
|
-
replaceable
|
|
262
|
-
isFormula
|
|
266
|
+
const { hit, replaceable, isFormula } = hitCell(worksheet, row, col, query, cellData);
|
|
267
|
+
if (hit) {
|
|
268
|
+
const result = {
|
|
269
|
+
provider: SHEETS_FIND_REPLACE_PROVIDER_NAME,
|
|
270
|
+
unitId,
|
|
271
|
+
replaceable,
|
|
272
|
+
isFormula,
|
|
263
273
|
range: {
|
|
264
|
-
subUnitId
|
|
274
|
+
subUnitId,
|
|
265
275
|
range: {
|
|
266
|
-
startRow:
|
|
267
|
-
startColumn:
|
|
268
|
-
endColumn:
|
|
269
|
-
endRow:
|
|
276
|
+
startRow: row,
|
|
277
|
+
startColumn: col,
|
|
278
|
+
endColumn: col + (colSpan != null ? colSpan : 1) - 1,
|
|
279
|
+
endRow: row + (rowSpan != null ? rowSpan : 1) - 1
|
|
270
280
|
}
|
|
271
281
|
}
|
|
272
282
|
};
|
|
273
|
-
|
|
283
|
+
results.push(result);
|
|
274
284
|
}
|
|
275
285
|
}
|
|
276
|
-
return { results
|
|
277
|
-
}
|
|
278
|
-
_findInSelections(
|
|
279
|
-
const { findDirection
|
|
280
|
-
return { results:
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
(
|
|
286
|
-
const
|
|
287
|
-
return
|
|
286
|
+
return { results };
|
|
287
|
+
}
|
|
288
|
+
_findInSelections(worksheet, selections, query, unitId) {
|
|
289
|
+
const { findDirection } = query, sortFn = findDirection === FindDirection.ROW ? isBehindPositionWithRowPriority : isBehindPositionWithColumnPriority, dedupeSet = /* @__PURE__ */ new Set();
|
|
290
|
+
return { results: selections.map((selection) => this._findInRange(
|
|
291
|
+
worksheet,
|
|
292
|
+
query,
|
|
293
|
+
selection.range,
|
|
294
|
+
unitId,
|
|
295
|
+
(row, col) => {
|
|
296
|
+
const key = `${row}-${col}`;
|
|
297
|
+
return dedupeSet.has(key) ? !0 : (dedupeSet.add(key), !1);
|
|
288
298
|
}
|
|
289
|
-
).results).flat().sort((
|
|
299
|
+
).results).flat().sort((a, b) => sortFn(a.range.range, b.range.range) ? -1 : 1) };
|
|
290
300
|
}
|
|
291
301
|
/** Find matches in a given worksheet. */
|
|
292
|
-
_findInWorksheet(
|
|
293
|
-
const
|
|
294
|
-
return this._findInRange(
|
|
302
|
+
_findInWorksheet(worksheet, query, unitId) {
|
|
303
|
+
const rowCount = worksheet.getRowCount(), colCount = worksheet.getColumnCount(), range = { startRow: 0, startColumn: 0, endRow: rowCount - 1, endColumn: colCount - 1 };
|
|
304
|
+
return this._findInRange(worksheet, query, range, unitId);
|
|
295
305
|
}
|
|
296
306
|
_disposeHighlights() {
|
|
297
|
-
var
|
|
298
|
-
this._highlightShapes.forEach((
|
|
299
|
-
|
|
300
|
-
}), this._highlightShapes = [], (
|
|
307
|
+
var _a5;
|
|
308
|
+
this._highlightShapes.forEach((shape) => {
|
|
309
|
+
shape.getScene().makeDirty(), shape.dispose();
|
|
310
|
+
}), this._highlightShapes = [], (_a5 = this._currentHighlightShape) == null || _a5.dispose(), this._currentHighlightShape = null;
|
|
301
311
|
}
|
|
302
312
|
_updateFindHighlight() {
|
|
303
|
-
var
|
|
313
|
+
var _a5;
|
|
304
314
|
this._disposeHighlights();
|
|
305
|
-
const
|
|
306
|
-
if (!
|
|
315
|
+
const skeleton = (_a5 = this._sheetSkeletonManagerService.getCurrent()) == null ? void 0 : _a5.skeleton;
|
|
316
|
+
if (!skeleton)
|
|
307
317
|
return;
|
|
308
|
-
const
|
|
309
|
-
if (
|
|
318
|
+
const unitId = this._workbook.getUnitId(), currentRender = this._renderManagerService.getRenderById(unitId);
|
|
319
|
+
if (currentRender == null)
|
|
310
320
|
return;
|
|
311
|
-
const { scene
|
|
312
|
-
if (!
|
|
321
|
+
const { scene } = currentRender, matches = this._matches, searchBackgroundColor = this._themeService.getCurrentTheme().gold400, color = new ColorKit(searchBackgroundColor).toRgb(), worksheet = this._workbook.getActiveSheet();
|
|
322
|
+
if (!worksheet)
|
|
313
323
|
return;
|
|
314
|
-
const
|
|
315
|
-
const { startColumn
|
|
316
|
-
left:
|
|
317
|
-
top:
|
|
318
|
-
color
|
|
319
|
-
width
|
|
320
|
-
height
|
|
324
|
+
const activeSheetId = worksheet.getSheetId(), highlightShapes = matches.filter((match) => match.range.subUnitId === activeSheetId).map((find, index) => {
|
|
325
|
+
const { startColumn, startRow, endColumn, endRow } = find.range.range, startPosition = getCoordByCell(startRow, startColumn, scene, skeleton), endPosition = getCoordByCell(endRow, endColumn, scene, skeleton), { startX, startY } = startPosition, { endX, endY } = endPosition, rowHidden = !worksheet.getRowRawVisible(startRow), columnHidden = !worksheet.getColVisible(startColumn), inHiddenRange = rowHidden || columnHidden, width = columnHidden ? 2 : endX - startX, height = rowHidden ? 2 : endY - startY, props = {
|
|
326
|
+
left: startX,
|
|
327
|
+
top: startY,
|
|
328
|
+
color,
|
|
329
|
+
width,
|
|
330
|
+
height,
|
|
321
331
|
evented: !1,
|
|
322
|
-
inHiddenRange
|
|
323
|
-
zIndex:
|
|
332
|
+
inHiddenRange,
|
|
333
|
+
zIndex: FIND_REPLACE_Z_INDEX
|
|
324
334
|
};
|
|
325
|
-
return new
|
|
335
|
+
return new SheetFindReplaceHighlightShape(`find-highlight-${index}`, props);
|
|
326
336
|
});
|
|
327
|
-
|
|
337
|
+
scene.addObjects(highlightShapes), this._highlightShapes = highlightShapes, scene.makeDirty();
|
|
328
338
|
}
|
|
329
|
-
_updateCurrentHighlightShape(
|
|
330
|
-
var
|
|
331
|
-
if ((
|
|
332
|
-
const
|
|
333
|
-
if (!
|
|
339
|
+
_updateCurrentHighlightShape(matchIndex) {
|
|
340
|
+
var _a5;
|
|
341
|
+
if ((_a5 = this._currentHighlightShape) == null || _a5.setShapeProps({ activated: !1 }), this._currentHighlightShape = null, matchIndex !== void 0) {
|
|
342
|
+
const shape = this._highlightShapes[matchIndex];
|
|
343
|
+
if (!shape)
|
|
334
344
|
return;
|
|
335
|
-
this._currentHighlightShape =
|
|
345
|
+
this._currentHighlightShape = shape, shape.setShapeProps({ activated: !0 });
|
|
336
346
|
}
|
|
337
347
|
}
|
|
338
348
|
_getSheetObject() {
|
|
339
|
-
return
|
|
340
|
-
}
|
|
341
|
-
_focusMatch(
|
|
342
|
-
var
|
|
343
|
-
const
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
{ unitId: this._workbook.getUnitId(), subUnitId
|
|
349
|
+
return getSheetObject(this._univerInstanceService, this._renderManagerService);
|
|
350
|
+
}
|
|
351
|
+
_focusMatch(match) {
|
|
352
|
+
var _a5;
|
|
353
|
+
const subUnitId = match.range.subUnitId;
|
|
354
|
+
subUnitId !== ((_a5 = this._workbook.getActiveSheet()) == null ? void 0 : _a5.getSheetId()) && this._commandService.executeCommand(
|
|
355
|
+
SetWorksheetActivateCommand.id,
|
|
356
|
+
{ unitId: this._workbook.getUnitId(), subUnitId },
|
|
347
357
|
{ fromFindReplace: !0 }
|
|
348
358
|
), this._commandService.executeCommand(
|
|
349
|
-
|
|
350
|
-
{ range:
|
|
359
|
+
ScrollToCellCommand.id,
|
|
360
|
+
{ range: match.range.range },
|
|
351
361
|
{ fromFindReplace: !0 }
|
|
352
362
|
);
|
|
353
363
|
}
|
|
354
|
-
_tryRestoreLastMatchesPosition(
|
|
355
|
-
if (!
|
|
356
|
-
const { subUnitId:
|
|
357
|
-
if (
|
|
364
|
+
_tryRestoreLastMatchesPosition(lastMatch, newMatches) {
|
|
365
|
+
if (!lastMatch) return 0;
|
|
366
|
+
const { subUnitId: lastSubUnitId } = lastMatch.range, { startColumn: lastStartColumn, startRow: lastStartRow } = lastMatch.range.range, index = newMatches.findIndex((match) => {
|
|
367
|
+
if (lastSubUnitId !== match.range.subUnitId)
|
|
358
368
|
return !1;
|
|
359
|
-
const { startColumn
|
|
360
|
-
return
|
|
369
|
+
const { startColumn, startRow } = match.range.range;
|
|
370
|
+
return startColumn === lastStartColumn && startRow === lastStartRow;
|
|
361
371
|
});
|
|
362
|
-
return
|
|
372
|
+
return index > -1 ? index + 1 : 0;
|
|
363
373
|
}
|
|
364
|
-
moveToNextMatch(
|
|
365
|
-
var
|
|
374
|
+
moveToNextMatch(params) {
|
|
375
|
+
var _a5, _b, _c, _d, _e;
|
|
366
376
|
if (!this._matches.length)
|
|
367
377
|
return null;
|
|
368
|
-
const
|
|
369
|
-
if (
|
|
370
|
-
const [
|
|
371
|
-
return this._matchesPosition =
|
|
378
|
+
const loop = (_a5 = params == null ? void 0 : params.loop) != null ? _a5 : !1, stayIfOnMatch = (_b = params == null ? void 0 : params.stayIfOnMatch) != null ? _b : !1, noFocus = (_c = params == null ? void 0 : params.noFocus) != null ? _c : !1, ignoreSelection = (_d = params == null ? void 0 : params.ignoreSelection) != null ? _d : !1, matchToMove = this._findNextMatch(loop, stayIfOnMatch, ignoreSelection);
|
|
379
|
+
if (matchToMove) {
|
|
380
|
+
const [match, index] = matchToMove;
|
|
381
|
+
return this._matchesPosition = index + 1, this._query.findScope === FindScope.UNIT ? this._activeHighlightIndex = this._matchesByWorksheet.get(match.range.subUnitId).findIndex((m) => m === match) : this._activeHighlightIndex = index, noFocus || this._focusMatch(match), ((_e = this._workbook.getActiveSheet()) == null ? void 0 : _e.getSheetId()) === match.range.subUnitId && this._updateCurrentHighlightShape(this._activeHighlightIndex), match;
|
|
372
382
|
}
|
|
373
383
|
return this._matchesPosition = 0, this._updateCurrentHighlightShape(), null;
|
|
374
384
|
}
|
|
375
|
-
moveToPreviousMatch(
|
|
376
|
-
var
|
|
385
|
+
moveToPreviousMatch(params) {
|
|
386
|
+
var _a5, _b, _c, _d, _e;
|
|
377
387
|
if (!this._matches.length)
|
|
378
388
|
return null;
|
|
379
|
-
const
|
|
380
|
-
if (
|
|
381
|
-
const [
|
|
382
|
-
return this._matchesPosition =
|
|
389
|
+
const loop = (_a5 = params == null ? void 0 : params.loop) != null ? _a5 : !1, stayIfOnMatch = (_b = params == null ? void 0 : params.stayIfOnMatch) != null ? _b : !1, noFocus = (_c = params == null ? void 0 : params.noFocus) != null ? _c : !1, ignoreSelection = (_d = params == null ? void 0 : params.ignoreSelection) != null ? _d : !1, matchToMove = this._findPreviousMatch(loop, stayIfOnMatch, ignoreSelection);
|
|
390
|
+
if (matchToMove) {
|
|
391
|
+
const [match, index] = matchToMove;
|
|
392
|
+
return this._matchesPosition = index + 1, this._query.findScope === FindScope.UNIT ? this._activeHighlightIndex = this._matchesByWorksheet.get(match.range.subUnitId).findIndex((m) => m === match) : this._activeHighlightIndex = index, noFocus || this._focusMatch(match), ((_e = this._workbook.getActiveSheet()) == null ? void 0 : _e.getSheetId()) === match.range.subUnitId && this._updateCurrentHighlightShape(this._activeHighlightIndex), match;
|
|
383
393
|
}
|
|
384
394
|
return this._matchesPosition = 0, this._updateCurrentHighlightShape(), null;
|
|
385
395
|
}
|
|
386
|
-
_findPreviousMatch(
|
|
387
|
-
var
|
|
396
|
+
_findPreviousMatch(loop = !1, stayIfOnMatch = !1, ignoreSelection = !1) {
|
|
397
|
+
var _a5;
|
|
388
398
|
if (this.currentMatch) {
|
|
389
|
-
const
|
|
390
|
-
if (
|
|
391
|
-
return [this.currentMatch,
|
|
392
|
-
const
|
|
393
|
-
if (!
|
|
399
|
+
const currentMatchIndex = this._matches.findIndex((match) => match === this.currentMatch);
|
|
400
|
+
if (stayIfOnMatch)
|
|
401
|
+
return [this.currentMatch, currentMatchIndex];
|
|
402
|
+
const nextMatchIndex = currentMatchIndex - 1;
|
|
403
|
+
if (!loop && nextMatchIndex < 0)
|
|
394
404
|
return null;
|
|
395
|
-
const
|
|
396
|
-
return [this._matches[
|
|
405
|
+
const length = this._matches.length, modded = (nextMatchIndex + length) % length;
|
|
406
|
+
return [this._matches[modded], modded];
|
|
397
407
|
}
|
|
398
|
-
const
|
|
399
|
-
if (
|
|
400
|
-
const
|
|
401
|
-
return [this._matches[
|
|
408
|
+
const lastSelection = this._workbookSelections.getCurrentLastSelection();
|
|
409
|
+
if (ignoreSelection || !lastSelection) {
|
|
410
|
+
const lastIndex = this._matches.length - 1;
|
|
411
|
+
return [this._matches[lastIndex], lastIndex];
|
|
402
412
|
}
|
|
403
|
-
if (this._query.findScope !==
|
|
404
|
-
return this._findPreviousMatchByRange(this._matches,
|
|
405
|
-
const
|
|
406
|
-
if (!
|
|
413
|
+
if (this._query.findScope !== FindScope.UNIT)
|
|
414
|
+
return this._findPreviousMatchByRange(this._matches, lastSelection.range);
|
|
415
|
+
const currentSheetId = (_a5 = this._workbook.getActiveSheet()) == null ? void 0 : _a5.getSheetId();
|
|
416
|
+
if (!currentSheetId)
|
|
407
417
|
return null;
|
|
408
|
-
const
|
|
409
|
-
return
|
|
418
|
+
const worksheetThatHasMatch = this._findPreviousWorksheetThatHasAMatch(currentSheetId, loop);
|
|
419
|
+
return worksheetThatHasMatch ? this._findPreviousMatchByRange(this._matchesByWorksheet.get(worksheetThatHasMatch), lastSelection.range) : null;
|
|
410
420
|
}
|
|
411
|
-
_findNextMatch(
|
|
412
|
-
var
|
|
421
|
+
_findNextMatch(loop = !1, stayIfOnMatch = !1, ignoreSelection = !1) {
|
|
422
|
+
var _a5;
|
|
413
423
|
if (this.currentMatch) {
|
|
414
|
-
const
|
|
415
|
-
if (
|
|
416
|
-
return [this.currentMatch,
|
|
417
|
-
const
|
|
418
|
-
if (!
|
|
424
|
+
const currentMatchIndex = this._matches.findIndex((match) => match === this.currentMatch);
|
|
425
|
+
if (stayIfOnMatch)
|
|
426
|
+
return [this.currentMatch, currentMatchIndex];
|
|
427
|
+
const nextMatchIndex = currentMatchIndex + 1, length = this._matches.length;
|
|
428
|
+
if (!loop && nextMatchIndex >= length)
|
|
419
429
|
return null;
|
|
420
|
-
const
|
|
421
|
-
return [this._matches[
|
|
430
|
+
const modded = nextMatchIndex % length;
|
|
431
|
+
return [this._matches[modded], modded];
|
|
422
432
|
}
|
|
423
|
-
const
|
|
424
|
-
if (
|
|
433
|
+
const last = this._workbookSelections.getCurrentLastSelection();
|
|
434
|
+
if (ignoreSelection || !last)
|
|
425
435
|
return [this._matches[0], 0];
|
|
426
|
-
if (this._query.findScope !==
|
|
427
|
-
return this._findNextMatchByRange(this._matches,
|
|
428
|
-
const
|
|
429
|
-
if (!
|
|
436
|
+
if (this._query.findScope !== FindScope.UNIT)
|
|
437
|
+
return this._findNextMatchByRange(this._matches, last.range, stayIfOnMatch);
|
|
438
|
+
const currentSheetId = (_a5 = this._workbook.getActiveSheet()) == null ? void 0 : _a5.getSheetId();
|
|
439
|
+
if (!currentSheetId)
|
|
430
440
|
return null;
|
|
431
|
-
const
|
|
432
|
-
return
|
|
433
|
-
}
|
|
434
|
-
_findPreviousWorksheetThatHasAMatch(
|
|
435
|
-
const
|
|
436
|
-
return
|
|
437
|
-
}
|
|
438
|
-
_findNextWorksheetThatHasAMatch(
|
|
439
|
-
const
|
|
440
|
-
return
|
|
441
|
-
}
|
|
442
|
-
_findNextMatchByRange(
|
|
443
|
-
const
|
|
444
|
-
let
|
|
445
|
-
const
|
|
446
|
-
if (!(
|
|
441
|
+
const worksheetThatHasMatch = this._findNextWorksheetThatHasAMatch(currentSheetId, loop);
|
|
442
|
+
return worksheetThatHasMatch ? this._findNextMatchByRange(this._matchesByWorksheet.get(worksheetThatHasMatch), last.range) : null;
|
|
443
|
+
}
|
|
444
|
+
_findPreviousWorksheetThatHasAMatch(currentWorksheet, loop = !1) {
|
|
445
|
+
const rawWorksheetsInOrder = this._workbook.getSheetOrders(), currentSheetIndex = rawWorksheetsInOrder.findIndex((sheet) => sheet === currentWorksheet), first = (loop ? rotate(rawWorksheetsInOrder, currentSheetIndex + 1) : rawWorksheetsInOrder.slice(0, currentSheetIndex + 1)).findLast((worksheet) => this._matchesByWorksheet.has(worksheet));
|
|
446
|
+
return first != null ? first : null;
|
|
447
|
+
}
|
|
448
|
+
_findNextWorksheetThatHasAMatch(currentWorksheet, loop = !1) {
|
|
449
|
+
const rawWorksheetsInOrder = this._workbook.getSheetOrders(), currentSheetIndex = rawWorksheetsInOrder.findIndex((sheet) => sheet === currentWorksheet), first = (loop ? rotate(rawWorksheetsInOrder, currentSheetIndex) : rawWorksheetsInOrder.slice(currentSheetIndex)).find((worksheet) => this._matchesByWorksheet.has(worksheet));
|
|
450
|
+
return first != null ? first : null;
|
|
451
|
+
}
|
|
452
|
+
_findNextMatchByRange(matches, range, stayIfOnMatch = !1) {
|
|
453
|
+
const findByRow = this._query.findDirection === FindDirection.ROW;
|
|
454
|
+
let index = matches.findIndex((match2) => {
|
|
455
|
+
const matchRange = match2.range.range;
|
|
456
|
+
if (!(findByRow ? isBehindPositionWithRowPriority(range, matchRange) : isBehindPositionWithColumnPriority(range, matchRange)))
|
|
447
457
|
return !1;
|
|
448
|
-
const
|
|
449
|
-
return
|
|
458
|
+
const isSame = isSamePosition(range, matchRange);
|
|
459
|
+
return stayIfOnMatch ? isSame : !isSame;
|
|
450
460
|
});
|
|
451
|
-
|
|
452
|
-
const
|
|
453
|
-
return [
|
|
454
|
-
}
|
|
455
|
-
_findPreviousMatchByRange(
|
|
456
|
-
const
|
|
457
|
-
let
|
|
458
|
-
const
|
|
459
|
-
if (!(
|
|
461
|
+
index === -1 && (index = matches.length - 1);
|
|
462
|
+
const match = matches[index];
|
|
463
|
+
return [match, this._matches.findIndex((m) => m === match)];
|
|
464
|
+
}
|
|
465
|
+
_findPreviousMatchByRange(matches, range, stayIfOnMatch = !1) {
|
|
466
|
+
const findByRow = this._query.findDirection === FindDirection.ROW;
|
|
467
|
+
let index = this._matches.findLastIndex((match2) => {
|
|
468
|
+
const matchRange = match2.range.range;
|
|
469
|
+
if (!(findByRow ? isBeforePositionWithRowPriority(range, matchRange) : isBeforePositionWithColumnPriority(range, matchRange)))
|
|
460
470
|
return !1;
|
|
461
|
-
const
|
|
462
|
-
return
|
|
471
|
+
const isSame = isSamePosition(range, matchRange);
|
|
472
|
+
return stayIfOnMatch ? isSame : !isSame;
|
|
463
473
|
});
|
|
464
|
-
|
|
465
|
-
const
|
|
466
|
-
return [
|
|
474
|
+
index === -1 && (index = 0);
|
|
475
|
+
const match = matches[index];
|
|
476
|
+
return [match, this._matches.findIndex((m) => m === match)];
|
|
467
477
|
}
|
|
468
|
-
async replace(
|
|
478
|
+
async replace(replaceString) {
|
|
469
479
|
if (this._matchesCount === 0 || !this.currentMatch || !this._query || !this.currentMatch.replaceable)
|
|
470
480
|
return !1;
|
|
471
|
-
const
|
|
481
|
+
const range = this.currentMatch.range, targetWorksheet = this._workbook.getSheetBySheetId(this.currentMatch.range.subUnitId), newContent = this._getReplacedCellData(
|
|
472
482
|
this.currentMatch,
|
|
473
|
-
|
|
474
|
-
this._query.findBy ===
|
|
483
|
+
targetWorksheet,
|
|
484
|
+
this._query.findBy === FindBy.FORMULA,
|
|
475
485
|
this._query.findString,
|
|
476
|
-
|
|
486
|
+
replaceString,
|
|
477
487
|
this._query.caseSensitive ? "g" : "ig"
|
|
478
|
-
),
|
|
488
|
+
), params = {
|
|
479
489
|
unitId: this.currentMatch.unitId,
|
|
480
|
-
subUnitId:
|
|
490
|
+
subUnitId: range.subUnitId,
|
|
481
491
|
value: {
|
|
482
|
-
[
|
|
483
|
-
[
|
|
492
|
+
[range.range.startRow]: {
|
|
493
|
+
[range.range.startColumn]: newContent
|
|
484
494
|
}
|
|
485
495
|
}
|
|
486
496
|
};
|
|
487
|
-
return this._commandService.executeCommand(
|
|
497
|
+
return this._commandService.executeCommand(SetRangeValuesCommand.id, params);
|
|
488
498
|
}
|
|
489
|
-
async replaceAll(
|
|
499
|
+
async replaceAll(replaceString) {
|
|
490
500
|
if (this._matchesCount === 0 || !this._query)
|
|
491
501
|
return { success: 0, failure: 0 };
|
|
492
|
-
const
|
|
493
|
-
return
|
|
494
|
-
const
|
|
495
|
-
|
|
496
|
-
const { startColumn
|
|
497
|
-
|
|
498
|
-
}),
|
|
499
|
-
count:
|
|
500
|
-
subUnitId
|
|
501
|
-
value:
|
|
502
|
+
const unitId = this._workbook.getUnitId(), { findString, caseSensitive, findBy } = this._query, shouldReplaceFormula = findBy === FindBy.FORMULA, replaceFlag = caseSensitive ? "g" : "ig", replacements = [];
|
|
503
|
+
return groupBy(this._matches.filter((m) => m.replaceable), (match) => match.range.subUnitId).forEach((matches, subUnitId) => {
|
|
504
|
+
const matrix = new ObjectMatrix(), worksheet = this._workbook.getSheetBySheetId(subUnitId);
|
|
505
|
+
matches.forEach((match) => {
|
|
506
|
+
const { startColumn, startRow } = match.range.range, newCellData = this._getReplacedCellData(match, worksheet, shouldReplaceFormula, findString, replaceString, replaceFlag);
|
|
507
|
+
newCellData && matrix.setValue(startRow, startColumn, newCellData);
|
|
508
|
+
}), replacements.push({
|
|
509
|
+
count: matches.length,
|
|
510
|
+
subUnitId,
|
|
511
|
+
value: matrix.getMatrix()
|
|
502
512
|
});
|
|
503
|
-
}),
|
|
504
|
-
unitId
|
|
505
|
-
replacements
|
|
513
|
+
}), replacements ? this._commandService.executeCommand(SheetReplaceCommand.id, {
|
|
514
|
+
unitId,
|
|
515
|
+
replacements
|
|
506
516
|
}) : { success: 0, failure: 0 };
|
|
507
517
|
}
|
|
508
|
-
_getReplacedCellData(
|
|
509
|
-
var
|
|
510
|
-
const
|
|
511
|
-
if (
|
|
512
|
-
return
|
|
513
|
-
if (!!((
|
|
514
|
-
const
|
|
515
|
-
return
|
|
518
|
+
_getReplacedCellData(match, worksheet, shouldReplaceFormula, findString, replaceString, replaceFlag) {
|
|
519
|
+
var _a5;
|
|
520
|
+
const range = match.range.range, { startRow, startColumn } = range, currentContent = worksheet.getCellRaw(startRow, startColumn);
|
|
521
|
+
if (match.isFormula)
|
|
522
|
+
return shouldReplaceFormula ? { f: currentContent.f.replace(new RegExp(escapeRegExp(findString), replaceFlag), replaceString), v: null } : null;
|
|
523
|
+
if (!!((_a5 = currentContent.p) != null && _a5.body)) {
|
|
524
|
+
const clonedRichText = Tools.deepClone(currentContent.p);
|
|
525
|
+
return replaceInDocumentBody(clonedRichText.body, findString, replaceString), { p: clonedRichText };
|
|
516
526
|
}
|
|
517
|
-
return { v:
|
|
518
|
-
}
|
|
519
|
-
};
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
],
|
|
528
|
-
function
|
|
529
|
-
return
|
|
527
|
+
return { v: currentContent.v.toString().replace(new RegExp(escapeRegExp(findString), replaceFlag), replaceString) };
|
|
528
|
+
}
|
|
529
|
+
}, __name(_a2, "SheetFindModel"), _a2);
|
|
530
|
+
SheetFindModel = __decorateClass$1([
|
|
531
|
+
__decorateParam$1(2, IUniverInstanceService),
|
|
532
|
+
__decorateParam$1(3, IRenderManagerService),
|
|
533
|
+
__decorateParam$1(4, ICommandService),
|
|
534
|
+
__decorateParam$1(5, IContextService),
|
|
535
|
+
__decorateParam$1(6, Inject(ThemeService)),
|
|
536
|
+
__decorateParam$1(7, Inject(SheetsSelectionsService))
|
|
537
|
+
], SheetFindModel);
|
|
538
|
+
function escapeRegExp(text) {
|
|
539
|
+
return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
|
|
530
540
|
}
|
|
531
|
-
|
|
532
|
-
|
|
541
|
+
__name(escapeRegExp, "escapeRegExp");
|
|
542
|
+
var _a3;
|
|
543
|
+
let SheetsFindReplaceProvider = (_a3 = class extends Disposable {
|
|
544
|
+
constructor(_univerInstanceService, _renderManagerService, _injector) {
|
|
533
545
|
super();
|
|
534
546
|
/**
|
|
535
547
|
* Hold all find results in this kind of univer business instances (Workbooks).
|
|
536
548
|
*/
|
|
537
|
-
|
|
538
|
-
this._univerInstanceService =
|
|
549
|
+
__publicField(this, "_findModelsByUnitId", /* @__PURE__ */ new Map());
|
|
550
|
+
this._univerInstanceService = _univerInstanceService, this._renderManagerService = _renderManagerService, this._injector = _injector;
|
|
539
551
|
}
|
|
540
|
-
async find(
|
|
552
|
+
async find(query) {
|
|
541
553
|
this._terminate();
|
|
542
|
-
const
|
|
543
|
-
return
|
|
544
|
-
const
|
|
545
|
-
return this._findModelsByUnitId.set(
|
|
554
|
+
const allWorkbooks = this._univerInstanceService.getAllUnitsForType(UniverInstanceType.UNIVER_SHEET), parsedQuery = this._preprocessQuery(query);
|
|
555
|
+
return allWorkbooks.map((workbook) => {
|
|
556
|
+
const skeletonManagerService = this._renderManagerService.getRenderById(workbook.getUnitId()).with(SheetSkeletonManagerService), sheetFind = this._injector.createInstance(SheetFindModel, workbook, skeletonManagerService);
|
|
557
|
+
return this._findModelsByUnitId.set(workbook.getUnitId(), sheetFind), sheetFind.start(parsedQuery), sheetFind;
|
|
546
558
|
});
|
|
547
559
|
}
|
|
548
560
|
terminate() {
|
|
549
561
|
this._terminate();
|
|
550
562
|
}
|
|
551
563
|
_terminate() {
|
|
552
|
-
this._findModelsByUnitId.forEach((
|
|
564
|
+
this._findModelsByUnitId.forEach((model) => model.dispose()), this._findModelsByUnitId.clear();
|
|
553
565
|
}
|
|
554
566
|
/**
|
|
555
567
|
* Parsed the query object before do actual searching in favor of performance.
|
|
556
568
|
* @param query the raw query object
|
|
557
569
|
* @returns the parsed query object
|
|
558
570
|
*/
|
|
559
|
-
_preprocessQuery(
|
|
560
|
-
let
|
|
561
|
-
return
|
|
562
|
-
...
|
|
563
|
-
findString
|
|
571
|
+
_preprocessQuery(query) {
|
|
572
|
+
let findString = query.caseSensitive ? query.findString : query.findString.toLowerCase();
|
|
573
|
+
return findString = findString.trim(), {
|
|
574
|
+
...query,
|
|
575
|
+
findString
|
|
564
576
|
};
|
|
565
577
|
}
|
|
566
|
-
};
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
],
|
|
572
|
-
const
|
|
573
|
-
function
|
|
574
|
-
const { findBy
|
|
575
|
-
return
|
|
578
|
+
}, __name(_a3, "SheetsFindReplaceProvider"), _a3);
|
|
579
|
+
SheetsFindReplaceProvider = __decorateClass$1([
|
|
580
|
+
__decorateParam$1(0, IUniverInstanceService),
|
|
581
|
+
__decorateParam$1(1, IRenderManagerService),
|
|
582
|
+
__decorateParam$1(2, Inject(Injector))
|
|
583
|
+
], SheetsFindReplaceProvider);
|
|
584
|
+
const VALUE_PASSING_OBJECT = { hit: !1, replaceable: !1, isFormula: !1, rawData: null };
|
|
585
|
+
function hitCell(worksheet, row, col, query, cellData) {
|
|
586
|
+
const { findBy } = query, findByFormula = findBy === FindBy.FORMULA, rawData = worksheet.getCellRaw(row, col);
|
|
587
|
+
return VALUE_PASSING_OBJECT.rawData = rawData, !(rawData != null && rawData.f) ? (VALUE_PASSING_OBJECT.isFormula = !1, matchCellData(cellData, query) ? rawData ? (VALUE_PASSING_OBJECT.hit = !0, VALUE_PASSING_OBJECT.replaceable = !0) : (VALUE_PASSING_OBJECT.hit = !0, VALUE_PASSING_OBJECT.replaceable = !1) : (VALUE_PASSING_OBJECT.hit = !1, VALUE_PASSING_OBJECT.replaceable = !1), VALUE_PASSING_OBJECT) : (VALUE_PASSING_OBJECT.isFormula = !0, findByFormula ? matchCellData({ v: rawData.f }, query) ? (VALUE_PASSING_OBJECT.hit = !0, VALUE_PASSING_OBJECT.replaceable = !0, VALUE_PASSING_OBJECT) : (VALUE_PASSING_OBJECT.hit = !1, VALUE_PASSING_OBJECT.replaceable = !1, VALUE_PASSING_OBJECT) : (VALUE_PASSING_OBJECT.replaceable = !1, matchCellData(cellData, query) ? VALUE_PASSING_OBJECT.hit = !0 : VALUE_PASSING_OBJECT.hit = !1, VALUE_PASSING_OBJECT));
|
|
576
588
|
}
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
589
|
+
__name(hitCell, "hitCell");
|
|
590
|
+
function matchCellData(cellData, query) {
|
|
591
|
+
let value = extractPureValue(cellData);
|
|
592
|
+
return value ? query.matchesTheWholeCell ? (value = trimLeadingTrailingWhitespace(value), query.caseSensitive ? value === query.findString : value.toLowerCase() === query.findString) : query.caseSensitive ? value.indexOf(query.findString) > -1 : value.toLowerCase().indexOf(query.findString) > -1 : !1;
|
|
580
593
|
}
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
594
|
+
__name(matchCellData, "matchCellData");
|
|
595
|
+
function extractPureValue(cell) {
|
|
596
|
+
var _a5, _b, _c;
|
|
597
|
+
const rawValue = (_c = (_b = (_a5 = cell == null ? void 0 : cell.p) == null ? void 0 : _a5.body) == null ? void 0 : _b.dataStream) != null ? _c : cell == null ? void 0 : cell.v;
|
|
598
|
+
return typeof rawValue == "number" ? `${rawValue}` : typeof rawValue == "boolean" ? rawValue ? "1" : "0" : rawValue;
|
|
585
599
|
}
|
|
586
|
-
|
|
587
|
-
|
|
600
|
+
__name(extractPureValue, "extractPureValue");
|
|
601
|
+
function trimLeadingTrailingWhitespace(value) {
|
|
602
|
+
return value.replace(/^ +/g, "").replace(/ +$/g, "");
|
|
588
603
|
}
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
604
|
+
__name(trimLeadingTrailingWhitespace, "trimLeadingTrailingWhitespace");
|
|
605
|
+
var __defProp2 = Object.defineProperty, __getOwnPropDesc = Object.getOwnPropertyDescriptor, __defNormalProp2 = /* @__PURE__ */ __name((obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, "__defNormalProp"), __decorateClass = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
606
|
+
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
607
|
+
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
608
|
+
return kind && result && __defProp2(target, key, result), result;
|
|
609
|
+
}, "__decorateClass"), __decorateParam = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam"), __publicField2 = /* @__PURE__ */ __name((obj, key, value) => __defNormalProp2(obj, typeof key != "symbol" ? key + "" : key, value), "__publicField");
|
|
610
|
+
const NAME = "SHEET_FIND_REPLACE_PLUGIN";
|
|
611
|
+
var _a4;
|
|
612
|
+
let UniverSheetsFindReplacePlugin = (_a4 = class extends Plugin {
|
|
613
|
+
constructor(_config, _injector) {
|
|
614
|
+
super(), this._injector = _injector;
|
|
615
|
+
}
|
|
616
|
+
onStarting() {
|
|
617
|
+
[[SheetsFindReplaceController]].forEach((d) => this._injector.add(d));
|
|
618
|
+
}
|
|
619
|
+
}, __name(_a4, "UniverSheetsFindReplacePlugin"), _a4);
|
|
620
|
+
__publicField2(UniverSheetsFindReplacePlugin, "pluginName", NAME);
|
|
621
|
+
__publicField2(UniverSheetsFindReplacePlugin, "type", UniverInstanceType.UNIVER_SHEET);
|
|
622
|
+
UniverSheetsFindReplacePlugin = __decorateClass([
|
|
623
|
+
DependentOn(UniverSheetsPlugin, UniverSheetsPlugin, UniverFindReplacePlugin),
|
|
624
|
+
__decorateParam(1, Inject(Injector))
|
|
625
|
+
], UniverSheetsFindReplacePlugin);
|
|
609
626
|
export {
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
627
|
+
SheetReplaceCommand,
|
|
628
|
+
SheetsFindReplaceController,
|
|
629
|
+
UniverSheetsFindReplacePlugin
|
|
613
630
|
};
|