@theia/notebook 1.53.0-next.55 → 1.53.0-next.64
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 +30 -30
- package/lib/browser/index.d.ts +1 -0
- package/lib/browser/index.d.ts.map +1 -1
- package/lib/browser/index.js +1 -0
- package/lib/browser/index.js.map +1 -1
- package/lib/browser/notebook-frontend-module.d.ts.map +1 -1
- package/lib/browser/notebook-frontend-module.js +2 -0
- package/lib/browser/notebook-frontend-module.js.map +1 -1
- package/lib/browser/service/notebook-cell-editor-service.d.ts +16 -0
- package/lib/browser/service/notebook-cell-editor-service.d.ts.map +1 -0
- package/lib/browser/service/notebook-cell-editor-service.js +53 -0
- package/lib/browser/service/notebook-cell-editor-service.js.map +1 -0
- package/lib/browser/view/notebook-cell-editor.d.ts +2 -0
- package/lib/browser/view/notebook-cell-editor.d.ts.map +1 -1
- package/lib/browser/view/notebook-cell-editor.js +12 -1
- package/lib/browser/view/notebook-cell-editor.js.map +1 -1
- package/lib/browser/view/notebook-code-cell-view.d.ts +2 -0
- package/lib/browser/view/notebook-code-cell-view.d.ts.map +1 -1
- package/lib/browser/view/notebook-code-cell-view.js +6 -1
- package/lib/browser/view/notebook-code-cell-view.js.map +1 -1
- package/lib/browser/view/notebook-markdown-cell-view.d.ts +2 -0
- package/lib/browser/view/notebook-markdown-cell-view.d.ts.map +1 -1
- package/lib/browser/view/notebook-markdown-cell-view.js +8 -3
- package/lib/browser/view/notebook-markdown-cell-view.js.map +1 -1
- package/package.json +7 -7
- package/src/browser/contributions/cell-operations.ts +44 -44
- package/src/browser/contributions/notebook-actions-contribution.ts +379 -379
- package/src/browser/contributions/notebook-cell-actions-contribution.ts +525 -525
- package/src/browser/contributions/notebook-color-contribution.ts +268 -268
- package/src/browser/contributions/notebook-context-keys.ts +113 -113
- package/src/browser/contributions/notebook-label-provider-contribution.ts +85 -85
- package/src/browser/contributions/notebook-outline-contribution.ts +114 -114
- package/src/browser/contributions/notebook-output-action-contribution.ts +82 -82
- package/src/browser/contributions/notebook-preferences.ts +92 -92
- package/src/browser/contributions/notebook-status-bar-contribution.ts +77 -77
- package/src/browser/contributions/notebook-undo-redo-handler.ts +41 -41
- package/src/browser/index.ts +28 -27
- package/src/browser/notebook-cell-resource-resolver.ts +130 -130
- package/src/browser/notebook-editor-widget-factory.ts +82 -82
- package/src/browser/notebook-editor-widget.tsx +330 -330
- package/src/browser/notebook-frontend-module.ts +121 -119
- package/src/browser/notebook-open-handler.ts +120 -120
- package/src/browser/notebook-output-utils.ts +119 -119
- package/src/browser/notebook-renderer-registry.ts +85 -85
- package/src/browser/notebook-type-registry.ts +54 -54
- package/src/browser/notebook-types.ts +186 -186
- package/src/browser/renderers/cell-output-webview.ts +33 -33
- package/src/browser/service/notebook-cell-editor-service.ts +56 -0
- package/src/browser/service/notebook-clipboard-service.ts +43 -43
- package/src/browser/service/notebook-context-manager.ts +162 -162
- package/src/browser/service/notebook-editor-widget-service.ts +101 -101
- package/src/browser/service/notebook-execution-service.ts +139 -139
- package/src/browser/service/notebook-execution-state-service.ts +311 -311
- package/src/browser/service/notebook-kernel-history-service.ts +124 -124
- package/src/browser/service/notebook-kernel-quick-pick-service.ts +479 -479
- package/src/browser/service/notebook-kernel-service.ts +357 -357
- package/src/browser/service/notebook-model-resolver-service.ts +160 -160
- package/src/browser/service/notebook-monaco-text-model-service.ts +48 -48
- package/src/browser/service/notebook-options.ts +155 -155
- package/src/browser/service/notebook-renderer-messaging-service.ts +121 -121
- package/src/browser/service/notebook-service.ts +215 -215
- package/src/browser/style/index.css +484 -483
- package/src/browser/view/notebook-cell-editor.tsx +276 -263
- package/src/browser/view/notebook-cell-list-view.tsx +279 -279
- package/src/browser/view/notebook-cell-toolbar-factory.tsx +102 -102
- package/src/browser/view/notebook-cell-toolbar.tsx +74 -74
- package/src/browser/view/notebook-code-cell-view.tsx +355 -350
- package/src/browser/view/notebook-find-widget.tsx +335 -335
- package/src/browser/view/notebook-main-toolbar.tsx +235 -235
- package/src/browser/view/notebook-markdown-cell-view.tsx +215 -208
- package/src/browser/view/notebook-viewport-service.ts +61 -61
- package/src/browser/view-model/notebook-cell-model.ts +473 -473
- package/src/browser/view-model/notebook-cell-output-model.ts +100 -100
- package/src/browser/view-model/notebook-model.ts +550 -550
- package/src/common/index.ts +18 -18
- package/src/common/notebook-common.ts +337 -337
- package/src/common/notebook-protocol.ts +35 -35
- package/src/common/notebook-range.ts +30 -30
|
@@ -1,335 +1,335 @@
|
|
|
1
|
-
// *****************************************************************************
|
|
2
|
-
// Copyright (C) 2024 TypeFox and others.
|
|
3
|
-
//
|
|
4
|
-
// This program and the accompanying materials are made available under the
|
|
5
|
-
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
-
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
-
//
|
|
8
|
-
// This Source Code may also be made available under the following Secondary
|
|
9
|
-
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
-
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
-
// with the GNU Classpath Exception which is available at
|
|
12
|
-
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
-
//
|
|
14
|
-
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
-
// *****************************************************************************
|
|
16
|
-
|
|
17
|
-
import { nls } from '@theia/core';
|
|
18
|
-
import * as React from '@theia/core/shared/react';
|
|
19
|
-
import { codicon } from '@theia/core/lib/browser';
|
|
20
|
-
import debounce = require('lodash/debounce');
|
|
21
|
-
|
|
22
|
-
export interface NotebookEditorFindMatch {
|
|
23
|
-
selected: boolean;
|
|
24
|
-
show(): void;
|
|
25
|
-
replace?(value: string): void;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export interface NotebookEditorFindMatchOptions {
|
|
29
|
-
search: string;
|
|
30
|
-
matchCase: boolean;
|
|
31
|
-
wholeWord: boolean;
|
|
32
|
-
regex: boolean;
|
|
33
|
-
activeFilters: string[];
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export interface NotebookEditorFindFilter {
|
|
37
|
-
id: string;
|
|
38
|
-
label: string;
|
|
39
|
-
active: boolean;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export interface NotebookEditorFindOptions {
|
|
43
|
-
search?: string;
|
|
44
|
-
jumpToMatch?: boolean;
|
|
45
|
-
matchCase?: boolean;
|
|
46
|
-
wholeWord?: boolean;
|
|
47
|
-
regex?: boolean;
|
|
48
|
-
modifyIndex?: (matches: NotebookEditorFindMatch[], index: number) => number;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export interface NotebookFindWidgetProps {
|
|
52
|
-
hidden?: boolean;
|
|
53
|
-
filters?: NotebookEditorFindFilter[];
|
|
54
|
-
onClose(): void;
|
|
55
|
-
onSearch(options: NotebookEditorFindMatchOptions): NotebookEditorFindMatch[];
|
|
56
|
-
onReplace(matches: NotebookEditorFindMatch[], value: string): void;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export interface NotebookFindWidgetState {
|
|
60
|
-
search: string;
|
|
61
|
-
replace: string;
|
|
62
|
-
expanded: boolean;
|
|
63
|
-
matchCase: boolean;
|
|
64
|
-
wholeWord: boolean;
|
|
65
|
-
regex: boolean;
|
|
66
|
-
activeFilters: string[];
|
|
67
|
-
currentMatch: number;
|
|
68
|
-
matches: NotebookEditorFindMatch[];
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export class NotebookFindWidget extends React.Component<NotebookFindWidgetProps, NotebookFindWidgetState> {
|
|
72
|
-
|
|
73
|
-
private searchRef = React.createRef<HTMLInputElement>();
|
|
74
|
-
private debounceSearch = debounce(this.search.bind(this), 50);
|
|
75
|
-
|
|
76
|
-
constructor(props: NotebookFindWidgetProps) {
|
|
77
|
-
super(props);
|
|
78
|
-
this.state = {
|
|
79
|
-
search: '',
|
|
80
|
-
replace: '',
|
|
81
|
-
currentMatch: 0,
|
|
82
|
-
matches: [],
|
|
83
|
-
expanded: false,
|
|
84
|
-
matchCase: false,
|
|
85
|
-
regex: false,
|
|
86
|
-
wholeWord: false,
|
|
87
|
-
activeFilters: props.filters?.filter(filter => filter.active).map(filter => filter.id) || []
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
override render(): React.ReactNode {
|
|
92
|
-
const hasMatches = this.hasMatches();
|
|
93
|
-
const canReplace = this.canReplace();
|
|
94
|
-
const canReplaceAll = this.canReplaceAll();
|
|
95
|
-
return (
|
|
96
|
-
<div onKeyUp={event => {
|
|
97
|
-
if (event.key === 'Escape') {
|
|
98
|
-
this.props.onClose();
|
|
99
|
-
}
|
|
100
|
-
}} className={`theia-notebook-find-widget ${!this.state.expanded ? 'search-mode' : ''} ${this.props.hidden ? 'hidden' : ''}`}>
|
|
101
|
-
<div className='theia-notebook-find-widget-expand' title={nls.localizeByDefault('Toggle Replace')} onClick={() => {
|
|
102
|
-
this.setState({
|
|
103
|
-
expanded: !this.state.expanded
|
|
104
|
-
});
|
|
105
|
-
}}>
|
|
106
|
-
<div className={codicon(`chevron-${this.state.expanded ? 'down' : 'right'}`)}></div>
|
|
107
|
-
</div>
|
|
108
|
-
<div className='theia-notebook-find-widget-inputs'>
|
|
109
|
-
<div className='theia-notebook-find-widget-input-wrapper'>
|
|
110
|
-
<input
|
|
111
|
-
ref={this.searchRef}
|
|
112
|
-
type='text'
|
|
113
|
-
className='theia-input theia-notebook-find-widget-input'
|
|
114
|
-
placeholder={nls.localizeByDefault('Find')}
|
|
115
|
-
value={this.state.search}
|
|
116
|
-
onChange={event => {
|
|
117
|
-
this.setState({
|
|
118
|
-
search: event.target.value
|
|
119
|
-
});
|
|
120
|
-
this.debounceSearch({});
|
|
121
|
-
}}
|
|
122
|
-
onKeyDown={event => {
|
|
123
|
-
if (event.key === 'Enter') {
|
|
124
|
-
if (event.shiftKey) {
|
|
125
|
-
this.gotoPreviousMatch();
|
|
126
|
-
} else {
|
|
127
|
-
this.gotoNextMatch();
|
|
128
|
-
}
|
|
129
|
-
event.preventDefault();
|
|
130
|
-
}
|
|
131
|
-
}}
|
|
132
|
-
/>
|
|
133
|
-
<div
|
|
134
|
-
className={`${codicon('case-sensitive', true)} option ${this.state.matchCase ? 'enabled' : ''}`}
|
|
135
|
-
title={nls.localizeByDefault('Match Case')}
|
|
136
|
-
onClick={() => {
|
|
137
|
-
this.search({
|
|
138
|
-
matchCase: !this.state.matchCase
|
|
139
|
-
});
|
|
140
|
-
}}></div>
|
|
141
|
-
<div
|
|
142
|
-
className={`${codicon('whole-word', true)} option ${this.state.wholeWord ? 'enabled' : ''}`}
|
|
143
|
-
title={nls.localizeByDefault('Match Whole Word')}
|
|
144
|
-
onClick={() => {
|
|
145
|
-
this.search({
|
|
146
|
-
wholeWord: !this.state.wholeWord
|
|
147
|
-
});
|
|
148
|
-
}}></div>
|
|
149
|
-
<div
|
|
150
|
-
className={`${codicon('regex', true)} option ${this.state.regex ? 'enabled' : ''}`}
|
|
151
|
-
title={nls.localizeByDefault('Use Regular Expression')}
|
|
152
|
-
onClick={() => {
|
|
153
|
-
this.search({
|
|
154
|
-
regex: !this.state.regex
|
|
155
|
-
});
|
|
156
|
-
}}></div>
|
|
157
|
-
{/* <div
|
|
158
|
-
className={`${codicon('filter', true)} option ${this.state.wholeWord ? 'enabled' : ''}`}
|
|
159
|
-
title={nls.localizeByDefault('Find Filters')}></div> */}
|
|
160
|
-
</div>
|
|
161
|
-
<input
|
|
162
|
-
type='text'
|
|
163
|
-
className='theia-input theia-notebook-find-widget-replace'
|
|
164
|
-
placeholder={nls.localizeByDefault('Replace')}
|
|
165
|
-
value={this.state.replace}
|
|
166
|
-
onChange={event => {
|
|
167
|
-
this.setState({
|
|
168
|
-
replace: event.target.value
|
|
169
|
-
});
|
|
170
|
-
}}
|
|
171
|
-
onKeyDown={event => {
|
|
172
|
-
if (event.key === 'Enter') {
|
|
173
|
-
this.replaceOne();
|
|
174
|
-
event.preventDefault();
|
|
175
|
-
}
|
|
176
|
-
}}
|
|
177
|
-
/>
|
|
178
|
-
</div>
|
|
179
|
-
<div className='theia-notebook-find-widget-buttons'>
|
|
180
|
-
<div className='theia-notebook-find-widget-buttons-first'>
|
|
181
|
-
<div className='theia-notebook-find-widget-matches-count'>
|
|
182
|
-
{this.getMatchesCount()}
|
|
183
|
-
</div>
|
|
184
|
-
<div
|
|
185
|
-
className={`${codicon('arrow-up', hasMatches)} ${hasMatches ? '' : 'disabled'}`}
|
|
186
|
-
title={nls.localizeByDefault('Previous Match')}
|
|
187
|
-
onClick={() => {
|
|
188
|
-
this.gotoPreviousMatch();
|
|
189
|
-
}}
|
|
190
|
-
></div>
|
|
191
|
-
<div
|
|
192
|
-
className={`${codicon('arrow-down', hasMatches)} ${hasMatches ? '' : 'disabled'}`}
|
|
193
|
-
title={nls.localizeByDefault('Next Match')}
|
|
194
|
-
onClick={() => {
|
|
195
|
-
this.gotoNextMatch();
|
|
196
|
-
}}
|
|
197
|
-
></div>
|
|
198
|
-
<div
|
|
199
|
-
className={codicon('close', true)}
|
|
200
|
-
title={nls.localizeByDefault('Close')}
|
|
201
|
-
onClick={() => {
|
|
202
|
-
this.props.onClose();
|
|
203
|
-
}}
|
|
204
|
-
></div>
|
|
205
|
-
</div>
|
|
206
|
-
<div className='theia-notebook-find-widget-buttons-second'>
|
|
207
|
-
<div
|
|
208
|
-
className={`${codicon('replace', canReplace)} ${canReplace ? '' : 'disabled'}`}
|
|
209
|
-
title={nls.localizeByDefault('Replace')}
|
|
210
|
-
onClick={() => {
|
|
211
|
-
this.replaceOne();
|
|
212
|
-
}}
|
|
213
|
-
></div>
|
|
214
|
-
<div
|
|
215
|
-
className={`${codicon('replace-all', canReplaceAll)} ${canReplaceAll ? '' : 'disabled'}`}
|
|
216
|
-
title={nls.localizeByDefault('Replace All')}
|
|
217
|
-
onClick={() => {
|
|
218
|
-
this.replaceAll();
|
|
219
|
-
}}
|
|
220
|
-
></div>
|
|
221
|
-
</div>
|
|
222
|
-
</div>
|
|
223
|
-
</div>
|
|
224
|
-
);
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
private hasMatches(): boolean {
|
|
228
|
-
return this.state.matches.length > 0;
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
private canReplace(): boolean {
|
|
232
|
-
return Boolean(this.state.matches[this.state.currentMatch]?.replace);
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
private canReplaceAll(): boolean {
|
|
236
|
-
return this.state.matches.some(match => Boolean(match.replace));
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
private getMatchesCount(): string {
|
|
240
|
-
if (this.hasMatches()) {
|
|
241
|
-
return nls.localizeByDefault('{0} of {1}', this.state.currentMatch + 1, this.state.matches.length);
|
|
242
|
-
} else {
|
|
243
|
-
return nls.localizeByDefault('No results');
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
private gotoNextMatch(): void {
|
|
248
|
-
this.search({
|
|
249
|
-
modifyIndex: (matches, index) => (index + 1) % matches.length,
|
|
250
|
-
jumpToMatch: true
|
|
251
|
-
});
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
private gotoPreviousMatch(): void {
|
|
255
|
-
this.search({
|
|
256
|
-
modifyIndex: (matches, index) => (index === 0 ? matches.length : index) - 1,
|
|
257
|
-
jumpToMatch: true
|
|
258
|
-
});
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
private replaceOne(): void {
|
|
262
|
-
const existingMatches = this.state.matches;
|
|
263
|
-
const match = existingMatches[this.state.currentMatch];
|
|
264
|
-
if (match) {
|
|
265
|
-
match.replace?.(this.state.replace);
|
|
266
|
-
this.search({
|
|
267
|
-
jumpToMatch: true,
|
|
268
|
-
modifyIndex: (matches, index) => {
|
|
269
|
-
if (matches.length < existingMatches.length) {
|
|
270
|
-
return index % matches.length;
|
|
271
|
-
} else {
|
|
272
|
-
const diff = matches.length - existingMatches.length;
|
|
273
|
-
return (index + diff + 1) % matches.length;
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
});
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
private replaceAll(): void {
|
|
281
|
-
this.props.onReplace(this.state.matches, this.state.replace);
|
|
282
|
-
this.search({});
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
override componentDidUpdate(prevProps: Readonly<NotebookFindWidgetProps>, prevState: Readonly<NotebookFindWidgetState>): void {
|
|
286
|
-
if (!this.props.hidden && prevProps.hidden) {
|
|
287
|
-
// Focus the search input when the widget switches from hidden to visible.
|
|
288
|
-
this.searchRef.current?.focus();
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
focusSearch(content?: string): void {
|
|
293
|
-
this.searchRef.current?.focus();
|
|
294
|
-
if (content) {
|
|
295
|
-
this.search({
|
|
296
|
-
search: content,
|
|
297
|
-
jumpToMatch: false
|
|
298
|
-
});
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
search(options: NotebookEditorFindOptions): void {
|
|
303
|
-
const matchCase = options.matchCase ?? this.state.matchCase;
|
|
304
|
-
const wholeWord = options.wholeWord ?? this.state.wholeWord;
|
|
305
|
-
const regex = options.regex ?? this.state.regex;
|
|
306
|
-
const search = options.search ?? this.state.search;
|
|
307
|
-
const matches = this.props.onSearch({
|
|
308
|
-
search,
|
|
309
|
-
matchCase,
|
|
310
|
-
wholeWord,
|
|
311
|
-
regex,
|
|
312
|
-
activeFilters: this.state.activeFilters
|
|
313
|
-
});
|
|
314
|
-
let currentMatch = Math.max(0, Math.min(this.state.currentMatch, matches.length - 1));
|
|
315
|
-
if (options.modifyIndex && matches.length > 0) {
|
|
316
|
-
currentMatch = options.modifyIndex(matches, currentMatch);
|
|
317
|
-
}
|
|
318
|
-
const selectedMatch = matches[currentMatch];
|
|
319
|
-
if (selectedMatch) {
|
|
320
|
-
selectedMatch.selected = true;
|
|
321
|
-
if (options.jumpToMatch) {
|
|
322
|
-
selectedMatch.show();
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
this.setState({
|
|
326
|
-
search,
|
|
327
|
-
matches,
|
|
328
|
-
currentMatch,
|
|
329
|
-
matchCase,
|
|
330
|
-
wholeWord,
|
|
331
|
-
regex
|
|
332
|
-
});
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
}
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2024 TypeFox and others.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
import { nls } from '@theia/core';
|
|
18
|
+
import * as React from '@theia/core/shared/react';
|
|
19
|
+
import { codicon } from '@theia/core/lib/browser';
|
|
20
|
+
import debounce = require('lodash/debounce');
|
|
21
|
+
|
|
22
|
+
export interface NotebookEditorFindMatch {
|
|
23
|
+
selected: boolean;
|
|
24
|
+
show(): void;
|
|
25
|
+
replace?(value: string): void;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface NotebookEditorFindMatchOptions {
|
|
29
|
+
search: string;
|
|
30
|
+
matchCase: boolean;
|
|
31
|
+
wholeWord: boolean;
|
|
32
|
+
regex: boolean;
|
|
33
|
+
activeFilters: string[];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface NotebookEditorFindFilter {
|
|
37
|
+
id: string;
|
|
38
|
+
label: string;
|
|
39
|
+
active: boolean;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface NotebookEditorFindOptions {
|
|
43
|
+
search?: string;
|
|
44
|
+
jumpToMatch?: boolean;
|
|
45
|
+
matchCase?: boolean;
|
|
46
|
+
wholeWord?: boolean;
|
|
47
|
+
regex?: boolean;
|
|
48
|
+
modifyIndex?: (matches: NotebookEditorFindMatch[], index: number) => number;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface NotebookFindWidgetProps {
|
|
52
|
+
hidden?: boolean;
|
|
53
|
+
filters?: NotebookEditorFindFilter[];
|
|
54
|
+
onClose(): void;
|
|
55
|
+
onSearch(options: NotebookEditorFindMatchOptions): NotebookEditorFindMatch[];
|
|
56
|
+
onReplace(matches: NotebookEditorFindMatch[], value: string): void;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface NotebookFindWidgetState {
|
|
60
|
+
search: string;
|
|
61
|
+
replace: string;
|
|
62
|
+
expanded: boolean;
|
|
63
|
+
matchCase: boolean;
|
|
64
|
+
wholeWord: boolean;
|
|
65
|
+
regex: boolean;
|
|
66
|
+
activeFilters: string[];
|
|
67
|
+
currentMatch: number;
|
|
68
|
+
matches: NotebookEditorFindMatch[];
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export class NotebookFindWidget extends React.Component<NotebookFindWidgetProps, NotebookFindWidgetState> {
|
|
72
|
+
|
|
73
|
+
private searchRef = React.createRef<HTMLInputElement>();
|
|
74
|
+
private debounceSearch = debounce(this.search.bind(this), 50);
|
|
75
|
+
|
|
76
|
+
constructor(props: NotebookFindWidgetProps) {
|
|
77
|
+
super(props);
|
|
78
|
+
this.state = {
|
|
79
|
+
search: '',
|
|
80
|
+
replace: '',
|
|
81
|
+
currentMatch: 0,
|
|
82
|
+
matches: [],
|
|
83
|
+
expanded: false,
|
|
84
|
+
matchCase: false,
|
|
85
|
+
regex: false,
|
|
86
|
+
wholeWord: false,
|
|
87
|
+
activeFilters: props.filters?.filter(filter => filter.active).map(filter => filter.id) || []
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
override render(): React.ReactNode {
|
|
92
|
+
const hasMatches = this.hasMatches();
|
|
93
|
+
const canReplace = this.canReplace();
|
|
94
|
+
const canReplaceAll = this.canReplaceAll();
|
|
95
|
+
return (
|
|
96
|
+
<div onKeyUp={event => {
|
|
97
|
+
if (event.key === 'Escape') {
|
|
98
|
+
this.props.onClose();
|
|
99
|
+
}
|
|
100
|
+
}} className={`theia-notebook-find-widget ${!this.state.expanded ? 'search-mode' : ''} ${this.props.hidden ? 'hidden' : ''}`}>
|
|
101
|
+
<div className='theia-notebook-find-widget-expand' title={nls.localizeByDefault('Toggle Replace')} onClick={() => {
|
|
102
|
+
this.setState({
|
|
103
|
+
expanded: !this.state.expanded
|
|
104
|
+
});
|
|
105
|
+
}}>
|
|
106
|
+
<div className={codicon(`chevron-${this.state.expanded ? 'down' : 'right'}`)}></div>
|
|
107
|
+
</div>
|
|
108
|
+
<div className='theia-notebook-find-widget-inputs'>
|
|
109
|
+
<div className='theia-notebook-find-widget-input-wrapper'>
|
|
110
|
+
<input
|
|
111
|
+
ref={this.searchRef}
|
|
112
|
+
type='text'
|
|
113
|
+
className='theia-input theia-notebook-find-widget-input'
|
|
114
|
+
placeholder={nls.localizeByDefault('Find')}
|
|
115
|
+
value={this.state.search}
|
|
116
|
+
onChange={event => {
|
|
117
|
+
this.setState({
|
|
118
|
+
search: event.target.value
|
|
119
|
+
});
|
|
120
|
+
this.debounceSearch({});
|
|
121
|
+
}}
|
|
122
|
+
onKeyDown={event => {
|
|
123
|
+
if (event.key === 'Enter') {
|
|
124
|
+
if (event.shiftKey) {
|
|
125
|
+
this.gotoPreviousMatch();
|
|
126
|
+
} else {
|
|
127
|
+
this.gotoNextMatch();
|
|
128
|
+
}
|
|
129
|
+
event.preventDefault();
|
|
130
|
+
}
|
|
131
|
+
}}
|
|
132
|
+
/>
|
|
133
|
+
<div
|
|
134
|
+
className={`${codicon('case-sensitive', true)} option ${this.state.matchCase ? 'enabled' : ''}`}
|
|
135
|
+
title={nls.localizeByDefault('Match Case')}
|
|
136
|
+
onClick={() => {
|
|
137
|
+
this.search({
|
|
138
|
+
matchCase: !this.state.matchCase
|
|
139
|
+
});
|
|
140
|
+
}}></div>
|
|
141
|
+
<div
|
|
142
|
+
className={`${codicon('whole-word', true)} option ${this.state.wholeWord ? 'enabled' : ''}`}
|
|
143
|
+
title={nls.localizeByDefault('Match Whole Word')}
|
|
144
|
+
onClick={() => {
|
|
145
|
+
this.search({
|
|
146
|
+
wholeWord: !this.state.wholeWord
|
|
147
|
+
});
|
|
148
|
+
}}></div>
|
|
149
|
+
<div
|
|
150
|
+
className={`${codicon('regex', true)} option ${this.state.regex ? 'enabled' : ''}`}
|
|
151
|
+
title={nls.localizeByDefault('Use Regular Expression')}
|
|
152
|
+
onClick={() => {
|
|
153
|
+
this.search({
|
|
154
|
+
regex: !this.state.regex
|
|
155
|
+
});
|
|
156
|
+
}}></div>
|
|
157
|
+
{/* <div
|
|
158
|
+
className={`${codicon('filter', true)} option ${this.state.wholeWord ? 'enabled' : ''}`}
|
|
159
|
+
title={nls.localizeByDefault('Find Filters')}></div> */}
|
|
160
|
+
</div>
|
|
161
|
+
<input
|
|
162
|
+
type='text'
|
|
163
|
+
className='theia-input theia-notebook-find-widget-replace'
|
|
164
|
+
placeholder={nls.localizeByDefault('Replace')}
|
|
165
|
+
value={this.state.replace}
|
|
166
|
+
onChange={event => {
|
|
167
|
+
this.setState({
|
|
168
|
+
replace: event.target.value
|
|
169
|
+
});
|
|
170
|
+
}}
|
|
171
|
+
onKeyDown={event => {
|
|
172
|
+
if (event.key === 'Enter') {
|
|
173
|
+
this.replaceOne();
|
|
174
|
+
event.preventDefault();
|
|
175
|
+
}
|
|
176
|
+
}}
|
|
177
|
+
/>
|
|
178
|
+
</div>
|
|
179
|
+
<div className='theia-notebook-find-widget-buttons'>
|
|
180
|
+
<div className='theia-notebook-find-widget-buttons-first'>
|
|
181
|
+
<div className='theia-notebook-find-widget-matches-count'>
|
|
182
|
+
{this.getMatchesCount()}
|
|
183
|
+
</div>
|
|
184
|
+
<div
|
|
185
|
+
className={`${codicon('arrow-up', hasMatches)} ${hasMatches ? '' : 'disabled'}`}
|
|
186
|
+
title={nls.localizeByDefault('Previous Match')}
|
|
187
|
+
onClick={() => {
|
|
188
|
+
this.gotoPreviousMatch();
|
|
189
|
+
}}
|
|
190
|
+
></div>
|
|
191
|
+
<div
|
|
192
|
+
className={`${codicon('arrow-down', hasMatches)} ${hasMatches ? '' : 'disabled'}`}
|
|
193
|
+
title={nls.localizeByDefault('Next Match')}
|
|
194
|
+
onClick={() => {
|
|
195
|
+
this.gotoNextMatch();
|
|
196
|
+
}}
|
|
197
|
+
></div>
|
|
198
|
+
<div
|
|
199
|
+
className={codicon('close', true)}
|
|
200
|
+
title={nls.localizeByDefault('Close')}
|
|
201
|
+
onClick={() => {
|
|
202
|
+
this.props.onClose();
|
|
203
|
+
}}
|
|
204
|
+
></div>
|
|
205
|
+
</div>
|
|
206
|
+
<div className='theia-notebook-find-widget-buttons-second'>
|
|
207
|
+
<div
|
|
208
|
+
className={`${codicon('replace', canReplace)} ${canReplace ? '' : 'disabled'}`}
|
|
209
|
+
title={nls.localizeByDefault('Replace')}
|
|
210
|
+
onClick={() => {
|
|
211
|
+
this.replaceOne();
|
|
212
|
+
}}
|
|
213
|
+
></div>
|
|
214
|
+
<div
|
|
215
|
+
className={`${codicon('replace-all', canReplaceAll)} ${canReplaceAll ? '' : 'disabled'}`}
|
|
216
|
+
title={nls.localizeByDefault('Replace All')}
|
|
217
|
+
onClick={() => {
|
|
218
|
+
this.replaceAll();
|
|
219
|
+
}}
|
|
220
|
+
></div>
|
|
221
|
+
</div>
|
|
222
|
+
</div>
|
|
223
|
+
</div>
|
|
224
|
+
);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
private hasMatches(): boolean {
|
|
228
|
+
return this.state.matches.length > 0;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
private canReplace(): boolean {
|
|
232
|
+
return Boolean(this.state.matches[this.state.currentMatch]?.replace);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
private canReplaceAll(): boolean {
|
|
236
|
+
return this.state.matches.some(match => Boolean(match.replace));
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
private getMatchesCount(): string {
|
|
240
|
+
if (this.hasMatches()) {
|
|
241
|
+
return nls.localizeByDefault('{0} of {1}', this.state.currentMatch + 1, this.state.matches.length);
|
|
242
|
+
} else {
|
|
243
|
+
return nls.localizeByDefault('No results');
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
private gotoNextMatch(): void {
|
|
248
|
+
this.search({
|
|
249
|
+
modifyIndex: (matches, index) => (index + 1) % matches.length,
|
|
250
|
+
jumpToMatch: true
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
private gotoPreviousMatch(): void {
|
|
255
|
+
this.search({
|
|
256
|
+
modifyIndex: (matches, index) => (index === 0 ? matches.length : index) - 1,
|
|
257
|
+
jumpToMatch: true
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
private replaceOne(): void {
|
|
262
|
+
const existingMatches = this.state.matches;
|
|
263
|
+
const match = existingMatches[this.state.currentMatch];
|
|
264
|
+
if (match) {
|
|
265
|
+
match.replace?.(this.state.replace);
|
|
266
|
+
this.search({
|
|
267
|
+
jumpToMatch: true,
|
|
268
|
+
modifyIndex: (matches, index) => {
|
|
269
|
+
if (matches.length < existingMatches.length) {
|
|
270
|
+
return index % matches.length;
|
|
271
|
+
} else {
|
|
272
|
+
const diff = matches.length - existingMatches.length;
|
|
273
|
+
return (index + diff + 1) % matches.length;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
private replaceAll(): void {
|
|
281
|
+
this.props.onReplace(this.state.matches, this.state.replace);
|
|
282
|
+
this.search({});
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
override componentDidUpdate(prevProps: Readonly<NotebookFindWidgetProps>, prevState: Readonly<NotebookFindWidgetState>): void {
|
|
286
|
+
if (!this.props.hidden && prevProps.hidden) {
|
|
287
|
+
// Focus the search input when the widget switches from hidden to visible.
|
|
288
|
+
this.searchRef.current?.focus();
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
focusSearch(content?: string): void {
|
|
293
|
+
this.searchRef.current?.focus();
|
|
294
|
+
if (content) {
|
|
295
|
+
this.search({
|
|
296
|
+
search: content,
|
|
297
|
+
jumpToMatch: false
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
search(options: NotebookEditorFindOptions): void {
|
|
303
|
+
const matchCase = options.matchCase ?? this.state.matchCase;
|
|
304
|
+
const wholeWord = options.wholeWord ?? this.state.wholeWord;
|
|
305
|
+
const regex = options.regex ?? this.state.regex;
|
|
306
|
+
const search = options.search ?? this.state.search;
|
|
307
|
+
const matches = this.props.onSearch({
|
|
308
|
+
search,
|
|
309
|
+
matchCase,
|
|
310
|
+
wholeWord,
|
|
311
|
+
regex,
|
|
312
|
+
activeFilters: this.state.activeFilters
|
|
313
|
+
});
|
|
314
|
+
let currentMatch = Math.max(0, Math.min(this.state.currentMatch, matches.length - 1));
|
|
315
|
+
if (options.modifyIndex && matches.length > 0) {
|
|
316
|
+
currentMatch = options.modifyIndex(matches, currentMatch);
|
|
317
|
+
}
|
|
318
|
+
const selectedMatch = matches[currentMatch];
|
|
319
|
+
if (selectedMatch) {
|
|
320
|
+
selectedMatch.selected = true;
|
|
321
|
+
if (options.jumpToMatch) {
|
|
322
|
+
selectedMatch.show();
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
this.setState({
|
|
326
|
+
search,
|
|
327
|
+
matches,
|
|
328
|
+
currentMatch,
|
|
329
|
+
matchCase,
|
|
330
|
+
wholeWord,
|
|
331
|
+
regex
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
}
|