@celljs/ta-workspace 0.0.0-stage → 4.6.1
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 +28 -2
- package/package.json +39 -4
- package/web/index.js +7289 -0
- package/web-src/browser.tsx +240 -0
- package/web-src/common.tsx +296 -0
- package/web-src/editors.tsx +471 -0
- package/web-src/explorer.tsx +479 -0
- package/web-src/file-icon.tsx +21 -0
- package/web-src/host.ts +121 -0
- package/web-src/i18n.ts +320 -0
- package/web-src/index.tsx +65 -0
- package/web-src/open-files.tsx +80 -0
- package/web-src/preview.tsx +132 -0
- package/web-src/react.ts +8 -0
- package/web-src/scm.tsx +388 -0
- package/web-src/search.tsx +485 -0
- package/web-src/style.ts +225 -0
- package/web-src/terminal.tsx +350 -0
- package/web-src/util/ansi.spec.ts +66 -0
- package/web-src/util/ansi.ts +438 -0
- package/web-src/util/file-icon.spec.ts +35 -0
- package/web-src/util/file-icon.ts +23 -0
- package/web-src/util/git.ts +203 -0
- package/web-src/util/keys.ts +56 -0
- package/web-src/util/preview.spec.ts +48 -0
- package/web-src/util/preview.ts +90 -0
- package/web-src/util/search.spec.ts +164 -0
- package/web-src/util/search.ts +274 -0
- package/web-src/util/seti-font.ts +6 -0
- package/web-src/util/seti.ts +761 -0
- package/web-src/util/workspace.spec.ts +191 -0
- package/web-src/util/workspace.ts +331 -0
- package/web-src/workspace-client.ts +119 -0
|
@@ -0,0 +1,485 @@
|
|
|
1
|
+
import { Action, copyText, Empty, Glyph, type MenuItem, useContextMenu, useKept } from './common';
|
|
2
|
+
import { openFile } from './editors';
|
|
3
|
+
import { FileIcon } from './file-icon';
|
|
4
|
+
import { Channel, FilesChanged, Host, pi } from './host';
|
|
5
|
+
import { t } from './i18n';
|
|
6
|
+
import { React } from './react';
|
|
7
|
+
import { SearchUtil, type TextMatch, type TextQuery, type TextResult } from './util/search';
|
|
8
|
+
import { type FileMatches, type PathFolder, WorkspaceUtil } from './util/workspace';
|
|
9
|
+
import { WorkspaceClient } from './workspace-client';
|
|
10
|
+
|
|
11
|
+
const DEBOUNCE_MS = 300;
|
|
12
|
+
|
|
13
|
+
interface SearchState {
|
|
14
|
+
query: TextQuery;
|
|
15
|
+
replace: string;
|
|
16
|
+
showReplace: boolean;
|
|
17
|
+
showDetails: boolean;
|
|
18
|
+
result?: TextResult;
|
|
19
|
+
error?: string;
|
|
20
|
+
busy: boolean;
|
|
21
|
+
collapsed: string[];
|
|
22
|
+
/** The results by folder, as a tree; else a list of files. */
|
|
23
|
+
tree: boolean;
|
|
24
|
+
/** Matches and files the user took out of the results (`path`, or `path:line:column`). */
|
|
25
|
+
dismissed: string[];
|
|
26
|
+
/** Runs again with the same query (refresh, after a replace). */
|
|
27
|
+
run: number;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const searches = new Map<string, SearchState>();
|
|
31
|
+
|
|
32
|
+
/** A folder to search, from the explorer's `find in folder`. */
|
|
33
|
+
export const SearchRequests = new Channel<{ cwd: string; include: string }>();
|
|
34
|
+
|
|
35
|
+
const INDENT = 12;
|
|
36
|
+
|
|
37
|
+
const matchKey = (match: TextMatch) => `${match.path}:${match.line}:${match.column}`;
|
|
38
|
+
|
|
39
|
+
/** Whether a key the user dismissed takes a match out: the match, its file, or a folder (`dir/`) it is in. */
|
|
40
|
+
function dismisses(key: string, match: TextMatch): boolean {
|
|
41
|
+
return key === match.path || key === matchKey(match) || (key.endsWith('/') && match.path.startsWith(key));
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
type ResultRow =
|
|
45
|
+
| { kind: 'folder'; key: string; folder: PathFolder<FileMatches>; depth: number }
|
|
46
|
+
| { kind: 'file'; group: FileMatches; depth: number }
|
|
47
|
+
| { kind: 'match'; match: TextMatch; depth: number };
|
|
48
|
+
|
|
49
|
+
/** The rows shown: the files and their matches, inside their folders with a tree; what is collapsed is left out. */
|
|
50
|
+
function resultRows(groups: readonly FileMatches[], tree: PathFolder<FileMatches> | undefined, collapsed: ReadonlySet<string>): ResultRow[] {
|
|
51
|
+
const rows: ResultRow[] = [];
|
|
52
|
+
const file = (group: FileMatches, depth: number) => {
|
|
53
|
+
rows.push({ kind: 'file', group, depth });
|
|
54
|
+
if (!collapsed.has(group.path)) {
|
|
55
|
+
for (const match of group.matches) {
|
|
56
|
+
rows.push({ kind: 'match', match, depth });
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
const folder = (node: PathFolder<FileMatches>, depth: number) => {
|
|
61
|
+
for (const inner of node.folders) {
|
|
62
|
+
const key = `${inner.path}/`;
|
|
63
|
+
rows.push({ kind: 'folder', key, folder: inner, depth });
|
|
64
|
+
if (!collapsed.has(key)) {
|
|
65
|
+
folder(inner, depth + 1);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
for (const group of node.items) {
|
|
69
|
+
file(group, depth);
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
if (tree) {
|
|
73
|
+
folder(tree, 0);
|
|
74
|
+
} else {
|
|
75
|
+
for (const group of groups) {
|
|
76
|
+
file(group, 0);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return rows;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** The keys of the folders of a tree (`dir/`), to collapse them all. */
|
|
83
|
+
function folderKeys(node: PathFolder<FileMatches>): string[] {
|
|
84
|
+
return node.folders.flatMap(inner => [`${inner.path}/`, ...folderKeys(inner)]);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function onToggleKey(event: React.KeyboardEvent, toggle: () => void): void {
|
|
88
|
+
if (event.key === 'Enter' || event.key === ' ') {
|
|
89
|
+
event.preventDefault();
|
|
90
|
+
toggle();
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** Text in the files of the conversation's directory, as the search of an IDE: options in the box, files to include or leave out, replace. */
|
|
95
|
+
export function SearchView() {
|
|
96
|
+
const cwd = pi.ui.useCwd();
|
|
97
|
+
const [state, setState] = useKept<SearchState>(searches, cwd, () => ({
|
|
98
|
+
query: { pattern: '' },
|
|
99
|
+
replace: '',
|
|
100
|
+
showReplace: false,
|
|
101
|
+
showDetails: false,
|
|
102
|
+
busy: false,
|
|
103
|
+
collapsed: [],
|
|
104
|
+
tree: false,
|
|
105
|
+
dismissed: [],
|
|
106
|
+
run: 0,
|
|
107
|
+
}));
|
|
108
|
+
const { query } = state;
|
|
109
|
+
const runId = React.useRef(0);
|
|
110
|
+
const input = React.useRef<HTMLTextAreaElement>(null);
|
|
111
|
+
const [menu, openMenu] = useContextMenu();
|
|
112
|
+
// The box grows with the text (Shift+Enter for another line), as the one of an IDE.
|
|
113
|
+
React.useLayoutEffect(() => {
|
|
114
|
+
const element = input.current;
|
|
115
|
+
if (element) {
|
|
116
|
+
element.style.height = 'auto';
|
|
117
|
+
element.style.height = `${Math.min(element.scrollHeight, 160)}px`;
|
|
118
|
+
}
|
|
119
|
+
}, [query.pattern]);
|
|
120
|
+
const patternError = query.regex && query.pattern ? SearchUtil.patternError(query) : undefined;
|
|
121
|
+
const set = (patch: Partial<SearchState>) => setState(previous => ({ ...previous, ...patch }));
|
|
122
|
+
const change = (patch: Partial<TextQuery>) => setState(previous => ({ ...previous, query: { ...previous.query, ...patch } }));
|
|
123
|
+
|
|
124
|
+
SearchRequests.useReceive(request => {
|
|
125
|
+
if (request.cwd === cwd) {
|
|
126
|
+
setState(previous => ({ ...previous, showDetails: true, query: { ...previous.query, include: request.include } }));
|
|
127
|
+
input.current?.focus();
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
React.useEffect(() => {
|
|
132
|
+
const id = ++runId.current;
|
|
133
|
+
if (!query.pattern || patternError) {
|
|
134
|
+
setState(previous => ({ ...previous, result: undefined, error: undefined, busy: false }));
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
setState(previous => ({ ...previous, busy: true }));
|
|
138
|
+
const timer = setTimeout(() => {
|
|
139
|
+
WorkspaceClient.search(cwd, query).then(
|
|
140
|
+
result => id === runId.current && setState(previous => ({ ...previous, result, error: undefined, busy: false, dismissed: [] })),
|
|
141
|
+
error => id === runId.current && setState(previous => ({ ...previous, result: undefined, error: Host.message(error), busy: false })),
|
|
142
|
+
);
|
|
143
|
+
}, DEBOUNCE_MS);
|
|
144
|
+
return () => clearTimeout(timer);
|
|
145
|
+
}, [cwd, query, state.run, patternError]);
|
|
146
|
+
|
|
147
|
+
const matches = React.useMemo(
|
|
148
|
+
() => (state.result?.matches ?? []).filter(match => !state.dismissed.some(key => dismisses(key, match))),
|
|
149
|
+
[state.result, state.dismissed],
|
|
150
|
+
);
|
|
151
|
+
const groups = React.useMemo(() => WorkspaceUtil.groupMatches(matches), [matches]);
|
|
152
|
+
const tree = React.useMemo(
|
|
153
|
+
() =>
|
|
154
|
+
state.tree
|
|
155
|
+
? WorkspaceUtil.pathTree(
|
|
156
|
+
groups,
|
|
157
|
+
group => group.path,
|
|
158
|
+
group => group.matches.length,
|
|
159
|
+
)
|
|
160
|
+
: undefined,
|
|
161
|
+
[state.tree, groups],
|
|
162
|
+
);
|
|
163
|
+
const rows = React.useMemo(() => resultRows(groups, tree, new Set(state.collapsed)), [groups, tree, state.collapsed]);
|
|
164
|
+
/** What collapse all folds: the files, and the folders of the tree. */
|
|
165
|
+
const foldable = React.useMemo(() => [...groups.map(group => group.path), ...(tree ? folderKeys(tree) : [])], [groups, tree]);
|
|
166
|
+
const toggle = (key: string) =>
|
|
167
|
+
setState(previous => ({
|
|
168
|
+
...previous,
|
|
169
|
+
collapsed: previous.collapsed.includes(key) ? previous.collapsed.filter(other => other !== key) : [...previous.collapsed, key],
|
|
170
|
+
}));
|
|
171
|
+
const allCollapsed = foldable.length > 0 && foldable.every(key => state.collapsed.includes(key));
|
|
172
|
+
const dismiss = (key: string) => setState(previous => ({ ...previous, dismissed: [...previous.dismissed, key] }));
|
|
173
|
+
const refresh = () => setState(previous => ({ ...previous, run: previous.run + 1 }));
|
|
174
|
+
const replacing = state.showReplace;
|
|
175
|
+
|
|
176
|
+
/** Replaces in one file: all its matches, or one. */
|
|
177
|
+
const replaceIn = async (path: string, at?: TextMatch): Promise<number> => {
|
|
178
|
+
const file = await pi.workspace.readFile(path, cwd);
|
|
179
|
+
if (file.text === undefined || file.truncated) {
|
|
180
|
+
throw new Error(t('cannotReplace', { path }));
|
|
181
|
+
}
|
|
182
|
+
const done = SearchUtil.replace(file.text, query, state.replace, at && { line: at.line, column: at.column });
|
|
183
|
+
if (done.count) {
|
|
184
|
+
await pi.workspace.writeFile(path, done.text, cwd);
|
|
185
|
+
}
|
|
186
|
+
return done.count;
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
const replace = async (paths: string[], at?: TextMatch) => {
|
|
190
|
+
try {
|
|
191
|
+
for (const path of paths) {
|
|
192
|
+
await replaceIn(path, at);
|
|
193
|
+
}
|
|
194
|
+
} catch (error) {
|
|
195
|
+
pi.ui.notify(Host.message(error), 'error');
|
|
196
|
+
}
|
|
197
|
+
FilesChanged.notify();
|
|
198
|
+
refresh();
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
const replaceAll = async () => {
|
|
202
|
+
const count = matches.length;
|
|
203
|
+
const files = groups.length;
|
|
204
|
+
if (!count) {
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
const confirmed = await pi.ui.confirm(t('replaceAllTitle', { count, files, text: state.replace }), undefined, {
|
|
208
|
+
confirmLabel: t('replaceAll'),
|
|
209
|
+
});
|
|
210
|
+
if (confirmed) {
|
|
211
|
+
await replace(groups.map(group => group.path));
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
const onPatternKey = (event: React.KeyboardEvent<HTMLTextAreaElement>) => {
|
|
216
|
+
if (event.key === 'Enter' && !event.shiftKey) {
|
|
217
|
+
event.preventDefault();
|
|
218
|
+
refresh();
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
const fileMenu = (path: string): MenuItem[] => [
|
|
223
|
+
{ label: t('open'), run: () => openFile(cwd, path) },
|
|
224
|
+
...(replacing ? [{ label: t('replaceAllInFile'), run: () => void replace([path]) }] : []),
|
|
225
|
+
{ label: t('dismiss'), run: () => dismiss(path) },
|
|
226
|
+
'-',
|
|
227
|
+
{ label: t('copyRelativePath'), run: () => copyText(path, t('copied')) },
|
|
228
|
+
];
|
|
229
|
+
|
|
230
|
+
const summary = () => {
|
|
231
|
+
if (!state.result || !query.pattern) {
|
|
232
|
+
return null;
|
|
233
|
+
}
|
|
234
|
+
if (groups.length === 0) {
|
|
235
|
+
return <div className="taw-summary">{t('noResults')}</div>;
|
|
236
|
+
}
|
|
237
|
+
return (
|
|
238
|
+
<div className="taw-summary">
|
|
239
|
+
{t('results', { count: matches.length, files: groups.length })}
|
|
240
|
+
{state.result.truncated && <div className="taw-warning">{t('moreResults', { count: state.result.matches.length })}</div>}
|
|
241
|
+
</div>
|
|
242
|
+
);
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
return (
|
|
246
|
+
<div className="taw-view">
|
|
247
|
+
<div className="taw-search-form">
|
|
248
|
+
<button
|
|
249
|
+
type="button"
|
|
250
|
+
className="taw-search-toggle"
|
|
251
|
+
aria-expanded={replacing}
|
|
252
|
+
title={t('toggleReplace')}
|
|
253
|
+
aria-label={t('toggleReplace')}
|
|
254
|
+
onClick={() => set({ showReplace: !replacing })}
|
|
255
|
+
>
|
|
256
|
+
<Glyph name={replacing ? 'ChevronDown' : 'ChevronRight'} size={14} />
|
|
257
|
+
</button>
|
|
258
|
+
<div className="taw-search-fields">
|
|
259
|
+
<div className={`taw-field ${patternError ? 'taw-invalid' : ''}`}>
|
|
260
|
+
<textarea
|
|
261
|
+
ref={input}
|
|
262
|
+
rows={1}
|
|
263
|
+
className="taw-input taw-search-input"
|
|
264
|
+
value={query.pattern}
|
|
265
|
+
placeholder={t('searchPlaceholder')}
|
|
266
|
+
aria-label={t('searchPlaceholder')}
|
|
267
|
+
spellCheck={false}
|
|
268
|
+
onChange={event => change({ pattern: event.target.value })}
|
|
269
|
+
onKeyDown={onPatternKey}
|
|
270
|
+
/>
|
|
271
|
+
<Action
|
|
272
|
+
icon="CaseSensitive"
|
|
273
|
+
label={t('matchCase')}
|
|
274
|
+
active={!!query.caseSensitive}
|
|
275
|
+
onClick={() => change({ caseSensitive: !query.caseSensitive })}
|
|
276
|
+
/>
|
|
277
|
+
<Action
|
|
278
|
+
icon="WholeWord"
|
|
279
|
+
label={t('matchWholeWord')}
|
|
280
|
+
active={!!query.wholeWord}
|
|
281
|
+
onClick={() => change({ wholeWord: !query.wholeWord })}
|
|
282
|
+
/>
|
|
283
|
+
<Action icon="Regex" label={t('useRegex')} active={!!query.regex} onClick={() => change({ regex: !query.regex })} />
|
|
284
|
+
</div>
|
|
285
|
+
{patternError && <div className="taw-input-message taw-error">{patternError}</div>}
|
|
286
|
+
{replacing && (
|
|
287
|
+
<div className="taw-replace-row">
|
|
288
|
+
<div className="taw-field">
|
|
289
|
+
<input
|
|
290
|
+
className="taw-input"
|
|
291
|
+
value={state.replace}
|
|
292
|
+
placeholder={t('replacePlaceholder')}
|
|
293
|
+
aria-label={t('replacePlaceholder')}
|
|
294
|
+
spellCheck={false}
|
|
295
|
+
onChange={event => set({ replace: event.target.value })}
|
|
296
|
+
onKeyDown={event => {
|
|
297
|
+
if (event.key === 'Enter' && (event.metaKey || event.ctrlKey) && event.altKey) {
|
|
298
|
+
event.preventDefault();
|
|
299
|
+
void replaceAll();
|
|
300
|
+
}
|
|
301
|
+
}}
|
|
302
|
+
/>
|
|
303
|
+
</div>
|
|
304
|
+
<Action icon="ReplaceAll" label={t('replaceAll')} disabled={matches.length === 0} onClick={() => void replaceAll()} />
|
|
305
|
+
</div>
|
|
306
|
+
)}
|
|
307
|
+
<div className="taw-details-toggle">
|
|
308
|
+
<Action
|
|
309
|
+
icon="Ellipsis"
|
|
310
|
+
label={t('toggleDetails')}
|
|
311
|
+
active={state.showDetails}
|
|
312
|
+
onClick={() => set({ showDetails: !state.showDetails })}
|
|
313
|
+
/>
|
|
314
|
+
</div>
|
|
315
|
+
{state.showDetails && (
|
|
316
|
+
<div className="taw-search-details">
|
|
317
|
+
<label className="taw-search-label">
|
|
318
|
+
<span>{t('filesToInclude')}</span>
|
|
319
|
+
<input
|
|
320
|
+
className="taw-input"
|
|
321
|
+
value={query.include ?? ''}
|
|
322
|
+
placeholder={t('includePlaceholder')}
|
|
323
|
+
spellCheck={false}
|
|
324
|
+
onChange={event => change({ include: event.target.value })}
|
|
325
|
+
/>
|
|
326
|
+
</label>
|
|
327
|
+
<label className="taw-search-label">
|
|
328
|
+
<span>{t('filesToExclude')}</span>
|
|
329
|
+
<input
|
|
330
|
+
className="taw-input"
|
|
331
|
+
value={query.exclude ?? ''}
|
|
332
|
+
placeholder={t('excludePlaceholder')}
|
|
333
|
+
spellCheck={false}
|
|
334
|
+
onChange={event => change({ exclude: event.target.value })}
|
|
335
|
+
/>
|
|
336
|
+
</label>
|
|
337
|
+
</div>
|
|
338
|
+
)}
|
|
339
|
+
</div>
|
|
340
|
+
</div>
|
|
341
|
+
<div className="taw-results-head">
|
|
342
|
+
<div className="taw-results-summary">
|
|
343
|
+
{state.busy ? <span className="taw-progress" role="progressbar" aria-label={t('loading')} /> : summary()}
|
|
344
|
+
</div>
|
|
345
|
+
<div className="taw-actions">
|
|
346
|
+
<Action icon="RefreshCw" label={t('refresh')} disabled={!query.pattern} onClick={refresh} />
|
|
347
|
+
<Action
|
|
348
|
+
icon="ListX"
|
|
349
|
+
label={t('clearResults')}
|
|
350
|
+
disabled={!query.pattern}
|
|
351
|
+
onClick={() => setState(previous => ({ ...previous, query: { ...previous.query, pattern: '' }, replace: '' }))}
|
|
352
|
+
/>
|
|
353
|
+
<Action
|
|
354
|
+
icon={allCollapsed ? 'ChevronsUpDown' : 'ChevronsDownUp'}
|
|
355
|
+
label={t(allCollapsed ? 'expandAll' : 'collapseAll')}
|
|
356
|
+
disabled={groups.length === 0}
|
|
357
|
+
onClick={() => set({ collapsed: allCollapsed ? [] : foldable })}
|
|
358
|
+
/>
|
|
359
|
+
<Action
|
|
360
|
+
icon={state.tree ? 'List' : 'ListTree'}
|
|
361
|
+
label={t(state.tree ? 'viewAsList' : 'viewAsTree')}
|
|
362
|
+
onClick={() => set({ tree: !state.tree })}
|
|
363
|
+
/>
|
|
364
|
+
</div>
|
|
365
|
+
</div>
|
|
366
|
+
<div className="taw-list" role="tree" aria-label={t('search')}>
|
|
367
|
+
{state.error && <Empty tone="error">{t('failed', { message: state.error })}</Empty>}
|
|
368
|
+
{rows.map(row => {
|
|
369
|
+
if (row.kind === 'folder') {
|
|
370
|
+
const open = !state.collapsed.includes(row.key);
|
|
371
|
+
const paths = groups.filter(group => WorkspaceUtil.within(group.path, row.folder.path)).map(group => group.path);
|
|
372
|
+
return (
|
|
373
|
+
<div
|
|
374
|
+
key={row.key}
|
|
375
|
+
role="treeitem"
|
|
376
|
+
tabIndex={0}
|
|
377
|
+
aria-expanded={open}
|
|
378
|
+
aria-level={row.depth + 1}
|
|
379
|
+
className="taw-row taw-result-file"
|
|
380
|
+
style={{ paddingLeft: 8 + row.depth * INDENT }}
|
|
381
|
+
title={row.folder.path}
|
|
382
|
+
onClick={() => toggle(row.key)}
|
|
383
|
+
onKeyDown={event => onToggleKey(event, () => toggle(row.key))}
|
|
384
|
+
onContextMenu={event =>
|
|
385
|
+
openMenu(event, [
|
|
386
|
+
...(replacing ? [{ label: t('replaceAllInFolder'), run: () => void replace(paths) }] : []),
|
|
387
|
+
{ label: t('dismiss'), run: () => dismiss(row.key) },
|
|
388
|
+
'-',
|
|
389
|
+
{ label: t('copyRelativePath'), run: () => copyText(row.folder.path, t('copied')) },
|
|
390
|
+
])
|
|
391
|
+
}
|
|
392
|
+
>
|
|
393
|
+
<span className="taw-twisty">
|
|
394
|
+
<Glyph name={open ? 'ChevronDown' : 'ChevronRight'} size={14} />
|
|
395
|
+
</span>
|
|
396
|
+
<Glyph name={open ? 'FolderOpen' : 'Folder'} />
|
|
397
|
+
<span className="taw-name">{row.folder.name}</span>
|
|
398
|
+
<span className="taw-row-actions">
|
|
399
|
+
{replacing && <Action icon="ReplaceAll" label={t('replaceAllInFolder')} onClick={() => void replace(paths)} />}
|
|
400
|
+
<Action icon="X" label={t('dismiss')} onClick={() => dismiss(row.key)} />
|
|
401
|
+
</span>
|
|
402
|
+
<span className="taw-badge">{row.folder.size}</span>
|
|
403
|
+
</div>
|
|
404
|
+
);
|
|
405
|
+
}
|
|
406
|
+
if (row.kind === 'file') {
|
|
407
|
+
const { group } = row;
|
|
408
|
+
const open = !state.collapsed.includes(group.path);
|
|
409
|
+
return (
|
|
410
|
+
<div
|
|
411
|
+
key={group.path}
|
|
412
|
+
role="treeitem"
|
|
413
|
+
tabIndex={0}
|
|
414
|
+
aria-expanded={open}
|
|
415
|
+
aria-level={row.depth + 1}
|
|
416
|
+
className="taw-row taw-result-file"
|
|
417
|
+
style={{ paddingLeft: 8 + row.depth * INDENT }}
|
|
418
|
+
title={group.path}
|
|
419
|
+
onClick={() => toggle(group.path)}
|
|
420
|
+
onKeyDown={event => onToggleKey(event, () => toggle(group.path))}
|
|
421
|
+
onContextMenu={event => openMenu(event, fileMenu(group.path))}
|
|
422
|
+
>
|
|
423
|
+
<span className="taw-twisty">
|
|
424
|
+
<Glyph name={open ? 'ChevronDown' : 'ChevronRight'} size={14} />
|
|
425
|
+
</span>
|
|
426
|
+
<FileIcon path={group.path} />
|
|
427
|
+
<span className="taw-name">{WorkspaceUtil.basename(group.path)}</span>
|
|
428
|
+
{!tree && <span className="taw-detail">{WorkspaceUtil.dirname(group.path)}</span>}
|
|
429
|
+
<span className="taw-row-actions">
|
|
430
|
+
{replacing && <Action icon="ReplaceAll" label={t('replaceAllInFile')} onClick={() => void replace([group.path])} />}
|
|
431
|
+
<Action icon="X" label={t('dismiss')} onClick={() => dismiss(group.path)} />
|
|
432
|
+
</span>
|
|
433
|
+
<span className="taw-badge">{group.matches.length}</span>
|
|
434
|
+
</div>
|
|
435
|
+
);
|
|
436
|
+
}
|
|
437
|
+
const { match } = row;
|
|
438
|
+
const [before, found, after] = WorkspaceUtil.highlight(match);
|
|
439
|
+
const target = { line: match.line, column: match.column, endColumn: match.column + match.length };
|
|
440
|
+
return (
|
|
441
|
+
<div
|
|
442
|
+
key={matchKey(match)}
|
|
443
|
+
role="treeitem"
|
|
444
|
+
tabIndex={0}
|
|
445
|
+
aria-level={row.depth + 1}
|
|
446
|
+
className="taw-row taw-match"
|
|
447
|
+
style={{ paddingLeft: 28 + row.depth * INDENT }}
|
|
448
|
+
title={`${t('line', { line: match.line })} ${match.preview}`}
|
|
449
|
+
onClick={() => openFile(cwd, match.path, target, { preview: true })}
|
|
450
|
+
onDoubleClick={() => openFile(cwd, match.path, target)}
|
|
451
|
+
onKeyDown={event => event.key === 'Enter' && openFile(cwd, match.path, target)}
|
|
452
|
+
onContextMenu={event =>
|
|
453
|
+
openMenu(event, [
|
|
454
|
+
{ label: t('open'), run: () => openFile(cwd, match.path, target) },
|
|
455
|
+
...(replacing ? [{ label: t('replace'), run: () => void replace([match.path], match) }] : []),
|
|
456
|
+
{ label: t('dismiss'), run: () => dismiss(matchKey(match)) },
|
|
457
|
+
'-',
|
|
458
|
+
{ label: t('copy'), run: () => copyText(match.preview, t('copied')) },
|
|
459
|
+
])
|
|
460
|
+
}
|
|
461
|
+
>
|
|
462
|
+
<span className="taw-preview">
|
|
463
|
+
{before}
|
|
464
|
+
{replacing ? (
|
|
465
|
+
<React.Fragment>
|
|
466
|
+
<del>{found}</del>
|
|
467
|
+
<ins>{state.replace}</ins>
|
|
468
|
+
</React.Fragment>
|
|
469
|
+
) : (
|
|
470
|
+
<mark>{found}</mark>
|
|
471
|
+
)}
|
|
472
|
+
{after}
|
|
473
|
+
</span>
|
|
474
|
+
<span className="taw-row-actions">
|
|
475
|
+
{replacing && <Action icon="Replace" label={t('replace')} onClick={() => void replace([match.path], match)} />}
|
|
476
|
+
<Action icon="X" label={t('dismiss')} onClick={() => dismiss(matchKey(match))} />
|
|
477
|
+
</span>
|
|
478
|
+
</div>
|
|
479
|
+
);
|
|
480
|
+
})}
|
|
481
|
+
</div>
|
|
482
|
+
{menu}
|
|
483
|
+
</div>
|
|
484
|
+
);
|
|
485
|
+
}
|