@pierre/diffs 1.3.0-beta.3 → 1.3.0-beta.5
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/README.md +6 -6
- package/dist/components/CodeView.js +6 -6
- package/dist/components/CodeView.js.map +1 -1
- package/dist/components/File.d.ts +3 -2
- package/dist/components/File.d.ts.map +1 -1
- package/dist/components/File.js +35 -21
- package/dist/components/File.js.map +1 -1
- package/dist/components/FileDiff.d.ts +8 -4
- package/dist/components/FileDiff.d.ts.map +1 -1
- package/dist/components/FileDiff.js +66 -56
- package/dist/components/FileDiff.js.map +1 -1
- package/dist/components/FileStream.js +4 -2
- package/dist/components/FileStream.js.map +1 -1
- package/dist/components/UnresolvedFile.js +1 -1
- package/dist/components/VirtualizedFile.d.ts +6 -2
- package/dist/components/VirtualizedFile.d.ts.map +1 -1
- package/dist/components/VirtualizedFile.js +89 -24
- package/dist/components/VirtualizedFile.js.map +1 -1
- package/dist/components/VirtualizedFileDiff.d.ts +8 -2
- package/dist/components/VirtualizedFileDiff.d.ts.map +1 -1
- package/dist/components/VirtualizedFileDiff.js +91 -15
- package/dist/components/VirtualizedFileDiff.js.map +1 -1
- package/dist/editor/command.d.ts +1 -1
- package/dist/editor/command.d.ts.map +1 -1
- package/dist/editor/command.js +3 -3
- package/dist/editor/command.js.map +1 -1
- package/dist/editor/editStack.d.ts +1 -1
- package/dist/editor/editor.d.ts +37 -9
- package/dist/editor/editor.d.ts.map +1 -1
- package/dist/editor/editor.js +558 -449
- package/dist/editor/editor.js.map +1 -1
- package/dist/editor/editor2.js +1 -1
- package/dist/editor/editor2.js.map +1 -1
- package/dist/editor/index.d.ts +2 -2
- package/dist/editor/lineAnnotations.d.ts +2 -1
- package/dist/editor/lineAnnotations.d.ts.map +1 -1
- package/dist/editor/lineAnnotations.js +111 -1
- package/dist/editor/lineAnnotations.js.map +1 -1
- package/dist/editor/marker.d.ts +33 -0
- package/dist/editor/marker.d.ts.map +1 -0
- package/dist/editor/marker.js +185 -0
- package/dist/editor/marker.js.map +1 -0
- package/dist/editor/pieceTable.d.ts +8 -3
- package/dist/editor/pieceTable.d.ts.map +1 -1
- package/dist/editor/pieceTable.js +74 -12
- package/dist/editor/pieceTable.js.map +1 -1
- package/dist/editor/searchPanel.d.ts +12 -3
- package/dist/editor/searchPanel.d.ts.map +1 -1
- package/dist/editor/searchPanel.js +168 -54
- package/dist/editor/searchPanel.js.map +1 -1
- package/dist/editor/selection.d.ts +19 -3
- package/dist/editor/selection.d.ts.map +1 -1
- package/dist/editor/selection.js +188 -37
- package/dist/editor/selection.js.map +1 -1
- package/dist/editor/{quickEdit.d.ts → selectionAction.d.ts} +8 -8
- package/dist/editor/selectionAction.d.ts.map +1 -0
- package/dist/editor/{quickEdit.js → selectionAction.js} +18 -18
- package/dist/editor/selectionAction.js.map +1 -0
- package/dist/editor/sprite.d.ts +4 -3
- package/dist/editor/sprite.d.ts.map +1 -1
- package/dist/editor/sprite.js +19 -5
- package/dist/editor/sprite.js.map +1 -1
- package/dist/editor/textDocument.d.ts +4 -4
- package/dist/editor/textDocument.d.ts.map +1 -1
- package/dist/editor/textDocument.js +7 -7
- package/dist/editor/textDocument.js.map +1 -1
- package/dist/editor/textMeasure.d.ts +1 -0
- package/dist/editor/textMeasure.d.ts.map +1 -1
- package/dist/editor/textMeasure.js +6 -0
- package/dist/editor/textMeasure.js.map +1 -1
- package/dist/editor/tokenzier.js +20 -9
- package/dist/editor/tokenzier.js.map +1 -1
- package/dist/editor/utils.d.ts +3 -1
- package/dist/editor/utils.d.ts.map +1 -1
- package/dist/editor/utils.js +16 -1
- package/dist/editor/utils.js.map +1 -1
- package/dist/highlighter/shared_highlighter.js +3 -29
- package/dist/highlighter/shared_highlighter.js.map +1 -1
- package/dist/highlighter/themes/attachResolvedThemes.js +4 -3
- package/dist/highlighter/themes/attachResolvedThemes.js.map +1 -1
- package/dist/highlighter/themes/cleanUpResolvedThemes.js +3 -2
- package/dist/highlighter/themes/cleanUpResolvedThemes.js.map +1 -1
- package/dist/highlighter/themes/constants.d.ts +1 -7
- package/dist/highlighter/themes/constants.d.ts.map +1 -1
- package/dist/highlighter/themes/constants.js +1 -4
- package/dist/highlighter/themes/constants.js.map +1 -1
- package/dist/highlighter/themes/getResolvedOrResolveTheme.js +2 -2
- package/dist/highlighter/themes/getResolvedOrResolveTheme.js.map +1 -1
- package/dist/highlighter/themes/getResolvedThemes.js +2 -8
- package/dist/highlighter/themes/getResolvedThemes.js.map +1 -1
- package/dist/highlighter/themes/hasResolvedThemes.js +2 -3
- package/dist/highlighter/themes/hasResolvedThemes.js.map +1 -1
- package/dist/highlighter/themes/registerCustomCSSVariableTheme.js +1 -1
- package/dist/highlighter/themes/registerCustomTheme.d.ts +5 -3
- package/dist/highlighter/themes/registerCustomTheme.d.ts.map +1 -1
- package/dist/highlighter/themes/registerCustomTheme.js +15 -5
- package/dist/highlighter/themes/registerCustomTheme.js.map +1 -1
- package/dist/highlighter/themes/resolveTheme.js +6 -27
- package/dist/highlighter/themes/resolveTheme.js.map +1 -1
- package/dist/highlighter/themes/resolveThemes.js +5 -12
- package/dist/highlighter/themes/resolveThemes.js.map +1 -1
- package/dist/highlighter/themes/themeResolution.d.ts +8 -0
- package/dist/highlighter/themes/themeResolution.d.ts.map +1 -0
- package/dist/highlighter/themes/themeResolution.js +22 -0
- package/dist/highlighter/themes/themeResolution.js.map +1 -0
- package/dist/highlighter/themes/themeResolver.d.ts +8 -0
- package/dist/highlighter/themes/themeResolver.d.ts.map +1 -0
- package/dist/highlighter/themes/themeResolver.js +8 -0
- package/dist/highlighter/themes/themeResolver.js.map +1 -0
- package/dist/index.d.ts +4 -4
- package/dist/index.js +3 -3
- package/dist/managers/InteractionManager.js +1 -1
- package/dist/managers/InteractionManager.js.map +1 -1
- package/dist/managers/ResizeManager.js +1 -1
- package/dist/managers/ResizeManager.js.map +1 -1
- package/dist/react/CodeView.js +1 -1
- package/dist/react/index.d.ts +2 -2
- package/dist/react/utils/useFileDiffInstance.js +1 -0
- package/dist/react/utils/useFileDiffInstance.js.map +1 -1
- package/dist/renderers/DiffHunksRenderer.d.ts +6 -2
- package/dist/renderers/DiffHunksRenderer.d.ts.map +1 -1
- package/dist/renderers/DiffHunksRenderer.js +183 -12
- package/dist/renderers/DiffHunksRenderer.js.map +1 -1
- package/dist/renderers/FileRenderer.d.ts +2 -2
- package/dist/renderers/FileRenderer.d.ts.map +1 -1
- package/dist/renderers/FileRenderer.js +17 -5
- package/dist/renderers/FileRenderer.js.map +1 -1
- package/dist/ssr/FileDiffReact.js +1 -1
- package/dist/ssr/index.d.ts +2 -2
- package/dist/types.d.ts +25 -8
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/getHighlighterThemeStyles.js +16 -12
- package/dist/utils/getHighlighterThemeStyles.js.map +1 -1
- package/dist/utils/includesFileAnnotations.d.ts +17 -0
- package/dist/utils/includesFileAnnotations.d.ts.map +1 -0
- package/dist/utils/includesFileAnnotations.js +19 -0
- package/dist/utils/includesFileAnnotations.js.map +1 -0
- package/dist/utils/parseMergeConflictDiffFromFile.js.map +1 -1
- package/dist/utils/parsePatchFiles.js +93 -4
- package/dist/utils/parsePatchFiles.js.map +1 -1
- package/dist/utils/renderDiffWithHighlighter.js +4 -2
- package/dist/utils/renderDiffWithHighlighter.js.map +1 -1
- package/dist/utils/renderFileWithHighlighter.js +4 -2
- package/dist/utils/renderFileWithHighlighter.js.map +1 -1
- package/dist/utils/updateDiffHunks.d.ts +13 -0
- package/dist/utils/updateDiffHunks.d.ts.map +1 -0
- package/dist/utils/updateDiffHunks.js +171 -0
- package/dist/utils/updateDiffHunks.js.map +1 -0
- package/dist/utils/virtualDiffLayout.d.ts +2 -1
- package/dist/utils/virtualDiffLayout.d.ts.map +1 -1
- package/dist/utils/virtualDiffLayout.js +9 -1
- package/dist/utils/virtualDiffLayout.js.map +1 -1
- package/dist/worker/{wasm-BaDzIkIn.js → wasm-qE0LgnY3.js} +2 -2
- package/dist/worker/{wasm-BaDzIkIn.js.map → wasm-qE0LgnY3.js.map} +1 -1
- package/dist/worker/worker-portable.js +1016 -275
- package/dist/worker/worker-portable.js.map +1 -1
- package/dist/worker/worker.js +31 -19
- package/dist/worker/worker.js.map +1 -1
- package/package.json +5 -10
- package/dist/editor/quickEdit.d.ts.map +0 -1
- package/dist/editor/quickEdit.js.map +0 -1
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import { isPrimaryModifier } from "./platform.js";
|
|
2
|
-
import { getEditorIconSvg } from "./sprite.js";
|
|
3
2
|
import { h } from "./utils.js";
|
|
3
|
+
import { buildSearchReplacementText } from "./pieceTable.js";
|
|
4
|
+
import { getEditorIconSvg } from "./sprite.js";
|
|
4
5
|
|
|
5
6
|
//#region src/editor/searchPanel.ts
|
|
6
7
|
var SearchPanelWidget = class {
|
|
7
8
|
#container;
|
|
8
9
|
#inputElement;
|
|
10
|
+
#updateMatches;
|
|
11
|
+
#applyMode;
|
|
9
12
|
constructor(options) {
|
|
10
|
-
const { textDocument, containerElement, defaultQuery, initialMatch, scrollToMatch, onUpdate, onClose } = options;
|
|
13
|
+
const { textDocument, containerElement, defaultQuery, mode = "find", initialMatch, scrollToMatch, applyReplace, onUpdate, onClose } = options;
|
|
11
14
|
const searchParams = {
|
|
12
15
|
text: defaultQuery,
|
|
13
16
|
replaceText: "",
|
|
@@ -19,28 +22,38 @@ var SearchPanelWidget = class {
|
|
|
19
22
|
all: [],
|
|
20
23
|
current: void 0
|
|
21
24
|
};
|
|
22
|
-
const matchResultElement = h("div", {
|
|
23
|
-
|
|
25
|
+
const matchResultElement = h("div", {
|
|
26
|
+
dataset: {
|
|
27
|
+
matches: "",
|
|
28
|
+
noMatches: ""
|
|
29
|
+
},
|
|
30
|
+
textContent: "No results"
|
|
31
|
+
});
|
|
32
|
+
const updateMatches = (options$1) => {
|
|
24
33
|
matches.all = searchParams.text !== "" ? textDocument.search(searchParams) : [];
|
|
25
|
-
this.#container.querySelectorAll("[data-disabled]").forEach((element) => {
|
|
34
|
+
this.#container.querySelectorAll("[data-icon][data-disabled]").forEach((element) => {
|
|
26
35
|
element.dataset.disabled = String(matches.all.length === 0);
|
|
27
36
|
});
|
|
28
37
|
if (searchParams.text === "") {
|
|
29
|
-
matchResultElement.textContent = "";
|
|
30
|
-
|
|
38
|
+
matchResultElement.textContent = "No results";
|
|
39
|
+
matchResultElement.dataset.noMatches = "";
|
|
31
40
|
return;
|
|
32
41
|
}
|
|
33
42
|
if (matches.all.length === 0) {
|
|
34
43
|
matchResultElement.textContent = "No results";
|
|
35
44
|
matchResultElement.dataset.noMatches = "";
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
updateCurrentMatch(onUpdate(matches.all));
|
|
45
|
+
matches.current = void 0;
|
|
46
|
+
onUpdate([]);
|
|
39
47
|
return;
|
|
40
48
|
}
|
|
41
|
-
|
|
42
|
-
|
|
49
|
+
delete matchResultElement.dataset.noMatches;
|
|
50
|
+
if (options$1?.syncSelection === false) {
|
|
51
|
+
updateCurrentMatch(onUpdate(matches.all, { syncSelection: false }));
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
updateCurrentMatch(onUpdate(matches.all));
|
|
43
55
|
};
|
|
56
|
+
this.#updateMatches = updateMatches;
|
|
44
57
|
const updateCurrentMatch = (currentMatch) => {
|
|
45
58
|
if (currentMatch === void 0) matchResultElement.textContent = `${matches.all.length} results`;
|
|
46
59
|
else {
|
|
@@ -74,6 +87,32 @@ var SearchPanelWidget = class {
|
|
|
74
87
|
}
|
|
75
88
|
matches.current = nextMatch;
|
|
76
89
|
};
|
|
90
|
+
const buildReplacementEdit = (matchStart, matchEnd) => ({
|
|
91
|
+
start: matchStart,
|
|
92
|
+
end: matchEnd,
|
|
93
|
+
text: buildSearchReplacementText((offset) => textDocument.positionAt(offset), (position) => textDocument.offsetAt(position), (line) => textDocument.getLineText(line), searchParams, matchStart, matchEnd)
|
|
94
|
+
});
|
|
95
|
+
const replace = () => {
|
|
96
|
+
if (searchParams.text === "" || matches.all.length === 0) return;
|
|
97
|
+
let currentMatch = matches.current;
|
|
98
|
+
if (currentMatch === void 0) {
|
|
99
|
+
findNextMatch(false, true);
|
|
100
|
+
currentMatch = matches.current;
|
|
101
|
+
if (currentMatch === void 0) return;
|
|
102
|
+
}
|
|
103
|
+
const [start, end] = currentMatch;
|
|
104
|
+
const edit = buildReplacementEdit(start, end);
|
|
105
|
+
applyReplace([edit]);
|
|
106
|
+
scrollToMatch([start + edit.text.length, start + edit.text.length], true);
|
|
107
|
+
matches.current = void 0;
|
|
108
|
+
updateMatches();
|
|
109
|
+
};
|
|
110
|
+
const replaceAll = () => {
|
|
111
|
+
if (searchParams.text === "" || matches.all.length === 0) return;
|
|
112
|
+
applyReplace(matches.all.map(([start, end]) => buildReplacementEdit(start, end)));
|
|
113
|
+
matches.current = void 0;
|
|
114
|
+
updateMatches();
|
|
115
|
+
};
|
|
77
116
|
const close = () => {
|
|
78
117
|
this.cleanup();
|
|
79
118
|
onClose();
|
|
@@ -97,6 +136,15 @@ var SearchPanelWidget = class {
|
|
|
97
136
|
const caseSensitiveToggle = makeToggle("case", "Match Case", "caseSensitive");
|
|
98
137
|
const wholeWordToggle = makeToggle("whole-word", "Whole Word", "wholeWord");
|
|
99
138
|
const regexToggle = makeToggle("regex", "Regexp", "regex");
|
|
139
|
+
const replaceInputElement = h("input", {
|
|
140
|
+
type: "text",
|
|
141
|
+
placeholder: "Replace",
|
|
142
|
+
dataset: "replace",
|
|
143
|
+
value: "",
|
|
144
|
+
oninput: (e) => {
|
|
145
|
+
searchParams.replaceText = e.target.value;
|
|
146
|
+
}
|
|
147
|
+
});
|
|
100
148
|
this.#inputElement = h("input", {
|
|
101
149
|
type: "text",
|
|
102
150
|
placeholder: "Search",
|
|
@@ -114,53 +162,113 @@ var SearchPanelWidget = class {
|
|
|
114
162
|
} else if (e.key === "Enter") {
|
|
115
163
|
e.preventDefault();
|
|
116
164
|
findNextMatch(false, true);
|
|
117
|
-
} else if (e.key === "f"
|
|
165
|
+
} else if (isPrimaryModifier(e) && (e.key === "f" || e.code === "KeyF")) {
|
|
166
|
+
e.preventDefault();
|
|
167
|
+
applyMode(e.altKey ? "replace" : "find");
|
|
168
|
+
}
|
|
118
169
|
}
|
|
119
170
|
});
|
|
171
|
+
const searchTogglesElement = h("div", {
|
|
172
|
+
dataset: "searchToggles",
|
|
173
|
+
children: [
|
|
174
|
+
caseSensitiveToggle,
|
|
175
|
+
wholeWordToggle,
|
|
176
|
+
regexToggle
|
|
177
|
+
]
|
|
178
|
+
});
|
|
179
|
+
const findInputBox = h("div", {
|
|
180
|
+
dataset: {
|
|
181
|
+
inputBox: "",
|
|
182
|
+
find: ""
|
|
183
|
+
},
|
|
184
|
+
children: [this.#inputElement, searchTogglesElement]
|
|
185
|
+
});
|
|
186
|
+
const replaceInputBox = h("div", {
|
|
187
|
+
dataset: {
|
|
188
|
+
inputBox: "",
|
|
189
|
+
replace: "",
|
|
190
|
+
replaceCell: ""
|
|
191
|
+
},
|
|
192
|
+
children: [replaceInputElement]
|
|
193
|
+
});
|
|
194
|
+
const replaceActionsElement = h("div", {
|
|
195
|
+
dataset: {
|
|
196
|
+
replaceActions: "",
|
|
197
|
+
replaceCell: ""
|
|
198
|
+
},
|
|
199
|
+
children: [h("div", {
|
|
200
|
+
dataset: { icon: "replace" },
|
|
201
|
+
title: "Replace",
|
|
202
|
+
innerHTML: getEditorIconSvg("replace"),
|
|
203
|
+
onclick: () => {
|
|
204
|
+
replace();
|
|
205
|
+
}
|
|
206
|
+
}), h("div", {
|
|
207
|
+
dataset: { icon: "replace-all" },
|
|
208
|
+
title: "Replace All",
|
|
209
|
+
innerHTML: getEditorIconSvg("replace-all"),
|
|
210
|
+
onclick: () => {
|
|
211
|
+
replaceAll();
|
|
212
|
+
}
|
|
213
|
+
})]
|
|
214
|
+
});
|
|
215
|
+
const navElement = h("div", {
|
|
216
|
+
dataset: "searchNav",
|
|
217
|
+
children: [
|
|
218
|
+
h("div", {
|
|
219
|
+
dataset: {
|
|
220
|
+
icon: "arrow-up",
|
|
221
|
+
disabled: "true"
|
|
222
|
+
},
|
|
223
|
+
title: "Previous",
|
|
224
|
+
innerHTML: getEditorIconSvg("arrow-up"),
|
|
225
|
+
onclick: () => {
|
|
226
|
+
findNextMatch(true);
|
|
227
|
+
}
|
|
228
|
+
}),
|
|
229
|
+
h("div", {
|
|
230
|
+
dataset: {
|
|
231
|
+
icon: "arrow-down",
|
|
232
|
+
disabled: "true"
|
|
233
|
+
},
|
|
234
|
+
title: "Next",
|
|
235
|
+
innerHTML: getEditorIconSvg("arrow-down"),
|
|
236
|
+
onclick: () => {
|
|
237
|
+
findNextMatch();
|
|
238
|
+
}
|
|
239
|
+
}),
|
|
240
|
+
h("div", {
|
|
241
|
+
dataset: { icon: "close" },
|
|
242
|
+
title: "Close",
|
|
243
|
+
innerHTML: getEditorIconSvg("close"),
|
|
244
|
+
onclick: close
|
|
245
|
+
})
|
|
246
|
+
]
|
|
247
|
+
});
|
|
248
|
+
const gridElement = h("div", {
|
|
249
|
+
dataset: {
|
|
250
|
+
searchGrid: "",
|
|
251
|
+
mode
|
|
252
|
+
},
|
|
253
|
+
children: [
|
|
254
|
+
findInputBox,
|
|
255
|
+
matchResultElement,
|
|
256
|
+
navElement,
|
|
257
|
+
replaceInputBox,
|
|
258
|
+
replaceActionsElement
|
|
259
|
+
]
|
|
260
|
+
});
|
|
261
|
+
const applyMode = (next) => {
|
|
262
|
+
gridElement.dataset.mode = next;
|
|
263
|
+
this.#inputElement.focus();
|
|
264
|
+
this.#inputElement.select();
|
|
265
|
+
};
|
|
266
|
+
this.#applyMode = applyMode;
|
|
120
267
|
this.#container = h("div", {
|
|
121
268
|
dataset: "searchPanel",
|
|
122
269
|
children: [h("div", {
|
|
123
|
-
dataset: "
|
|
124
|
-
children: [
|
|
125
|
-
h("div", {
|
|
126
|
-
dataset: { icon: "search" },
|
|
127
|
-
innerHTML: getEditorIconSvg("search")
|
|
128
|
-
}),
|
|
129
|
-
this.#inputElement,
|
|
130
|
-
matchResultElement,
|
|
131
|
-
caseSensitiveToggle,
|
|
132
|
-
wholeWordToggle,
|
|
133
|
-
regexToggle,
|
|
134
|
-
h("div", { dataset: "divider" }),
|
|
135
|
-
h("div", {
|
|
136
|
-
dataset: {
|
|
137
|
-
icon: "arrow-up",
|
|
138
|
-
disabled: "true"
|
|
139
|
-
},
|
|
140
|
-
title: "Previous",
|
|
141
|
-
innerHTML: getEditorIconSvg("arrow-up"),
|
|
142
|
-
onclick: () => {
|
|
143
|
-
findNextMatch(true);
|
|
144
|
-
}
|
|
145
|
-
}),
|
|
146
|
-
h("div", {
|
|
147
|
-
dataset: {
|
|
148
|
-
icon: "arrow-down",
|
|
149
|
-
disabled: "true"
|
|
150
|
-
},
|
|
151
|
-
title: "Next",
|
|
152
|
-
innerHTML: getEditorIconSvg("arrow-down"),
|
|
153
|
-
onclick: () => {
|
|
154
|
-
findNextMatch();
|
|
155
|
-
}
|
|
156
|
-
}),
|
|
157
|
-
h("div", {
|
|
158
|
-
dataset: { icon: "close" },
|
|
159
|
-
title: "Close",
|
|
160
|
-
innerHTML: getEditorIconSvg("close"),
|
|
161
|
-
onclick: close
|
|
162
|
-
})
|
|
163
|
-
]
|
|
270
|
+
dataset: "editorWidget",
|
|
271
|
+
children: [gridElement]
|
|
164
272
|
})]
|
|
165
273
|
});
|
|
166
274
|
matches.current = initialMatch;
|
|
@@ -174,6 +282,12 @@ var SearchPanelWidget = class {
|
|
|
174
282
|
focus() {
|
|
175
283
|
this.#inputElement.focus();
|
|
176
284
|
}
|
|
285
|
+
updateMatches(options) {
|
|
286
|
+
this.#updateMatches?.(options);
|
|
287
|
+
}
|
|
288
|
+
setMode(mode) {
|
|
289
|
+
this.#applyMode?.(mode);
|
|
290
|
+
}
|
|
177
291
|
cleanup() {
|
|
178
292
|
this.#container.remove();
|
|
179
293
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"searchPanel.js","names":["searchParams: SearchParams","#container","nextMatch: MatchRange | undefined","#inputElement"],"sources":["../../src/editor/searchPanel.ts"],"sourcesContent":["import { isPrimaryModifier } from './platform';\nimport { getEditorIconSvg, type SVGSpriteNames } from './sprite';\nimport type { TextDocument } from './textDocument';\nimport { h } from './utils';\n\nexport type MatchRange = [startOffset: number, endOffset: number];\n\nexport interface SearchParams {\n text: string;\n replaceText: string;\n caseSensitive: boolean;\n wholeWord: boolean;\n regex: boolean;\n}\n\nexport interface SearchPanelOptions {\n textDocument: TextDocument<unknown>;\n containerElement: HTMLElement;\n defaultQuery: string;\n initialMatch?: MatchRange;\n scrollToMatch: (nextMatch: MatchRange, retainFocus: boolean) => void;\n onUpdate: (matches: MatchRange[]) => MatchRange | undefined;\n onClose: () => void;\n}\n\nexport class SearchPanelWidget {\n #container: HTMLDivElement;\n #inputElement: HTMLInputElement;\n\n constructor(options: SearchPanelOptions) {\n const {\n textDocument,\n containerElement,\n defaultQuery,\n initialMatch,\n scrollToMatch,\n onUpdate,\n onClose,\n } = options;\n\n const searchParams: SearchParams = {\n text: defaultQuery,\n replaceText: '',\n caseSensitive: false,\n wholeWord: false,\n regex: false,\n };\n\n const matches = {\n all: [] as MatchRange[],\n current: undefined as MatchRange | undefined,\n };\n\n const matchResultElement = h('div', { dataset: 'matches' });\n const updateMatches = () => {\n matches.all =\n searchParams.text !== '' ? textDocument.search(searchParams) : [];\n this.#container\n .querySelectorAll<HTMLElement>('[data-disabled]')\n .forEach((element) => {\n element.dataset.disabled = String(matches.all.length === 0);\n });\n\n if (searchParams.text === '') {\n matchResultElement.textContent = '';\n delete matchResultElement.dataset.noMatches;\n return;\n }\n\n if (matches.all.length === 0) {\n matchResultElement.textContent = 'No results';\n matchResultElement.dataset.noMatches = '';\n } else {\n delete matchResultElement.dataset.noMatches;\n updateCurrentMatch(onUpdate(matches.all));\n return;\n }\n\n matches.current = undefined;\n onUpdate([]);\n };\n\n const updateCurrentMatch = (currentMatch: MatchRange | undefined) => {\n if (currentMatch === undefined) {\n matchResultElement.textContent = `${matches.all.length} results`;\n } else {\n const [start, end] = currentMatch;\n const index = matches.all.findIndex(\n (m) => m[0] === start && m[1] === end\n );\n matchResultElement.textContent = `${index + 1} of ${matches.all.length}`;\n }\n matches.current = currentMatch;\n };\n\n const updateSearchParam = <K extends keyof SearchParams>(\n key: K,\n value: SearchParams[K]\n ) => {\n searchParams[key] = value;\n updateMatches();\n };\n\n const findNextMatch = (\n findPrevious: boolean = false,\n retainFocus: boolean = false\n ) => {\n const allMatches = matches.all;\n let nextMatch: MatchRange | undefined = allMatches[0];\n if (allMatches.length > 0) {\n if (findPrevious) {\n const searchOffset = matches.current?.[0] ?? 0;\n nextMatch = allMatches.at(-1);\n for (const m of allMatches) {\n if (m[1] <= searchOffset) {\n nextMatch = m;\n } else {\n break;\n }\n }\n } else {\n const searchOffset = matches.current?.[1] ?? 0;\n for (const m of allMatches) {\n if (m[0] >= searchOffset) {\n nextMatch = m;\n break;\n }\n }\n }\n }\n if (nextMatch !== undefined) {\n updateCurrentMatch(nextMatch);\n scrollToMatch(nextMatch, retainFocus);\n }\n matches.current = nextMatch;\n };\n\n const close = () => {\n this.cleanup();\n onClose();\n };\n\n // Builds an always-visible icon button that toggles one boolean search\n // option (case/whole-word/regex). The button reflects its on/off state via\n // the `data-active` attribute so the stylesheet can highlight it.\n const makeToggle = (\n icon: SVGSpriteNames,\n title: string,\n key: 'caseSensitive' | 'wholeWord' | 'regex'\n ) => {\n const button = h('div', {\n dataset: { icon, active: String(searchParams[key]) },\n title,\n innerHTML: getEditorIconSvg(icon),\n onclick: () => {\n const next = !searchParams[key];\n button.dataset.active = String(next);\n updateSearchParam(key, next);\n },\n });\n return button;\n };\n\n const caseSensitiveToggle = makeToggle(\n 'case',\n 'Match Case',\n 'caseSensitive'\n );\n const wholeWordToggle = makeToggle('whole-word', 'Whole Word', 'wholeWord');\n const regexToggle = makeToggle('regex', 'Regexp', 'regex');\n\n this.#inputElement = h('input', {\n type: 'text',\n placeholder: 'Search',\n dataset: 'search',\n value: defaultQuery,\n oninput: (e: Event) => {\n searchParams.text = (e.target as HTMLInputElement).value;\n matches.current = undefined;\n updateMatches();\n },\n onkeydown: (e: KeyboardEvent) => {\n if (e.key === 'Escape') {\n e.preventDefault();\n close();\n } else if (e.key === 'Enter') {\n e.preventDefault();\n findNextMatch(false, true);\n } else if (e.key === 'f' && isPrimaryModifier(e)) {\n // prevent the default browser search panel open behavior\n e.preventDefault();\n }\n },\n });\n\n this.#container = h('div', {\n dataset: 'searchPanel',\n children: [\n h('div', {\n dataset: 'searchPanelRow',\n children: [\n h('div', {\n dataset: { icon: 'search' },\n innerHTML: getEditorIconSvg('search'),\n }),\n this.#inputElement,\n matchResultElement,\n caseSensitiveToggle,\n wholeWordToggle,\n regexToggle,\n h('div', { dataset: 'divider' }),\n h('div', {\n dataset: { icon: 'arrow-up', disabled: 'true' },\n title: 'Previous',\n innerHTML: getEditorIconSvg('arrow-up'),\n onclick: () => {\n findNextMatch(true);\n },\n }),\n h('div', {\n dataset: { icon: 'arrow-down', disabled: 'true' },\n title: 'Next',\n innerHTML: getEditorIconSvg('arrow-down'),\n onclick: () => {\n findNextMatch();\n },\n }),\n h('div', {\n dataset: { icon: 'close' },\n title: 'Close',\n innerHTML: getEditorIconSvg('close'),\n onclick: close,\n }),\n ],\n }),\n ],\n });\n\n matches.current = initialMatch;\n containerElement.before(this.#container);\n\n requestAnimationFrame(() => {\n if (initialMatch !== undefined) {\n updateMatches();\n } else {\n onUpdate([]);\n }\n this.#inputElement.select();\n });\n }\n\n focus(): void {\n this.#inputElement.focus();\n }\n\n cleanup(): void {\n this.#container.remove();\n }\n}\n"],"mappings":";;;;;AAyBA,IAAa,oBAAb,MAA+B;CAC7B;CACA;CAEA,YAAY,SAA6B;EACvC,MAAM,EACJ,cACA,kBACA,cACA,cACA,eACA,UACA,YACE;EAEJ,MAAMA,eAA6B;GACjC,MAAM;GACN,aAAa;GACb,eAAe;GACf,WAAW;GACX,OAAO;GACR;EAED,MAAM,UAAU;GACd,KAA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ACA;KACA;KACA;KACA,EAAE,OAAO,EAAE,SAAS,WAAW,CAAC;KAChC,EAAE,OAAO;MACP,SAAS;OAAE,MAAM;OAAY,UAAU;OAAQ;MAC/C,OAAO;MACP,WAAW,iBAAiB,WAAW;MACvC,eAAe;AACb,qBAAc,KAAK;;MAEtB,CAAC;KACF,EAAE,OAAO;MACP,SAAS;OAAE,MAAM;OAAc,UAAU;OAAQ;MACjD,OAAO;MACP,WAAW,iBAAiB,aAAa;MACzC,eAAe;AACb,sBAAe;;MAElB,CAAC;KACF,EAAE,OAAO;MACP,SAAS,EAAE,MAAM,SAAS;MAC1B,OAAO;MACP,WAAW,iBAAiB,QAAQ;MACpC,SAAS;MACV,CAAC;KACH;IACF,CAAC,CACH;GACF,CAAC;AAEF,UAAQ,UAAU;AAClB,mBAAiB,OAAO,MAAKF,UAAW;AAExC,8BAA4B;AAC1B,OAAI,iBAAiB,OACnB,gBAAe;OAEf,UAAS,EAAE,CAAC;AAEd,SAAKE,aAAc,QAAQ;IAC3B;;CAGJ,QAAc;AACZ,QAAKA,aAAc,OAAO;;CAG5B,UAAgB;AACd,QAAKF,UAAW,QAAQ"}
|
|
1
|
+
{"version":3,"file":"searchPanel.js","names":["searchParams: SearchParams","#container","options","#updateMatches","nextMatch: MatchRange | undefined","#inputElement","#applyMode"],"sources":["../../src/editor/searchPanel.ts"],"sourcesContent":["import { buildSearchReplacementText } from './pieceTable';\nimport { isPrimaryModifier } from './platform';\nimport { getEditorIconSvg, type SVGSpriteNames } from './sprite';\nimport type { ResolvedTextEdit, TextDocument } from './textDocument';\nimport { h } from './utils';\n\nexport type MatchRange = [startOffset: number, endOffset: number];\n\nexport type SearchPanelMode = 'find' | 'replace';\n\nexport interface SearchParams {\n text: string;\n replaceText: string;\n caseSensitive: boolean;\n wholeWord: boolean;\n regex: boolean;\n}\n\nexport interface SearchPanelOptions {\n textDocument: TextDocument<unknown>;\n containerElement: HTMLElement;\n defaultQuery: string;\n mode?: SearchPanelMode;\n initialMatch?: MatchRange;\n scrollToMatch: (nextMatch: MatchRange, retainFocus: boolean) => void;\n applyReplace: (edits: ResolvedTextEdit[]) => void;\n onUpdate: (\n matches: MatchRange[],\n options?: { syncSelection?: boolean }\n ) => MatchRange | undefined;\n onClose: () => void;\n}\n\nexport class SearchPanelWidget {\n #container: HTMLDivElement;\n #inputElement: HTMLInputElement;\n #updateMatches?: (options?: { syncSelection?: boolean }) => void;\n #applyMode?: (mode: SearchPanelMode) => void;\n\n constructor(options: SearchPanelOptions) {\n const {\n textDocument,\n containerElement,\n defaultQuery,\n mode = 'find',\n initialMatch,\n scrollToMatch,\n applyReplace,\n onUpdate,\n onClose,\n } = options;\n\n const searchParams: SearchParams = {\n text: defaultQuery,\n replaceText: '',\n caseSensitive: false,\n wholeWord: false,\n regex: false,\n };\n\n const matches = {\n all: [] as MatchRange[],\n current: undefined as MatchRange | undefined,\n };\n\n // Default to the empty-query \"no results\" state so it shows on open before\n // any search runs.\n const matchResultElement = h('div', {\n dataset: { matches: '', noMatches: '' },\n textContent: 'No results',\n });\n const updateMatches = (options?: { syncSelection?: boolean }) => {\n matches.all =\n searchParams.text !== '' ? textDocument.search(searchParams) : [];\n this.#container\n .querySelectorAll<HTMLElement>('[data-icon][data-disabled]')\n .forEach((element) => {\n element.dataset.disabled = String(matches.all.length === 0);\n });\n\n if (searchParams.text === '') {\n matchResultElement.textContent = 'No results';\n matchResultElement.dataset.noMatches = '';\n return;\n }\n\n if (matches.all.length === 0) {\n matchResultElement.textContent = 'No results';\n matchResultElement.dataset.noMatches = '';\n matches.current = undefined;\n onUpdate([]);\n return;\n }\n\n delete matchResultElement.dataset.noMatches;\n if (options?.syncSelection === false) {\n const currentMatch = onUpdate(matches.all, { syncSelection: false });\n updateCurrentMatch(currentMatch);\n return;\n }\n\n updateCurrentMatch(onUpdate(matches.all));\n };\n this.#updateMatches = updateMatches;\n\n const updateCurrentMatch = (currentMatch: MatchRange | undefined) => {\n if (currentMatch === undefined) {\n matchResultElement.textContent = `${matches.all.length} results`;\n } else {\n const [start, end] = currentMatch;\n const index = matches.all.findIndex(\n (m) => m[0] === start && m[1] === end\n );\n matchResultElement.textContent = `${index + 1} of ${matches.all.length}`;\n }\n matches.current = currentMatch;\n };\n\n const updateSearchParam = <K extends keyof SearchParams>(\n key: K,\n value: SearchParams[K]\n ) => {\n searchParams[key] = value;\n updateMatches();\n };\n\n const findNextMatch = (\n findPrevious: boolean = false,\n retainFocus: boolean = false\n ) => {\n const allMatches = matches.all;\n let nextMatch: MatchRange | undefined = allMatches[0];\n if (allMatches.length > 0) {\n if (findPrevious) {\n const searchOffset = matches.current?.[0] ?? 0;\n nextMatch = allMatches.at(-1);\n for (const m of allMatches) {\n if (m[1] <= searchOffset) {\n nextMatch = m;\n } else {\n break;\n }\n }\n } else {\n const searchOffset = matches.current?.[1] ?? 0;\n for (const m of allMatches) {\n if (m[0] >= searchOffset) {\n nextMatch = m;\n break;\n }\n }\n }\n }\n if (nextMatch !== undefined) {\n updateCurrentMatch(nextMatch);\n scrollToMatch(nextMatch, retainFocus);\n }\n matches.current = nextMatch;\n };\n\n const buildReplacementEdit = (\n matchStart: number,\n matchEnd: number\n ): ResolvedTextEdit => ({\n start: matchStart,\n end: matchEnd,\n text: buildSearchReplacementText(\n (offset) => textDocument.positionAt(offset),\n (position) => textDocument.offsetAt(position),\n (line) => textDocument.getLineText(line),\n searchParams,\n matchStart,\n matchEnd\n ),\n });\n\n const replace = () => {\n if (searchParams.text === '' || matches.all.length === 0) {\n return;\n }\n\n let currentMatch = matches.current;\n if (currentMatch === undefined) {\n findNextMatch(false, true);\n currentMatch = matches.current;\n if (currentMatch === undefined) {\n return;\n }\n }\n\n const [start, end] = currentMatch;\n const edit = buildReplacementEdit(start, end);\n applyReplace([edit]);\n\n // Collapse after the replacement so the next search pass advances.\n scrollToMatch([start + edit.text.length, start + edit.text.length], true);\n matches.current = undefined;\n updateMatches();\n };\n\n const replaceAll = () => {\n if (searchParams.text === '' || matches.all.length === 0) {\n return;\n }\n\n applyReplace(\n matches.all.map(([start, end]) => buildReplacementEdit(start, end))\n );\n matches.current = undefined;\n updateMatches();\n };\n\n const close = () => {\n this.cleanup();\n onClose();\n };\n\n // Builds an always-visible icon button that toggles one boolean search\n // option (case/whole-word/regex). The button reflects its on/off state via\n // the `data-active` attribute so the stylesheet can highlight it.\n const makeToggle = (\n icon: SVGSpriteNames,\n title: string,\n key: 'caseSensitive' | 'wholeWord' | 'regex'\n ) => {\n const button = h('div', {\n dataset: { icon, active: String(searchParams[key]) },\n title,\n innerHTML: getEditorIconSvg(icon),\n onclick: () => {\n const next = !searchParams[key];\n button.dataset.active = String(next);\n updateSearchParam(key, next);\n },\n });\n return button;\n };\n\n const caseSensitiveToggle = makeToggle(\n 'case',\n 'Match Case',\n 'caseSensitive'\n );\n const wholeWordToggle = makeToggle('whole-word', 'Whole Word', 'wholeWord');\n const regexToggle = makeToggle('regex', 'Regexp', 'regex');\n\n const replaceInputElement = h('input', {\n type: 'text',\n placeholder: 'Replace',\n dataset: 'replace',\n value: '',\n oninput: (e: Event) => {\n searchParams.replaceText = (e.target as HTMLInputElement).value;\n },\n });\n\n this.#inputElement = h('input', {\n type: 'text',\n placeholder: 'Search',\n dataset: 'search',\n value: defaultQuery,\n oninput: (e: Event) => {\n searchParams.text = (e.target as HTMLInputElement).value;\n matches.current = undefined;\n updateMatches();\n },\n onkeydown: (e: KeyboardEvent) => {\n if (e.key === 'Escape') {\n e.preventDefault();\n close();\n } else if (e.key === 'Enter') {\n e.preventDefault();\n findNextMatch(false, true);\n } else if (\n isPrimaryModifier(e) &&\n (e.key === 'f' || e.code === 'KeyF')\n ) {\n // Prevent the default browser search panel and switch the panel mode\n // in place (cmd+f -> find, cmd+opt+f -> find/replace).\n e.preventDefault();\n applyMode(e.altKey ? 'replace' : 'find');\n }\n },\n });\n\n // The three search-option toggles are overlaid on the right edge of the\n // find input instead of sitting beside it.\n const searchTogglesElement = h('div', {\n dataset: 'searchToggles',\n children: [caseSensitiveToggle, wholeWordToggle, regexToggle],\n });\n\n const findInputBox = h('div', {\n dataset: { inputBox: '', find: '' },\n children: [this.#inputElement, searchTogglesElement],\n });\n\n // The replace input and its action buttons are tagged as replace cells so\n // they can be hidden together when the panel is in find-only mode.\n const replaceInputBox = h('div', {\n dataset: { inputBox: '', replace: '', replaceCell: '' },\n children: [replaceInputElement],\n });\n\n const replaceActionsElement = h('div', {\n dataset: { replaceActions: '', replaceCell: '' },\n children: [\n h('div', {\n dataset: { icon: 'replace' },\n title: 'Replace',\n innerHTML: getEditorIconSvg('replace'),\n onclick: () => {\n replace();\n },\n }),\n h('div', {\n dataset: { icon: 'replace-all' },\n title: 'Replace All',\n innerHTML: getEditorIconSvg('replace-all'),\n onclick: () => {\n replaceAll();\n },\n }),\n ],\n });\n\n const navElement = h('div', {\n dataset: 'searchNav',\n children: [\n h('div', {\n dataset: { icon: 'arrow-up', disabled: 'true' },\n title: 'Previous',\n innerHTML: getEditorIconSvg('arrow-up'),\n onclick: () => {\n findNextMatch(true);\n },\n }),\n h('div', {\n dataset: { icon: 'arrow-down', disabled: 'true' },\n title: 'Next',\n innerHTML: getEditorIconSvg('arrow-down'),\n onclick: () => {\n findNextMatch();\n },\n }),\n h('div', {\n dataset: { icon: 'close' },\n title: 'Close',\n innerHTML: getEditorIconSvg('close'),\n onclick: close,\n }),\n ],\n });\n\n // A 2x2 grid of inputs (find/replace) and their trailing content (results\n // text / replace actions), with the find navigation buttons in a third\n // column on the first row. DOM order drives grid auto-placement:\n // row 1: find input | results text | nav buttons\n // row 2: replace input | replace actions\n const gridElement = h('div', {\n dataset: { searchGrid: '', mode },\n children: [\n findInputBox,\n matchResultElement,\n navElement,\n replaceInputBox,\n replaceActionsElement,\n ],\n });\n\n // Toggles the panel between find and find/replace modes by showing or\n // hiding the replace cells, then returns focus to the find input.\n const applyMode = (next: SearchPanelMode) => {\n gridElement.dataset.mode = next;\n this.#inputElement.focus();\n this.#inputElement.select();\n };\n this.#applyMode = applyMode;\n\n this.#container = h('div', {\n dataset: 'searchPanel',\n children: [\n h('div', {\n dataset: 'editorWidget',\n children: [gridElement],\n }),\n ],\n });\n\n matches.current = initialMatch;\n containerElement.before(this.#container);\n\n requestAnimationFrame(() => {\n if (initialMatch !== undefined) {\n updateMatches();\n } else {\n onUpdate([]);\n }\n this.#inputElement.select();\n });\n }\n\n focus(): void {\n this.#inputElement.focus();\n }\n\n updateMatches(options?: { syncSelection?: boolean }): void {\n this.#updateMatches?.(options);\n }\n\n setMode(mode: SearchPanelMode): void {\n this.#applyMode?.(mode);\n }\n\n cleanup(): void {\n this.#container.remove();\n }\n}\n"],"mappings":";;;;;;AAiCA,IAAa,oBAAb,MAA+B;CAC7B;CACA;CACA;CACA;CAEA,YAAY,SAA6B;EACvC,MAAM,EACJ,cACA,kBACA,cACA,OAAO,QACP,cACA,eACA,cACA,UACA,YACE;EAEJ,MAAMA,eAA6B;GACjC,MAAM;GACN,aAAa;GACb,eAAe;GACf,WAAW;GACX,OAAO;GACR;EAED,MAAM,UAAU;GACd,KAAK,EAAE;GACP,SAAS;GACV;EAID,MAAM,qBAAqB,EAAE,OAAO;GAClC,SAAS;IAAE,SAAS;IAAI,WAAW;IAAI;GACvC,aAAa;GACd,CAAC;EACF,MAAM,iBAAiB,cAA0C;AAC/D,WAAQ,MACN,aAAa,SAAS,KAAK,aAAa,OAAO,aAAa,GAAG,EAAE;AACnE,SAAKC,UACF,iBAA8B,6BAA6B,CAC3D,SAAS,YAAY;AACpB,YAAQ,QAAQ,WAAW,OAAO,QAAQ,IAAI,WAAW,EAAE;KAC3D;AAEJ,OAAI,aAAa,SAAS,IAAI;AAC5B,uBAAmB,cAAc;AACjC,uBAAmB,QAAQ,YAAY;AACvC;;AAGF,OAAI,QAAQ,IAAI,WAAW,GAAG;AAC5B,uBAAmB,cAAc;AACjC,uBAAmB,QAAQ,YAAY;AACvC,YAAQ,UAAU;AAClB,aAAS,EAAE,CAAC;AACZ;;AAGF,UAAO,mBAAmB,QAAQ;AAClC,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vC,eAAe;AACb,oBAAc,KAAK;;KAEtB,CAAC;IACF,EAAE,OAAO;KACP,SAAS;MAAE,MAAM;MAAc,UAAU;MAAQ;KACjD,OAAO;KACP,WAAW,iBAAiB,aAAa;KACzC,eAAe;AACb,qBAAe;;KAElB,CAAC;IACF,EAAE,OAAO;KACP,SAAS,EAAE,MAAM,SAAS;KAC1B,OAAO;KACP,WAAW,iBAAiB,QAAQ;KACpC,SAAS;KACV,CAAC;IACH;GACF,CAAC;EAOF,MAAM,cAAc,EAAE,OAAO;GAC3B,SAAS;IAAE,YAAY;IAAI;IAAM;GACjC,UAAU;IACR;IACA;IACA;IACA;IACA;IACD;GACF,CAAC;EAIF,MAAM,aAAa,SAA0B;AAC3C,eAAY,QAAQ,OAAO;AAC3B,SAAKA,aAAc,OAAO;AAC1B,SAAKA,aAAc,QAAQ;;AAE7B,QAAKC,YAAa;AAElB,QAAKL,YAAa,EAAE,OAAO;GACzB,SAAS;GACT,UAAU,CACR,EAAE,OAAO;IACP,SAAS;IACT,UAAU,CAAC,YAAY;IACxB,CAAC,CACH;GACF,CAAC;AAEF,UAAQ,UAAU;AAClB,mBAAiB,OAAO,MAAKA,UAAW;AAExC,8BAA4B;AAC1B,OAAI,iBAAiB,OACnB,gBAAe;OAEf,UAAS,EAAE,CAAC;AAEd,SAAKI,aAAc,QAAQ;IAC3B;;CAGJ,QAAc;AACZ,QAAKA,aAAc,OAAO;;CAG5B,cAAc,SAA6C;AACzD,QAAKF,gBAAiB,QAAQ;;CAGhC,QAAQ,MAA6B;AACnC,QAAKG,YAAa,KAAK;;CAGzB,UAAgB;AACd,QAAKL,UAAW,QAAQ"}
|
|
@@ -56,10 +56,26 @@ declare function applyDeleteHardLineForwardToSelections<LAnnotation>(textDocumen
|
|
|
56
56
|
nextSelections: EditorSelection[];
|
|
57
57
|
change?: TextDocumentChange;
|
|
58
58
|
};
|
|
59
|
+
/**
|
|
60
|
+
* Deletes from each selection back to the start of its soft (visual) line.
|
|
61
|
+
* Non-collapsed selections delete their selected text instead.
|
|
62
|
+
*/
|
|
63
|
+
declare function applyDeleteSoftLineBackwardToSelections<LAnnotation>(textDocument: TextDocument<LAnnotation>, selections: EditorSelection[], getSoftLineStart?: (line: number, character: number) => number, lineAnnotations?: DiffLineAnnotation<LAnnotation>[]): {
|
|
64
|
+
nextSelections: EditorSelection[];
|
|
65
|
+
change?: TextDocumentChange;
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Deletes the word or separator group immediately before each selection.
|
|
69
|
+
* Non-collapsed selections delete their selected text instead.
|
|
70
|
+
*/
|
|
71
|
+
declare function applyDeleteWordBackwardToSelections<LAnnotation>(textDocument: TextDocument<LAnnotation>, selections: EditorSelection[], lineAnnotations?: DiffLineAnnotation<LAnnotation>[]): {
|
|
72
|
+
nextSelections: EditorSelection[];
|
|
73
|
+
change?: TextDocumentChange;
|
|
74
|
+
};
|
|
59
75
|
/**
|
|
60
76
|
* Checks if a selection is collapsed.
|
|
61
77
|
*/
|
|
62
|
-
declare function isCollapsedSelection(selection: EditorSelection): boolean;
|
|
78
|
+
declare function isCollapsedSelection(selection: EditorSelection | Range): boolean;
|
|
63
79
|
/**
|
|
64
80
|
* Returns the caret (focus) position for a selection.
|
|
65
81
|
*/
|
|
@@ -71,7 +87,7 @@ declare function isLineEditable(lineType: string): boolean;
|
|
|
71
87
|
/**
|
|
72
88
|
* Checks whether selections `a` and `b` intersect.
|
|
73
89
|
*/
|
|
74
|
-
declare function selectionIntersects(a: EditorSelection, b: EditorSelection): boolean;
|
|
90
|
+
declare function selectionIntersects(a: EditorSelection | Range, b: EditorSelection | Range): boolean;
|
|
75
91
|
/**
|
|
76
92
|
* Compares two positions.
|
|
77
93
|
*/
|
|
@@ -122,5 +138,5 @@ declare function getSelectionAnchor(lineElement: HTMLElement, character: number)
|
|
|
122
138
|
*/
|
|
123
139
|
declare function expandCollapsedSelectionToWord(textDocument: TextDocument<unknown>, selection: EditorSelection): EditorSelection;
|
|
124
140
|
//#endregion
|
|
125
|
-
export { DirectionBackward, DirectionForward, DirectionNone, EditorSelection, SelectionDirection, applyDeleteHardLineForwardToSelections, applyTextChangeToSelections, applyTextReplaceToSelections, applyTransposeToSelections, comparePosition, convertSelection, createSelectionFrom, createSelectionFromAnchorAndFocusOffsets, expandCollapsedSelectionToWord, extendSelection, extendSelections, findNexMatch, getCaretPosition, getDocumentBoundarySelection, getDocumentFullSelection, getSelectionAnchor, getSelectionText, isCollapsedSelection, isLineEditable, mapCursorMove, mapSelectionShift, mergeOverlappingSelections, resolveIndentEdits, selectionIntersects };
|
|
141
|
+
export { DirectionBackward, DirectionForward, DirectionNone, EditorSelection, SelectionDirection, applyDeleteHardLineForwardToSelections, applyDeleteSoftLineBackwardToSelections, applyDeleteWordBackwardToSelections, applyTextChangeToSelections, applyTextReplaceToSelections, applyTransposeToSelections, comparePosition, convertSelection, createSelectionFrom, createSelectionFromAnchorAndFocusOffsets, expandCollapsedSelectionToWord, extendSelection, extendSelections, findNexMatch, getCaretPosition, getDocumentBoundarySelection, getDocumentFullSelection, getSelectionAnchor, getSelectionText, isCollapsedSelection, isLineEditable, mapCursorMove, mapSelectionShift, mergeOverlappingSelections, resolveIndentEdits, selectionIntersects };
|
|
126
142
|
//# sourceMappingURL=selection.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"selection.d.ts","names":["DiffLineAnnotation","Position","Range","ResolvedTextEdit","TextDocument","TextDocumentChange","TextEdit","DirectionBackward","DirectionNone","DirectionForward","SelectionDirection","EditorSelection","convertSelection","StaticRange","resolveIndentEdits","mapCursorMove","mapSelectionShift","applyTextChangeToSelections","LAnnotation","applyTextReplaceToSelections","applyTransposeToSelections","applyDeleteHardLineForwardToSelections","isCollapsedSelection","getCaretPosition","isLineEditable","selectionIntersects","comparePosition","createSelectionFromAnchorAndFocusOffsets","createSelectionFrom","extendSelection","extendSelections","mergeOverlappingSelections","findNexMatch","getDocumentFullSelection","getDocumentBoundarySelection","getSelectionText","getSelectionAnchor","HTMLElement","Node","expandCollapsedSelectionToWord"],"sources":["../../src/editor/selection.d.ts"],"sourcesContent":["import type { DiffLineAnnotation } from '../types';\nimport type { Position, Range, ResolvedTextEdit, TextDocument, TextDocumentChange, TextEdit } from './textDocument';\nexport declare const DirectionBackward = -1;\nexport declare const DirectionNone = 0;\nexport declare const DirectionForward = 1;\nexport type SelectionDirection = typeof DirectionBackward | typeof DirectionNone | typeof DirectionForward;\nexport interface EditorSelection extends Range {\n direction: SelectionDirection;\n}\n/**\n * Converts a selection from a web selection to an editor selection.\n */\nexport declare function convertSelection(range: StaticRange, direction?: SelectionDirection): EditorSelection | undefined;\n/**\n * Resolves the indent edits for a selection.\n */\nexport declare function resolveIndentEdits(textDocument: TextDocument<unknown>, selection: EditorSelection, tabSize: number, outdent: boolean): [edits: TextEdit[], nextSelection: EditorSelection];\n/**\n * Maps the cursor move to all selections.\n */\nexport declare function mapCursorMove(textDocument: TextDocument<unknown>, selections: EditorSelection[], shortcut: 'textStart' | 'start' | 'end' | 'up' | 'down' | 'left' | 'right'): EditorSelection[];\n/**\n * Same as mapCursorMove, but with shift key pressed.\n */\nexport declare function mapSelectionShift(textDocument: TextDocument<unknown>, selections: EditorSelection[], shortcut: 'textStart' | 'start' | 'end' | 'up' | 'down' | 'left' | 'right'): EditorSelection[];\n/**\n * Applies a text change to the given text document\n */\nexport declare function applyTextChangeToSelections<LAnnotation>(textDocument: TextDocument<LAnnotation>, selections: EditorSelection[], edit: ResolvedTextEdit, lineAnnotations?: DiffLineAnnotation<LAnnotation>[], tabSize?: number): {\n nextSelections: EditorSelection[];\n change?: TextDocumentChange;\n};\n/**\n * Applies a text replace to multiple selections.\n */\nexport declare function applyTextReplaceToSelections<LAnnotation>(textDocument: TextDocument<LAnnotation>, selections: EditorSelection[], texts: string[], lineAnnotations?: DiffLineAnnotation<LAnnotation>[]): {\n nextSelections: EditorSelection[];\n change?: TextDocumentChange;\n};\n/**\n * Swaps the two characters adjacent to a collapsed selection, matching browser\n * insertTranspose (Ctrl+T) behavior.\n */\nexport declare function applyTransposeToSelections<LAnnotation>(textDocument: TextDocument<LAnnotation>, selections: EditorSelection[], lineAnnotations?: DiffLineAnnotation<LAnnotation>[]): {\n nextSelections: EditorSelection[];\n change?: TextDocumentChange;\n};\n/**\n * Deletes from each selection to the end of its line, including the line break\n * when the caret is already at the end of a non-final line. Non-collapsed\n * selections delete their selected text instead.\n */\nexport declare function applyDeleteHardLineForwardToSelections<LAnnotation>(textDocument: TextDocument<LAnnotation>, selections: EditorSelection[], lineAnnotations?: DiffLineAnnotation<LAnnotation>[]): {\n nextSelections: EditorSelection[];\n change?: TextDocumentChange;\n};\n/**\n * Checks if a selection is collapsed.\n */\nexport declare function isCollapsedSelection(selection: EditorSelection): boolean;\n/**\n * Returns the caret (focus) position for a selection.\n */\nexport declare function getCaretPosition(selection: EditorSelection): Position;\n/**\n * Checks if a line is editable.\n */\nexport declare function isLineEditable(lineType: string): boolean;\n/**\n * Checks whether selections `a` and `b` intersect.\n */\nexport declare function selectionIntersects(a: EditorSelection, b: EditorSelection): boolean;\n/**\n * Compares two positions.\n */\nexport declare function comparePosition(a: Position, b: Position): number;\n/**\n * Creates a selection from anchor and focus offsets.\n */\nexport declare function createSelectionFromAnchorAndFocusOffsets(textDocument: TextDocument<unknown>, anchorOffset: number, focusOffset: number): EditorSelection;\n/**\n * Creates a selection from a anchor and focus selection.\n */\nexport declare function createSelectionFrom(anchorSelection: EditorSelection, focusSelection: EditorSelection): EditorSelection;\n/**\n * Extends or shrinks the selection `original` using the endpoints of `target`, \\\n * matching contenteditable shift + click extend behavior.\n */\nexport declare function extendSelection(original: EditorSelection, target: EditorSelection): EditorSelection;\n/**\n * Extends multiple selections.\n */\nexport declare function extendSelections(selections: EditorSelection[], target: EditorSelection): EditorSelection[];\n/**\n * Merges overlapping selections.\n */\nexport declare function mergeOverlappingSelections(selections: EditorSelection[]): EditorSelection[];\n/**\n * Finds the next matching word and updates the selections.\n */\nexport declare function findNexMatch(textDocument: TextDocument<unknown>, selections: EditorSelection[]): EditorSelection[] | undefined;\n/**\n * Get the full selection of the document.\n */\nexport declare function getDocumentFullSelection(textDocument: TextDocument<unknown>): EditorSelection;\n/**\n * Get the boundary selection of the document.\n */\nexport declare function getDocumentBoundarySelection(textDocument: TextDocument<unknown>, atEnd: boolean): EditorSelection;\n/**\n * Get the text of the selections for the given text document.\n */\nexport declare function getSelectionText(textDocument: TextDocument<unknown>, selections: EditorSelection[]): string;\n/**\n * Get the anchor node and offset for a selection.\n */\nexport declare function getSelectionAnchor(lineElement: HTMLElement, character: number): [Node, number];\n/**\n * Expands a zero-width selection to the word-like segment that contains the caret.\n */\nexport declare function expandCollapsedSelectionToWord(textDocument: TextDocument<unknown>, selection: EditorSelection): EditorSelection;\n//# sourceMappingURL=selection.d.ts.map"],"mappings":";;;;cAEqBO,iBAAAA;cACAC,aAAAA;AADAD,cAEAE,gBAAAA,GAFiB,CAAA;AACjBD,KAETE,kBAAAA,GAFsB,OAEMH,iBAFN,GAAA,OAEiCC,aAFjC,GAAA,OAEwDC,gBAFxD;AACbA,UAEJE,eAAAA,SAAwBT,KAFJ,CAAA;EACzBQ,SAAAA,EAEGA,kBAFe;;;;;AACbC,iBAMOC,gBAAAA,CALTF,KAAAA,EAKiCG,WANPX,EAAK,SAAA,CAAA,EAM2BQ,kBAN3B,CAAA,EAMgDC,eANhD,GAAA,SAAA;AAM9C;;;AAA8FA,iBAItEG,kBAAAA,CAJsEH,YAAAA,EAIrCP,YAJqCO,CAAAA,OAAAA,CAAAA,EAAAA,SAAAA,EAIHA,eAJGA,EAAAA,OAAAA,EAAAA,MAAAA,EAAAA,OAAAA,EAAAA,OAAAA,CAAAA,EAAAA,CAAAA,KAAAA,EAI0DL,QAJ1DK,EAAAA,EAAAA,aAAAA,EAIqFA,eAJrFA,CAAAA;;AAI9F;;AAA2FA,iBAInEI,aAAAA,CAJmEJ,YAAAA,EAIvCP,YAJuCO,CAAAA,OAAAA,CAAAA,EAA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,eAK9DA;;;;AAIlD;AAAqDA,iBAJ7BkB,eAAAA,CAI6BlB,QAAAA,EAJHA,eAIGA,EAAAA,MAAAA,EAJsBA,eAItBA,CAAAA,EAJwCA,eAIxCA;;;;AAI7BoB,iBAJAD,gBAAAA,CAI0B,UAAanB,EAJVA,eAI8BA,EAAAA,EAAAA,MAAAA,EAJHA,eAIkB,CAAA,EAJAA,eAIA,EAAA;AAIlG;;;AAA0GA,iBAJlFoB,0BAAAA,CAIkFpB,UAAAA,EAJ3CA,eAI2CA,EAAAA,CAAAA,EAJvBA,eAIuBA,EAAAA;;AAI1G;AAIA;AAIwBwB,iBAZAH,YAAAA,CAY+B5B,YAAAA,EAZJA,YAYuCO,CAAAA,OAAe,CAAA,EAAA,UAAA,EAZnBA,eAYmB,EAAA,CAAA,EAZCA,eAYD,EAAA,GAAA,SAAA;AAIzG;AAIA;;AAAuGA,iBAhB/EsB,wBAAAA,CAgB+EtB,YAAAA,EAhBxCP,YAgBwCO,CAAAA,OAAAA,CAAAA,CAAAA,EAhBhBA,eAgBgBA;;;;iBAZ/EuB,4BAAAA,eAA2C9B,wCAAwCO;;;;iBAInFwB,gBAAAA,eAA+B/B,mCAAmCO;;;;iBAIlEyB,kBAAAA,cAAgCC,kCAAkCC;;;;iBAIlEC,8BAAAA,eAA6CnC,kCAAkCO,kBAAkBA"}
|
|
1
|
+
{"version":3,"file":"selection.d.ts","names":["DiffLineAnnotation","Position","Range","ResolvedTextEdit","TextDocument","TextDocumentChange","TextEdit","DirectionBackward","DirectionNone","DirectionForward","SelectionDirection","EditorSelection","convertSelection","StaticRange","resolveIndentEdits","mapCursorMove","mapSelectionShift","applyTextChangeToSelections","LAnnotation","applyTextReplaceToSelections","applyTransposeToSelections","applyDeleteHardLineForwardToSelections","applyDeleteSoftLineBackwardToSelections","applyDeleteWordBackwardToSelections","isCollapsedSelection","getCaretPosition","isLineEditable","selectionIntersects","comparePosition","createSelectionFromAnchorAndFocusOffsets","createSelectionFrom","extendSelection","extendSelections","mergeOverlappingSelections","findNexMatch","getDocumentFullSelection","getDocumentBoundarySelection","getSelectionText","getSelectionAnchor","HTMLElement","Node","expandCollapsedSelectionToWord"],"sources":["../../src/editor/selection.d.ts"],"sourcesContent":["import type { DiffLineAnnotation } from '../types';\nimport type { Position, Range, ResolvedTextEdit, TextDocument, TextDocumentChange, TextEdit } from './textDocument';\nexport declare const DirectionBackward = -1;\nexport declare const DirectionNone = 0;\nexport declare const DirectionForward = 1;\nexport type SelectionDirection = typeof DirectionBackward | typeof DirectionNone | typeof DirectionForward;\nexport interface EditorSelection extends Range {\n direction: SelectionDirection;\n}\n/**\n * Converts a selection from a web selection to an editor selection.\n */\nexport declare function convertSelection(range: StaticRange, direction?: SelectionDirection): EditorSelection | undefined;\n/**\n * Resolves the indent edits for a selection.\n */\nexport declare function resolveIndentEdits(textDocument: TextDocument<unknown>, selection: EditorSelection, tabSize: number, outdent: boolean): [edits: TextEdit[], nextSelection: EditorSelection];\n/**\n * Maps the cursor move to all selections.\n */\nexport declare function mapCursorMove(textDocument: TextDocument<unknown>, selections: EditorSelection[], shortcut: 'textStart' | 'start' | 'end' | 'up' | 'down' | 'left' | 'right'): EditorSelection[];\n/**\n * Same as mapCursorMove, but with shift key pressed.\n */\nexport declare function mapSelectionShift(textDocument: TextDocument<unknown>, selections: EditorSelection[], shortcut: 'textStart' | 'start' | 'end' | 'up' | 'down' | 'left' | 'right'): EditorSelection[];\n/**\n * Applies a text change to the given text document\n */\nexport declare function applyTextChangeToSelections<LAnnotation>(textDocument: TextDocument<LAnnotation>, selections: EditorSelection[], edit: ResolvedTextEdit, lineAnnotations?: DiffLineAnnotation<LAnnotation>[], tabSize?: number): {\n nextSelections: EditorSelection[];\n change?: TextDocumentChange;\n};\n/**\n * Applies a text replace to multiple selections.\n */\nexport declare function applyTextReplaceToSelections<LAnnotation>(textDocument: TextDocument<LAnnotation>, selections: EditorSelection[], texts: string[], lineAnnotations?: DiffLineAnnotation<LAnnotation>[]): {\n nextSelections: EditorSelection[];\n change?: TextDocumentChange;\n};\n/**\n * Swaps the two characters adjacent to a collapsed selection, matching browser\n * insertTranspose (Ctrl+T) behavior.\n */\nexport declare function applyTransposeToSelections<LAnnotation>(textDocument: TextDocument<LAnnotation>, selections: EditorSelection[], lineAnnotations?: DiffLineAnnotation<LAnnotation>[]): {\n nextSelections: EditorSelection[];\n change?: TextDocumentChange;\n};\n/**\n * Deletes from each selection to the end of its line, including the line break\n * when the caret is already at the end of a non-final line. Non-collapsed\n * selections delete their selected text instead.\n */\nexport declare function applyDeleteHardLineForwardToSelections<LAnnotation>(textDocument: TextDocument<LAnnotation>, selections: EditorSelection[], lineAnnotations?: DiffLineAnnotation<LAnnotation>[]): {\n nextSelections: EditorSelection[];\n change?: TextDocumentChange;\n};\n/**\n * Deletes from each selection back to the start of its soft (visual) line.\n * Non-collapsed selections delete their selected text instead.\n */\nexport declare function applyDeleteSoftLineBackwardToSelections<LAnnotation>(textDocument: TextDocument<LAnnotation>, selections: EditorSelection[], getSoftLineStart?: (line: number, character: number) => number, lineAnnotations?: DiffLineAnnotation<LAnnotation>[]): {\n nextSelections: EditorSelection[];\n change?: TextDocumentChange;\n};\n/**\n * Deletes the word or separator group immediately before each selection.\n * Non-collapsed selections delete their selected text instead.\n */\nexport declare function applyDeleteWordBackwardToSelections<LAnnotation>(textDocument: TextDocument<LAnnotation>, selections: EditorSelection[], lineAnnotations?: DiffLineAnnotation<LAnnotation>[]): {\n nextSelections: EditorSelection[];\n change?: TextDocumentChange;\n};\n/**\n * Checks if a selection is collapsed.\n */\nexport declare function isCollapsedSelection(selection: EditorSelection | Range): boolean;\n/**\n * Returns the caret (focus) position for a selection.\n */\nexport declare function getCaretPosition(selection: EditorSelection): Position;\n/**\n * Checks if a line is editable.\n */\nexport declare function isLineEditable(lineType: string): boolean;\n/**\n * Checks whether selections `a` and `b` intersect.\n */\nexport declare function selectionIntersects(a: EditorSelection | Range, b: EditorSelection | Range): boolean;\n/**\n * Compares two positions.\n */\nexport declare function comparePosition(a: Position, b: Position): number;\n/**\n * Creates a selection from anchor and focus offsets.\n */\nexport declare function createSelectionFromAnchorAndFocusOffsets(textDocument: TextDocument<unknown>, anchorOffset: number, focusOffset: number): EditorSelection;\n/**\n * Creates a selection from a anchor and focus selection.\n */\nexport declare function createSelectionFrom(anchorSelection: EditorSelection, focusSelection: EditorSelection): EditorSelection;\n/**\n * Extends or shrinks the selection `original` using the endpoints of `target`, \\\n * matching contenteditable shift + click extend behavior.\n */\nexport declare function extendSelection(original: EditorSelection, target: EditorSelection): EditorSelection;\n/**\n * Extends multiple selections.\n */\nexport declare function extendSelections(selections: EditorSelection[], target: EditorSelection): EditorSelection[];\n/**\n * Merges overlapping selections.\n */\nexport declare function mergeOverlappingSelections(selections: EditorSelection[]): EditorSelection[];\n/**\n * Finds the next matching word and updates the selections.\n */\nexport declare function findNexMatch(textDocument: TextDocument<unknown>, selections: EditorSelection[]): EditorSelection[] | undefined;\n/**\n * Get the full selection of the document.\n */\nexport declare function getDocumentFullSelection(textDocument: TextDocument<unknown>): EditorSelection;\n/**\n * Get the boundary selection of the document.\n */\nexport declare function getDocumentBoundarySelection(textDocument: TextDocument<unknown>, atEnd: boolean): EditorSelection;\n/**\n * Get the text of the selections for the given text document.\n */\nexport declare function getSelectionText(textDocument: TextDocument<unknown>, selections: EditorSelection[]): string;\n/**\n * Get the anchor node and offset for a selection.\n */\nexport declare function getSelectionAnchor(lineElement: HTMLElement, character: number): [Node, number];\n/**\n * Expands a zero-width selection to the word-like segment that contains the caret.\n */\nexport declare function expandCollapsedSelectionToWord(textDocument: TextDocument<unknown>, selection: EditorSelection): EditorSelection;\n//# sourceMappingURL=selection.d.ts.map"],"mappings":";;;;cAEqBO,iBAAAA;cACAC,aAAAA;AADAD,cAEAE,gBAAAA,GAFiB,CAAA;AACjBD,KAETE,kBAAAA,GAFsB,OAEMH,iBAFN,GAAA,OAEiCC,aAFjC,GAAA,OAEwDC,gBAFxD;AACbA,UAEJE,eAAAA,SA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