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