@theia/notebook 1.53.0-next.5 → 1.53.0-next.55

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.
Files changed (88) hide show
  1. package/README.md +30 -30
  2. package/lib/browser/contributions/notebook-actions-contribution.d.ts +1 -0
  3. package/lib/browser/contributions/notebook-actions-contribution.d.ts.map +1 -1
  4. package/lib/browser/contributions/notebook-actions-contribution.js +31 -5
  5. package/lib/browser/contributions/notebook-actions-contribution.js.map +1 -1
  6. package/lib/browser/contributions/notebook-cell-actions-contribution.d.ts +2 -0
  7. package/lib/browser/contributions/notebook-cell-actions-contribution.d.ts.map +1 -1
  8. package/lib/browser/contributions/notebook-cell-actions-contribution.js +41 -7
  9. package/lib/browser/contributions/notebook-cell-actions-contribution.js.map +1 -1
  10. package/lib/browser/contributions/notebook-status-bar-contribution.d.ts +14 -0
  11. package/lib/browser/contributions/notebook-status-bar-contribution.d.ts.map +1 -0
  12. package/lib/browser/contributions/notebook-status-bar-contribution.js +75 -0
  13. package/lib/browser/contributions/notebook-status-bar-contribution.js.map +1 -0
  14. package/lib/browser/notebook-editor-widget.d.ts.map +1 -1
  15. package/lib/browser/notebook-editor-widget.js +3 -5
  16. package/lib/browser/notebook-editor-widget.js.map +1 -1
  17. package/lib/browser/notebook-frontend-module.d.ts.map +1 -1
  18. package/lib/browser/notebook-frontend-module.js +3 -0
  19. package/lib/browser/notebook-frontend-module.js.map +1 -1
  20. package/lib/browser/notebook-open-handler.d.ts +3 -2
  21. package/lib/browser/notebook-open-handler.d.ts.map +1 -1
  22. package/lib/browser/notebook-open-handler.js +12 -5
  23. package/lib/browser/notebook-open-handler.js.map +1 -1
  24. package/lib/browser/view/notebook-cell-editor.d.ts +1 -0
  25. package/lib/browser/view/notebook-cell-editor.d.ts.map +1 -1
  26. package/lib/browser/view/notebook-cell-editor.js +30 -16
  27. package/lib/browser/view/notebook-cell-editor.js.map +1 -1
  28. package/lib/browser/view/notebook-cell-list-view.d.ts +6 -4
  29. package/lib/browser/view/notebook-cell-list-view.d.ts.map +1 -1
  30. package/lib/browser/view/notebook-cell-list-view.js +20 -13
  31. package/lib/browser/view/notebook-cell-list-view.js.map +1 -1
  32. package/lib/browser/view-model/notebook-cell-model.d.ts +3 -0
  33. package/lib/browser/view-model/notebook-cell-model.d.ts.map +1 -1
  34. package/lib/browser/view-model/notebook-cell-model.js +5 -0
  35. package/lib/browser/view-model/notebook-cell-model.js.map +1 -1
  36. package/package.json +8 -8
  37. package/src/browser/contributions/cell-operations.ts +44 -44
  38. package/src/browser/contributions/notebook-actions-contribution.ts +379 -350
  39. package/src/browser/contributions/notebook-cell-actions-contribution.ts +525 -487
  40. package/src/browser/contributions/notebook-color-contribution.ts +268 -268
  41. package/src/browser/contributions/notebook-context-keys.ts +113 -113
  42. package/src/browser/contributions/notebook-label-provider-contribution.ts +85 -85
  43. package/src/browser/contributions/notebook-outline-contribution.ts +114 -114
  44. package/src/browser/contributions/notebook-output-action-contribution.ts +82 -82
  45. package/src/browser/contributions/notebook-preferences.ts +92 -92
  46. package/src/browser/contributions/notebook-status-bar-contribution.ts +77 -0
  47. package/src/browser/contributions/notebook-undo-redo-handler.ts +41 -41
  48. package/src/browser/index.ts +27 -27
  49. package/src/browser/notebook-cell-resource-resolver.ts +130 -130
  50. package/src/browser/notebook-editor-widget-factory.ts +82 -82
  51. package/src/browser/notebook-editor-widget.tsx +330 -331
  52. package/src/browser/notebook-frontend-module.ts +119 -115
  53. package/src/browser/notebook-open-handler.ts +120 -114
  54. package/src/browser/notebook-output-utils.ts +119 -119
  55. package/src/browser/notebook-renderer-registry.ts +85 -85
  56. package/src/browser/notebook-type-registry.ts +54 -54
  57. package/src/browser/notebook-types.ts +186 -186
  58. package/src/browser/renderers/cell-output-webview.ts +33 -33
  59. package/src/browser/service/notebook-clipboard-service.ts +43 -43
  60. package/src/browser/service/notebook-context-manager.ts +162 -162
  61. package/src/browser/service/notebook-editor-widget-service.ts +101 -101
  62. package/src/browser/service/notebook-execution-service.ts +139 -139
  63. package/src/browser/service/notebook-execution-state-service.ts +311 -311
  64. package/src/browser/service/notebook-kernel-history-service.ts +124 -124
  65. package/src/browser/service/notebook-kernel-quick-pick-service.ts +479 -479
  66. package/src/browser/service/notebook-kernel-service.ts +357 -357
  67. package/src/browser/service/notebook-model-resolver-service.ts +160 -160
  68. package/src/browser/service/notebook-monaco-text-model-service.ts +48 -48
  69. package/src/browser/service/notebook-options.ts +155 -155
  70. package/src/browser/service/notebook-renderer-messaging-service.ts +121 -121
  71. package/src/browser/service/notebook-service.ts +215 -215
  72. package/src/browser/style/index.css +483 -471
  73. package/src/browser/view/notebook-cell-editor.tsx +263 -247
  74. package/src/browser/view/notebook-cell-list-view.tsx +279 -262
  75. package/src/browser/view/notebook-cell-toolbar-factory.tsx +102 -102
  76. package/src/browser/view/notebook-cell-toolbar.tsx +74 -74
  77. package/src/browser/view/notebook-code-cell-view.tsx +350 -350
  78. package/src/browser/view/notebook-find-widget.tsx +335 -335
  79. package/src/browser/view/notebook-main-toolbar.tsx +235 -235
  80. package/src/browser/view/notebook-markdown-cell-view.tsx +208 -208
  81. package/src/browser/view/notebook-viewport-service.ts +61 -61
  82. package/src/browser/view-model/notebook-cell-model.ts +473 -466
  83. package/src/browser/view-model/notebook-cell-output-model.ts +100 -100
  84. package/src/browser/view-model/notebook-model.ts +550 -550
  85. package/src/common/index.ts +18 -18
  86. package/src/common/notebook-common.ts +337 -337
  87. package/src/common/notebook-protocol.ts +35 -35
  88. 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
+ }