@theia/notebook 1.52.0 → 1.53.0-next.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/browser/contributions/cell-operations.d.ts +1 -1
- package/lib/browser/contributions/cell-operations.d.ts.map +1 -1
- package/lib/browser/contributions/cell-operations.js +10 -2
- package/lib/browser/contributions/cell-operations.js.map +1 -1
- package/lib/browser/contributions/notebook-actions-contribution.d.ts +1 -0
- package/lib/browser/contributions/notebook-actions-contribution.d.ts.map +1 -1
- package/lib/browser/contributions/notebook-actions-contribution.js +19 -23
- package/lib/browser/contributions/notebook-actions-contribution.js.map +1 -1
- package/lib/browser/contributions/notebook-cell-actions-contribution.d.ts +2 -0
- package/lib/browser/contributions/notebook-cell-actions-contribution.d.ts.map +1 -1
- package/lib/browser/contributions/notebook-cell-actions-contribution.js +26 -15
- package/lib/browser/contributions/notebook-cell-actions-contribution.js.map +1 -1
- package/lib/browser/contributions/notebook-undo-redo-handler.d.ts +10 -0
- package/lib/browser/contributions/notebook-undo-redo-handler.d.ts.map +1 -0
- package/lib/browser/contributions/notebook-undo-redo-handler.js +49 -0
- package/lib/browser/contributions/notebook-undo-redo-handler.js.map +1 -0
- package/lib/browser/notebook-editor-widget.d.ts +6 -0
- package/lib/browser/notebook-editor-widget.d.ts.map +1 -1
- package/lib/browser/notebook-editor-widget.js +39 -1
- package/lib/browser/notebook-editor-widget.js.map +1 -1
- package/lib/browser/notebook-frontend-module.d.ts.map +1 -1
- package/lib/browser/notebook-frontend-module.js +3 -0
- package/lib/browser/notebook-frontend-module.js.map +1 -1
- package/lib/browser/service/notebook-context-manager.d.ts +2 -1
- package/lib/browser/service/notebook-context-manager.d.ts.map +1 -1
- package/lib/browser/service/notebook-context-manager.js +6 -3
- package/lib/browser/service/notebook-context-manager.js.map +1 -1
- package/lib/browser/service/notebook-options.d.ts +1 -0
- package/lib/browser/service/notebook-options.d.ts.map +1 -1
- package/lib/browser/service/notebook-options.js +1 -0
- package/lib/browser/service/notebook-options.js.map +1 -1
- package/lib/browser/service/notebook-service.d.ts +1 -0
- package/lib/browser/service/notebook-service.d.ts.map +1 -1
- package/lib/browser/service/notebook-service.js +7 -0
- package/lib/browser/service/notebook-service.js.map +1 -1
- package/lib/browser/view/notebook-cell-editor.d.ts +7 -1
- package/lib/browser/view/notebook-cell-editor.d.ts.map +1 -1
- package/lib/browser/view/notebook-cell-editor.js +75 -5
- package/lib/browser/view/notebook-cell-editor.js.map +1 -1
- package/lib/browser/view/notebook-cell-list-view.d.ts +3 -0
- package/lib/browser/view/notebook-cell-list-view.d.ts.map +1 -1
- package/lib/browser/view/notebook-cell-list-view.js +26 -2
- package/lib/browser/view/notebook-cell-list-view.js.map +1 -1
- package/lib/browser/view/notebook-code-cell-view.d.ts +1 -1
- package/lib/browser/view/notebook-code-cell-view.d.ts.map +1 -1
- package/lib/browser/view/notebook-code-cell-view.js +19 -17
- package/lib/browser/view/notebook-code-cell-view.js.map +1 -1
- package/lib/browser/view/notebook-find-widget.d.ts +63 -0
- package/lib/browser/view/notebook-find-widget.d.ts.map +1 -0
- package/lib/browser/view/notebook-find-widget.js +225 -0
- package/lib/browser/view/notebook-find-widget.js.map +1 -0
- package/lib/browser/view/notebook-markdown-cell-view.d.ts +4 -0
- package/lib/browser/view/notebook-markdown-cell-view.d.ts.map +1 -1
- package/lib/browser/view/notebook-markdown-cell-view.js +105 -8
- package/lib/browser/view/notebook-markdown-cell-view.js.map +1 -1
- package/lib/browser/view-model/notebook-cell-model.d.ts +24 -1
- package/lib/browser/view-model/notebook-cell-model.d.ts.map +1 -1
- package/lib/browser/view-model/notebook-cell-model.js +71 -1
- package/lib/browser/view-model/notebook-cell-model.js.map +1 -1
- package/lib/browser/view-model/notebook-model.d.ts +8 -1
- package/lib/browser/view-model/notebook-model.d.ts.map +1 -1
- package/lib/browser/view-model/notebook-model.js +66 -14
- package/lib/browser/view-model/notebook-model.js.map +1 -1
- package/package.json +8 -7
- package/src/browser/contributions/cell-operations.ts +8 -2
- package/src/browser/contributions/notebook-actions-contribution.ts +21 -22
- package/src/browser/contributions/notebook-cell-actions-contribution.ts +26 -16
- package/src/browser/contributions/notebook-undo-redo-handler.ts +41 -0
- package/src/browser/notebook-editor-widget.tsx +49 -2
- package/src/browser/notebook-frontend-module.ts +5 -1
- package/src/browser/service/notebook-context-manager.ts +8 -4
- package/src/browser/service/notebook-options.ts +2 -1
- package/src/browser/service/notebook-service.ts +7 -1
- package/src/browser/style/index.css +165 -6
- package/src/browser/view/notebook-cell-editor.tsx +79 -6
- package/src/browser/view/notebook-cell-list-view.tsx +32 -3
- package/src/browser/view/notebook-code-cell-view.tsx +19 -17
- package/src/browser/view/notebook-find-widget.tsx +335 -0
- package/src/browser/view/notebook-markdown-cell-view.tsx +134 -17
- package/src/browser/view-model/notebook-cell-model.ts +94 -8
- package/src/browser/view-model/notebook-model.ts +77 -20
|
@@ -0,0 +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
|
+
}
|
|
@@ -23,8 +23,12 @@ import { NotebookCellModel } from '../view-model/notebook-cell-model';
|
|
|
23
23
|
import { CellEditor } from './notebook-cell-editor';
|
|
24
24
|
import { inject, injectable } from '@theia/core/shared/inversify';
|
|
25
25
|
import { MonacoEditorServices } from '@theia/monaco/lib/browser/monaco-editor';
|
|
26
|
-
import { nls } from '@theia/core';
|
|
26
|
+
import { CommandRegistry, nls } from '@theia/core';
|
|
27
27
|
import { NotebookContextManager } from '../service/notebook-context-manager';
|
|
28
|
+
import { NotebookOptionsService } from '../service/notebook-options';
|
|
29
|
+
import { NotebookCodeCellStatus } from './notebook-code-cell-view';
|
|
30
|
+
import { NotebookEditorFindMatch, NotebookEditorFindMatchOptions } from './notebook-find-widget';
|
|
31
|
+
import * as mark from 'advanced-mark.js';
|
|
28
32
|
|
|
29
33
|
@injectable()
|
|
30
34
|
export class NotebookMarkdownCellRenderer implements CellRenderer {
|
|
@@ -37,9 +41,21 @@ export class NotebookMarkdownCellRenderer implements CellRenderer {
|
|
|
37
41
|
@inject(NotebookContextManager)
|
|
38
42
|
protected readonly notebookContextManager: NotebookContextManager;
|
|
39
43
|
|
|
44
|
+
@inject(CommandRegistry)
|
|
45
|
+
protected readonly commandRegistry: CommandRegistry;
|
|
46
|
+
|
|
47
|
+
@inject(NotebookOptionsService)
|
|
48
|
+
protected readonly notebookOptionsService: NotebookOptionsService;
|
|
49
|
+
|
|
40
50
|
render(notebookModel: NotebookModel, cell: NotebookCellModel): React.ReactNode {
|
|
41
|
-
return <MarkdownCell
|
|
42
|
-
|
|
51
|
+
return <MarkdownCell
|
|
52
|
+
markdownRenderer={this.markdownRenderer}
|
|
53
|
+
commandRegistry={this.commandRegistry}
|
|
54
|
+
monacoServices={this.monacoServices}
|
|
55
|
+
notebookOptionsService={this.notebookOptionsService}
|
|
56
|
+
cell={cell}
|
|
57
|
+
notebookModel={notebookModel}
|
|
58
|
+
notebookContextManager={this.notebookContextManager} />;
|
|
43
59
|
}
|
|
44
60
|
|
|
45
61
|
renderDragImage(cell: NotebookCellModel): HTMLElement {
|
|
@@ -53,39 +69,140 @@ export class NotebookMarkdownCellRenderer implements CellRenderer {
|
|
|
53
69
|
}
|
|
54
70
|
|
|
55
71
|
interface MarkdownCellProps {
|
|
56
|
-
markdownRenderer: MarkdownRenderer
|
|
57
|
-
monacoServices: MonacoEditorServices
|
|
72
|
+
markdownRenderer: MarkdownRenderer;
|
|
73
|
+
monacoServices: MonacoEditorServices;
|
|
58
74
|
|
|
59
|
-
|
|
60
|
-
|
|
75
|
+
commandRegistry: CommandRegistry;
|
|
76
|
+
cell: NotebookCellModel;
|
|
77
|
+
notebookModel: NotebookModel;
|
|
61
78
|
notebookContextManager: NotebookContextManager;
|
|
79
|
+
notebookOptionsService: NotebookOptionsService;
|
|
62
80
|
}
|
|
63
81
|
|
|
64
|
-
function MarkdownCell({
|
|
82
|
+
function MarkdownCell({
|
|
83
|
+
markdownRenderer, monacoServices, cell, notebookModel, notebookContextManager, notebookOptionsService, commandRegistry
|
|
84
|
+
}: MarkdownCellProps): React.JSX.Element {
|
|
65
85
|
const [editMode, setEditMode] = React.useState(cell.editing);
|
|
86
|
+
let empty = false;
|
|
66
87
|
|
|
67
88
|
React.useEffect(() => {
|
|
68
89
|
const listener = cell.onDidRequestCellEditChange(cellEdit => setEditMode(cellEdit));
|
|
69
90
|
return () => listener.dispose();
|
|
70
91
|
}, [editMode]);
|
|
71
92
|
|
|
72
|
-
|
|
93
|
+
React.useEffect(() => {
|
|
94
|
+
if (!editMode) {
|
|
95
|
+
const instance = new mark(markdownContent);
|
|
96
|
+
cell.onMarkdownFind = options => {
|
|
97
|
+
instance.unmark();
|
|
98
|
+
if (empty) {
|
|
99
|
+
return [];
|
|
100
|
+
}
|
|
101
|
+
return searchInMarkdown(instance, options);
|
|
102
|
+
};
|
|
103
|
+
return () => {
|
|
104
|
+
cell.onMarkdownFind = undefined;
|
|
105
|
+
instance.unmark();
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
}, [editMode, cell.source]);
|
|
109
|
+
|
|
110
|
+
let markdownContent: HTMLElement[] = React.useMemo(() => {
|
|
73
111
|
const markdownString = new MarkdownStringImpl(cell.source, { supportHtml: true, isTrusted: true });
|
|
74
|
-
|
|
75
|
-
|
|
112
|
+
const rendered = markdownRenderer.render(markdownString).element;
|
|
113
|
+
const children: HTMLElement[] = [];
|
|
114
|
+
rendered.childNodes.forEach(child => {
|
|
115
|
+
if (child instanceof HTMLElement) {
|
|
116
|
+
children.push(child);
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
return children;
|
|
120
|
+
}, [cell.source]);
|
|
76
121
|
|
|
77
|
-
if (
|
|
122
|
+
if (markdownContent.length === 0) {
|
|
78
123
|
const italic = document.createElement('i');
|
|
79
124
|
italic.className = 'theia-notebook-empty-markdown';
|
|
80
125
|
italic.innerText = nls.localizeByDefault('Empty markdown cell, double-click or press enter to edit.');
|
|
81
126
|
italic.style.pointerEvents = 'none';
|
|
82
|
-
markdownContent = italic;
|
|
127
|
+
markdownContent = [italic];
|
|
128
|
+
empty = true;
|
|
83
129
|
}
|
|
84
130
|
|
|
85
131
|
return editMode ?
|
|
86
|
-
<
|
|
87
|
-
|
|
132
|
+
(<div className='theia-notebook-markdown-editor-container' key="code">
|
|
133
|
+
<CellEditor notebookModel={notebookModel} cell={cell}
|
|
134
|
+
monacoServices={monacoServices}
|
|
135
|
+
notebookContextManager={notebookContextManager}
|
|
136
|
+
fontInfo={notebookOptionsService.editorFontInfo} />
|
|
137
|
+
<NotebookCodeCellStatus cell={cell} notebook={notebookModel}
|
|
138
|
+
commandRegistry={commandRegistry}
|
|
139
|
+
onClick={() => cell.requestFocusEditor()} />
|
|
140
|
+
</div >) :
|
|
141
|
+
(<div className='theia-notebook-markdown-content' key="markdown"
|
|
88
142
|
onDoubleClick={() => cell.requestEdit()}
|
|
89
|
-
ref={node => node?.replaceChildren(markdownContent)}
|
|
90
|
-
|
|
143
|
+
ref={node => node?.replaceChildren(...markdownContent)}
|
|
144
|
+
/>);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function searchInMarkdown(instance: mark, options: NotebookEditorFindMatchOptions): NotebookEditorFindMatch[] {
|
|
148
|
+
const matches: NotebookEditorFindMatch[] = [];
|
|
149
|
+
const markOptions: mark.MarkOptions & mark.RegExpOptions = {
|
|
150
|
+
className: 'theia-find-match',
|
|
151
|
+
diacritics: false,
|
|
152
|
+
caseSensitive: options.matchCase,
|
|
153
|
+
acrossElements: true,
|
|
154
|
+
separateWordSearch: false,
|
|
155
|
+
each: node => {
|
|
156
|
+
matches.push(new MarkdownEditorFindMatch(node));
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
if (options.regex || options.wholeWord) {
|
|
160
|
+
let search = options.search;
|
|
161
|
+
if (options.wholeWord) {
|
|
162
|
+
if (!options.regex) {
|
|
163
|
+
search = escapeRegExp(search);
|
|
164
|
+
}
|
|
165
|
+
search = '\\b' + search + '\\b';
|
|
166
|
+
}
|
|
167
|
+
instance.markRegExp(new RegExp(search, options.matchCase ? '' : 'i'), markOptions);
|
|
168
|
+
} else {
|
|
169
|
+
instance.mark(options.search, markOptions);
|
|
170
|
+
}
|
|
171
|
+
return matches;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function escapeRegExp(value: string): string {
|
|
175
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
class MarkdownEditorFindMatch implements NotebookEditorFindMatch {
|
|
179
|
+
|
|
180
|
+
constructor(readonly node: Node) { }
|
|
181
|
+
|
|
182
|
+
private _selected = false;
|
|
183
|
+
|
|
184
|
+
get selected(): boolean {
|
|
185
|
+
return this._selected;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
set selected(selected: boolean) {
|
|
189
|
+
this._selected = selected;
|
|
190
|
+
const className = 'theia-find-match-selected';
|
|
191
|
+
if (this.node instanceof HTMLElement) {
|
|
192
|
+
if (selected) {
|
|
193
|
+
this.node.classList.add(className);
|
|
194
|
+
} else {
|
|
195
|
+
this.node.classList.remove(className);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
show(): void {
|
|
201
|
+
if (this.node instanceof HTMLElement) {
|
|
202
|
+
this.node.scrollIntoView({
|
|
203
|
+
behavior: 'instant',
|
|
204
|
+
block: 'center'
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
}
|
|
91
208
|
}
|
|
@@ -32,6 +32,8 @@ import { NotebookCellOutputModel } from './notebook-cell-output-model';
|
|
|
32
32
|
import { PreferenceService } from '@theia/core/lib/browser';
|
|
33
33
|
import { NotebookPreferences } from '../contributions/notebook-preferences';
|
|
34
34
|
import { LanguageService } from '@theia/core/lib/browser/language-service';
|
|
35
|
+
import { NotebookEditorFindMatch, NotebookEditorFindMatchOptions } from '../view/notebook-find-widget';
|
|
36
|
+
import { Range } from '@theia/core/shared/vscode-languageserver-protocol';
|
|
35
37
|
|
|
36
38
|
export const NotebookCellModelFactory = Symbol('NotebookModelFactory');
|
|
37
39
|
export type NotebookCellModelFactory = (props: NotebookCellModelProps) => NotebookCellModel;
|
|
@@ -86,22 +88,22 @@ export interface NotebookCellModelProps {
|
|
|
86
88
|
export class NotebookCellModel implements NotebookCell, Disposable {
|
|
87
89
|
|
|
88
90
|
protected readonly onDidChangeOutputsEmitter = new Emitter<NotebookCellOutputsSplice>();
|
|
89
|
-
readonly onDidChangeOutputs
|
|
91
|
+
readonly onDidChangeOutputs = this.onDidChangeOutputsEmitter.event;
|
|
90
92
|
|
|
91
93
|
protected readonly onDidChangeOutputItemsEmitter = new Emitter<CellOutput>();
|
|
92
|
-
readonly onDidChangeOutputItems
|
|
94
|
+
readonly onDidChangeOutputItems = this.onDidChangeOutputItemsEmitter.event;
|
|
93
95
|
|
|
94
96
|
protected readonly onDidChangeContentEmitter = new Emitter<'content' | 'language' | 'mime'>();
|
|
95
|
-
readonly onDidChangeContent
|
|
97
|
+
readonly onDidChangeContent = this.onDidChangeContentEmitter.event;
|
|
96
98
|
|
|
97
99
|
protected readonly onDidChangeMetadataEmitter = new Emitter<void>();
|
|
98
|
-
readonly onDidChangeMetadata
|
|
100
|
+
readonly onDidChangeMetadata = this.onDidChangeMetadataEmitter.event;
|
|
99
101
|
|
|
100
102
|
protected readonly onDidChangeInternalMetadataEmitter = new Emitter<CellInternalMetadataChangedEvent>();
|
|
101
|
-
readonly onDidChangeInternalMetadata
|
|
103
|
+
readonly onDidChangeInternalMetadata = this.onDidChangeInternalMetadataEmitter.event;
|
|
102
104
|
|
|
103
105
|
protected readonly onDidChangeLanguageEmitter = new Emitter<string>();
|
|
104
|
-
readonly onDidChangeLanguage
|
|
106
|
+
readonly onDidChangeLanguage = this.onDidChangeLanguageEmitter.event;
|
|
105
107
|
|
|
106
108
|
protected readonly onDidRequestCellEditChangeEmitter = new Emitter<boolean>();
|
|
107
109
|
readonly onDidRequestCellEditChange = this.onDidRequestCellEditChangeEmitter.event;
|
|
@@ -113,10 +115,16 @@ export class NotebookCellModel implements NotebookCell, Disposable {
|
|
|
113
115
|
readonly onWillBlurCellEditor = this.onWillBlurCellEditorEmitter.event;
|
|
114
116
|
|
|
115
117
|
protected readonly onDidChangeEditorOptionsEmitter = new Emitter<MonacoEditor.IOptions>();
|
|
116
|
-
readonly onDidChangeEditorOptions
|
|
118
|
+
readonly onDidChangeEditorOptions = this.onDidChangeEditorOptionsEmitter.event;
|
|
117
119
|
|
|
118
120
|
protected readonly outputVisibilityChangeEmitter = new Emitter<boolean>();
|
|
119
|
-
readonly onDidChangeOutputVisibility
|
|
121
|
+
readonly onDidChangeOutputVisibility = this.outputVisibilityChangeEmitter.event;
|
|
122
|
+
|
|
123
|
+
protected readonly onDidFindMatchesEmitter = new Emitter<NotebookCodeEditorFindMatch[]>();
|
|
124
|
+
readonly onDidFindMatches: Event<NotebookCodeEditorFindMatch[]> = this.onDidFindMatchesEmitter.event;
|
|
125
|
+
|
|
126
|
+
protected readonly onDidSelectFindMatchEmitter = new Emitter<NotebookCodeEditorFindMatch>();
|
|
127
|
+
readonly onDidSelectFindMatch: Event<NotebookCodeEditorFindMatch> = this.onDidSelectFindMatchEmitter.event;
|
|
120
128
|
|
|
121
129
|
@inject(NotebookCellModelProps)
|
|
122
130
|
protected readonly props: NotebookCellModelProps;
|
|
@@ -175,10 +183,12 @@ export class NotebookCellModel implements NotebookCell, Disposable {
|
|
|
175
183
|
get source(): string {
|
|
176
184
|
return this.props.source;
|
|
177
185
|
}
|
|
186
|
+
|
|
178
187
|
set source(source: string) {
|
|
179
188
|
this.props.source = source;
|
|
180
189
|
this.textModel?.textEditorModel.setValue(source);
|
|
181
190
|
}
|
|
191
|
+
|
|
182
192
|
get language(): string {
|
|
183
193
|
return this.props.language;
|
|
184
194
|
}
|
|
@@ -368,6 +378,82 @@ export class NotebookCellModel implements NotebookCell, Disposable {
|
|
|
368
378
|
this.onDidChangeOutputItemsEmitter.fire(output);
|
|
369
379
|
}
|
|
370
380
|
}
|
|
381
|
+
|
|
382
|
+
onMarkdownFind: ((options: NotebookEditorFindMatchOptions) => NotebookEditorFindMatch[]) | undefined;
|
|
383
|
+
|
|
384
|
+
showMatch(selected: NotebookCodeEditorFindMatch): void {
|
|
385
|
+
this.onDidSelectFindMatchEmitter.fire(selected);
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
findMatches(options: NotebookEditorFindMatchOptions): NotebookEditorFindMatch[] {
|
|
389
|
+
if (this.cellKind === CellKind.Markup && !this.editing) {
|
|
390
|
+
return this.onMarkdownFind?.(options) ?? [];
|
|
391
|
+
}
|
|
392
|
+
if (!this.textModel) {
|
|
393
|
+
return [];
|
|
394
|
+
}
|
|
395
|
+
const matches = options.search ? this.textModel.findMatches({
|
|
396
|
+
searchString: options.search,
|
|
397
|
+
isRegex: options.regex,
|
|
398
|
+
matchCase: options.matchCase,
|
|
399
|
+
matchWholeWord: options.wholeWord
|
|
400
|
+
}) : [];
|
|
401
|
+
const editorFindMatches = matches.map(match => new NotebookCodeEditorFindMatch(this, match.range, this.textModel!));
|
|
402
|
+
this.onDidFindMatchesEmitter.fire(editorFindMatches);
|
|
403
|
+
return editorFindMatches;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
replaceAll(matches: NotebookCodeEditorFindMatch[], value: string): void {
|
|
407
|
+
const editOperations = matches.map(match => ({
|
|
408
|
+
range: {
|
|
409
|
+
startColumn: match.range.start.character,
|
|
410
|
+
startLineNumber: match.range.start.line,
|
|
411
|
+
endColumn: match.range.end.character,
|
|
412
|
+
endLineNumber: match.range.end.line
|
|
413
|
+
},
|
|
414
|
+
text: value
|
|
415
|
+
}));
|
|
416
|
+
this.textModel?.textEditorModel.pushEditOperations(
|
|
417
|
+
// eslint-disable-next-line no-null/no-null
|
|
418
|
+
null,
|
|
419
|
+
editOperations,
|
|
420
|
+
// eslint-disable-next-line no-null/no-null
|
|
421
|
+
() => null);
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
export interface NotebookCellFindMatches {
|
|
426
|
+
matches: NotebookEditorFindMatch[];
|
|
427
|
+
selected: NotebookEditorFindMatch;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
export class NotebookCodeEditorFindMatch implements NotebookEditorFindMatch {
|
|
431
|
+
|
|
432
|
+
selected = false;
|
|
433
|
+
|
|
434
|
+
constructor(readonly cell: NotebookCellModel, readonly range: Range, readonly textModel: MonacoEditorModel) {
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
show(): void {
|
|
438
|
+
this.cell.showMatch(this);
|
|
439
|
+
}
|
|
440
|
+
replace(value: string): void {
|
|
441
|
+
this.textModel.textEditorModel.pushEditOperations(
|
|
442
|
+
// eslint-disable-next-line no-null/no-null
|
|
443
|
+
null,
|
|
444
|
+
[{
|
|
445
|
+
range: {
|
|
446
|
+
startColumn: this.range.start.character,
|
|
447
|
+
startLineNumber: this.range.start.line,
|
|
448
|
+
endColumn: this.range.end.character,
|
|
449
|
+
endLineNumber: this.range.end.line
|
|
450
|
+
},
|
|
451
|
+
text: value
|
|
452
|
+
}],
|
|
453
|
+
// eslint-disable-next-line no-null/no-null
|
|
454
|
+
() => null);
|
|
455
|
+
}
|
|
456
|
+
|
|
371
457
|
}
|
|
372
458
|
|
|
373
459
|
function computeRunStartTimeAdjustment(oldMetadata: NotebookCellInternalMetadata, newMetadata: NotebookCellInternalMetadata): number | undefined {
|