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