@jupyterlab/codemirror 4.0.0-alpha.2 → 4.0.0-alpha.20
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/codemirror-ipythongfm.d.ts +9 -3
- package/lib/codemirror-ipythongfm.js +52 -30
- package/lib/codemirror-ipythongfm.js.map +1 -1
- package/lib/commands.d.ts +13 -0
- package/lib/commands.js +32 -0
- package/lib/commands.js.map +1 -0
- package/lib/editor.d.ts +48 -279
- package/lib/editor.js +220 -818
- package/lib/editor.js.map +1 -1
- package/lib/extension.d.ts +236 -0
- package/lib/extension.js +687 -0
- package/lib/extension.js.map +1 -0
- package/lib/extensions/customStyle.d.ts +25 -0
- package/lib/extensions/customStyle.js +51 -0
- package/lib/extensions/customStyle.js.map +1 -0
- package/lib/extensions/index.d.ts +3 -0
- package/lib/extensions/index.js +8 -0
- package/lib/extensions/index.js.map +1 -0
- package/lib/extensions/rulers.d.ts +8 -0
- package/lib/extensions/rulers.js +85 -0
- package/lib/extensions/rulers.js.map +1 -0
- package/lib/extensions/ybinding.d.ts +125 -0
- package/lib/extensions/ybinding.js +213 -0
- package/lib/extensions/ybinding.js.map +1 -0
- package/lib/factory.d.ts +15 -5
- package/lib/factory.js +53 -24
- package/lib/factory.js.map +1 -1
- package/lib/index.d.ts +7 -19
- package/lib/index.js +7 -23
- package/lib/index.js.map +1 -1
- package/lib/language.d.ts +96 -0
- package/lib/language.js +1690 -0
- package/lib/language.js.map +1 -0
- package/lib/mimetype.d.ts +3 -0
- package/lib/mimetype.js +16 -5
- package/lib/mimetype.js.map +1 -1
- package/lib/searchprovider.d.ts +197 -0
- package/lib/searchprovider.js +550 -0
- package/lib/searchprovider.js.map +1 -0
- package/lib/theme.d.ts +57 -0
- package/lib/theme.js +194 -0
- package/lib/theme.js.map +1 -0
- package/lib/token.d.ts +375 -0
- package/lib/token.js +18 -0
- package/lib/token.js.map +1 -0
- package/package.json +45 -41
- package/src/codemirror-ipythongfm.ts +109 -0
- package/src/commands.ts +34 -0
- package/src/editor.ts +783 -0
- package/src/extension.ts +878 -0
- package/src/extensions/customStyle.ts +79 -0
- package/src/extensions/index.ts +8 -0
- package/src/extensions/rulers.ts +112 -0
- package/src/extensions/ybinding.ts +267 -0
- package/src/factory.ts +100 -0
- package/src/index.ts +17 -0
- package/src/language.ts +1729 -0
- package/src/mimetype.ts +54 -0
- package/src/searchprovider.ts +700 -0
- package/src/theme.ts +219 -0
- package/src/token.ts +436 -0
- package/src/typings.d.ts +13 -0
- package/style/base.css +22 -162
- package/style/index.css +1 -7
- package/style/index.js +1 -7
- package/lib/codemirror-ipython.d.ts +0 -2
- package/lib/codemirror-ipython.js +0 -30
- package/lib/codemirror-ipython.js.map +0 -1
- package/lib/mode.d.ts +0 -81
- package/lib/mode.js +0 -149
- package/lib/mode.js.map +0 -1
- package/lib/syntaxstatus.d.ts +0 -67
- package/lib/syntaxstatus.js +0 -140
- package/lib/syntaxstatus.js.map +0 -1
- package/lib/tokens.d.ts +0 -18
- package/lib/tokens.js +0 -9
- package/lib/tokens.js.map +0 -1
- package/typings/codemirror/codemirror.d.ts +0 -227
|
@@ -0,0 +1,550 @@
|
|
|
1
|
+
// Copyright (c) Jupyter Development Team.
|
|
2
|
+
// Distributed under the terms of the Modified BSD License.
|
|
3
|
+
import { JSONExt } from '@lumino/coreutils';
|
|
4
|
+
import { StateEffect, StateField } from '@codemirror/state';
|
|
5
|
+
import { Decoration, EditorView } from '@codemirror/view';
|
|
6
|
+
import { GenericSearchProvider, TextSearchEngine } from '@jupyterlab/documentsearch';
|
|
7
|
+
import { Signal } from '@lumino/signaling';
|
|
8
|
+
/**
|
|
9
|
+
* Search provider for editors.
|
|
10
|
+
*/
|
|
11
|
+
export class EditorSearchProvider {
|
|
12
|
+
/**
|
|
13
|
+
* Constructor
|
|
14
|
+
*/
|
|
15
|
+
constructor() {
|
|
16
|
+
/**
|
|
17
|
+
* Current match index
|
|
18
|
+
*/
|
|
19
|
+
this.currentIndex = null;
|
|
20
|
+
/**
|
|
21
|
+
* Current search query
|
|
22
|
+
*/
|
|
23
|
+
this.query = null;
|
|
24
|
+
this._isActive = true;
|
|
25
|
+
this._isDisposed = false;
|
|
26
|
+
this._cmHandler = null;
|
|
27
|
+
this.currentIndex = null;
|
|
28
|
+
this._stateChanged = new Signal(this);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* CodeMirror search highlighter
|
|
32
|
+
*/
|
|
33
|
+
get cmHandler() {
|
|
34
|
+
if (!this._cmHandler) {
|
|
35
|
+
this._cmHandler = new CodeMirrorSearchHighlighter(this.editor);
|
|
36
|
+
}
|
|
37
|
+
return this._cmHandler;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Changed signal to be emitted when search matches change.
|
|
41
|
+
*/
|
|
42
|
+
get stateChanged() {
|
|
43
|
+
return this._stateChanged;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Current match index
|
|
47
|
+
*/
|
|
48
|
+
get currentMatchIndex() {
|
|
49
|
+
return this.isActive ? this.currentIndex : null;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Whether the cell search is active.
|
|
53
|
+
*
|
|
54
|
+
* This is used when applying search only on selected cells.
|
|
55
|
+
*/
|
|
56
|
+
get isActive() {
|
|
57
|
+
return this._isActive;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Whether the search provider is disposed or not.
|
|
61
|
+
*/
|
|
62
|
+
get isDisposed() {
|
|
63
|
+
return this._isDisposed;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Number of matches in the cell.
|
|
67
|
+
*/
|
|
68
|
+
get matchesCount() {
|
|
69
|
+
return this.isActive ? this.cmHandler.matches.length : 0;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Clear currently highlighted match
|
|
73
|
+
*/
|
|
74
|
+
clearHighlight() {
|
|
75
|
+
this.currentIndex = null;
|
|
76
|
+
this.cmHandler.clearHighlight();
|
|
77
|
+
return Promise.resolve();
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Dispose the search provider
|
|
81
|
+
*/
|
|
82
|
+
dispose() {
|
|
83
|
+
if (this._isDisposed) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
this._isDisposed = true;
|
|
87
|
+
Signal.clearData(this);
|
|
88
|
+
if (this.isActive) {
|
|
89
|
+
this.endQuery().catch(reason => {
|
|
90
|
+
console.error(`Failed to end search query on cells.`, reason);
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Set `isActive` status.
|
|
96
|
+
*
|
|
97
|
+
* #### Notes
|
|
98
|
+
* It will start or end the search
|
|
99
|
+
*
|
|
100
|
+
* @param v New value
|
|
101
|
+
*/
|
|
102
|
+
async setIsActive(v) {
|
|
103
|
+
if (this._isActive !== v) {
|
|
104
|
+
this._isActive = v;
|
|
105
|
+
}
|
|
106
|
+
if (this._isActive) {
|
|
107
|
+
if (this.query !== null) {
|
|
108
|
+
await this.startQuery(this.query, this.filters);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
await this.endQuery();
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Initialize the search using the provided options. Should update the UI
|
|
117
|
+
* to highlight all matches and "select" the first match.
|
|
118
|
+
*
|
|
119
|
+
* @param query A RegExp to be use to perform the search
|
|
120
|
+
* @param filters Filter parameters to pass to provider
|
|
121
|
+
*/
|
|
122
|
+
async startQuery(query, filters) {
|
|
123
|
+
this.query = query;
|
|
124
|
+
this.filters = filters;
|
|
125
|
+
// Search input
|
|
126
|
+
const content = this.model.sharedModel.getSource();
|
|
127
|
+
await this.updateCodeMirror(content);
|
|
128
|
+
this.model.sharedModel.changed.connect(this.onSharedModelChanged, this);
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Stop the search and clean any UI elements.
|
|
132
|
+
*/
|
|
133
|
+
async endQuery() {
|
|
134
|
+
await this.cmHandler.endQuery();
|
|
135
|
+
this.currentIndex = null;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Highlight the next match.
|
|
139
|
+
*
|
|
140
|
+
* @returns The next match if there is one.
|
|
141
|
+
*/
|
|
142
|
+
async highlightNext(loop = true) {
|
|
143
|
+
if (this.matchesCount === 0 || !this.isActive) {
|
|
144
|
+
this.currentIndex = null;
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
// This starts from the cursor position
|
|
148
|
+
let match = await this.cmHandler.highlightNext();
|
|
149
|
+
if (match) {
|
|
150
|
+
this.currentIndex = this.cmHandler.currentIndex;
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
this.currentIndex = loop ? 0 : null;
|
|
154
|
+
}
|
|
155
|
+
return match;
|
|
156
|
+
}
|
|
157
|
+
return Promise.resolve(this.getCurrentMatch());
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Highlight the previous match.
|
|
161
|
+
*
|
|
162
|
+
* @returns The previous match if there is one.
|
|
163
|
+
*/
|
|
164
|
+
async highlightPrevious(loop = true) {
|
|
165
|
+
if (this.matchesCount === 0 || !this.isActive) {
|
|
166
|
+
this.currentIndex = null;
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
// This starts from the cursor position
|
|
170
|
+
let match = await this.cmHandler.highlightPrevious();
|
|
171
|
+
if (match) {
|
|
172
|
+
this.currentIndex = this.cmHandler.currentIndex;
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
this.currentIndex = loop ? this.matchesCount - 1 : null;
|
|
176
|
+
}
|
|
177
|
+
return match;
|
|
178
|
+
}
|
|
179
|
+
return Promise.resolve(this.getCurrentMatch());
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Replace the currently selected match with the provided text.
|
|
183
|
+
*
|
|
184
|
+
* If no match is selected, it won't do anything.
|
|
185
|
+
*
|
|
186
|
+
* @param newText The replacement text.
|
|
187
|
+
* @returns Whether a replace occurred.
|
|
188
|
+
*/
|
|
189
|
+
replaceCurrentMatch(newText, loop, options) {
|
|
190
|
+
if (!this.isActive) {
|
|
191
|
+
return Promise.resolve(false);
|
|
192
|
+
}
|
|
193
|
+
let occurred = false;
|
|
194
|
+
if (this.currentIndex !== null &&
|
|
195
|
+
this.currentIndex < this.cmHandler.matches.length) {
|
|
196
|
+
const editor = this.editor;
|
|
197
|
+
const selection = editor.state.sliceDoc(editor.state.selection.main.from, editor.state.selection.main.to);
|
|
198
|
+
const match = this.getCurrentMatch();
|
|
199
|
+
// If cursor is not on a selection, highlight the next match
|
|
200
|
+
if (selection !== (match === null || match === void 0 ? void 0 : match.text)) {
|
|
201
|
+
this.currentIndex = null;
|
|
202
|
+
// The next will be highlighted as a consequence of this returning false
|
|
203
|
+
}
|
|
204
|
+
else {
|
|
205
|
+
this.cmHandler.matches.splice(this.currentIndex, 1);
|
|
206
|
+
this.currentIndex = null;
|
|
207
|
+
const substitutedText = (options === null || options === void 0 ? void 0 : options.regularExpression)
|
|
208
|
+
? match.text.replace(this.query, newText)
|
|
209
|
+
: newText;
|
|
210
|
+
const insertText = (options === null || options === void 0 ? void 0 : options.preserveCase)
|
|
211
|
+
? GenericSearchProvider.preserveCase(match.text, substitutedText)
|
|
212
|
+
: substitutedText;
|
|
213
|
+
this.model.sharedModel.updateSource(match.position, match.position + match.text.length, insertText);
|
|
214
|
+
occurred = true;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return Promise.resolve(occurred);
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Replace all matches in the cell source with the provided text
|
|
221
|
+
*
|
|
222
|
+
* @param newText The replacement text.
|
|
223
|
+
* @returns Whether a replace occurred.
|
|
224
|
+
*/
|
|
225
|
+
replaceAllMatches(newText, options) {
|
|
226
|
+
if (!this.isActive) {
|
|
227
|
+
return Promise.resolve(false);
|
|
228
|
+
}
|
|
229
|
+
let occurred = this.cmHandler.matches.length > 0;
|
|
230
|
+
let src = this.model.sharedModel.getSource();
|
|
231
|
+
let lastEnd = 0;
|
|
232
|
+
const finalSrc = this.cmHandler.matches.reduce((agg, match) => {
|
|
233
|
+
const start = match.position;
|
|
234
|
+
const end = start + match.text.length;
|
|
235
|
+
const substitutedText = (options === null || options === void 0 ? void 0 : options.regularExpression)
|
|
236
|
+
? match.text.replace(this.query, newText)
|
|
237
|
+
: newText;
|
|
238
|
+
const insertText = (options === null || options === void 0 ? void 0 : options.preserveCase)
|
|
239
|
+
? GenericSearchProvider.preserveCase(match.text, substitutedText)
|
|
240
|
+
: substitutedText;
|
|
241
|
+
const newStep = `${agg}${src.slice(lastEnd, start)}${insertText}`;
|
|
242
|
+
lastEnd = end;
|
|
243
|
+
return newStep;
|
|
244
|
+
}, '');
|
|
245
|
+
if (occurred) {
|
|
246
|
+
this.cmHandler.matches = [];
|
|
247
|
+
this.currentIndex = null;
|
|
248
|
+
this.model.sharedModel.setSource(`${finalSrc}${src.slice(lastEnd)}`);
|
|
249
|
+
}
|
|
250
|
+
return Promise.resolve(occurred);
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Get the current match if it exists.
|
|
254
|
+
*
|
|
255
|
+
* @returns The current match
|
|
256
|
+
*/
|
|
257
|
+
getCurrentMatch() {
|
|
258
|
+
if (this.currentIndex === null) {
|
|
259
|
+
return undefined;
|
|
260
|
+
}
|
|
261
|
+
else {
|
|
262
|
+
let match = undefined;
|
|
263
|
+
if (this.currentIndex < this.cmHandler.matches.length) {
|
|
264
|
+
match = this.cmHandler.matches[this.currentIndex];
|
|
265
|
+
}
|
|
266
|
+
return match;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Callback on source change
|
|
271
|
+
*
|
|
272
|
+
* @param emitter Source of the change
|
|
273
|
+
* @param changes Source change
|
|
274
|
+
*/
|
|
275
|
+
async onSharedModelChanged(emitter, changes) {
|
|
276
|
+
if (changes.sourceChange) {
|
|
277
|
+
await this.updateCodeMirror(emitter.getSource());
|
|
278
|
+
this._stateChanged.emit();
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Update matches
|
|
283
|
+
*/
|
|
284
|
+
async updateCodeMirror(content) {
|
|
285
|
+
if (this.query !== null && this.isActive) {
|
|
286
|
+
this.cmHandler.matches = await TextSearchEngine.search(this.query, content);
|
|
287
|
+
}
|
|
288
|
+
else {
|
|
289
|
+
this.cmHandler.matches = [];
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Helper class to highlight texts in a code mirror editor.
|
|
295
|
+
*
|
|
296
|
+
* Highlighted texts (aka `matches`) must be provided through
|
|
297
|
+
* the `matches` attributes.
|
|
298
|
+
*/
|
|
299
|
+
export class CodeMirrorSearchHighlighter {
|
|
300
|
+
/**
|
|
301
|
+
* Constructor
|
|
302
|
+
*
|
|
303
|
+
* @param editor The CodeMirror editor
|
|
304
|
+
*/
|
|
305
|
+
constructor(editor) {
|
|
306
|
+
this._cm = editor;
|
|
307
|
+
this._matches = new Array();
|
|
308
|
+
this._currentIndex = null;
|
|
309
|
+
this._highlightEffect = StateEffect.define({
|
|
310
|
+
map: (value, mapping) => ({
|
|
311
|
+
matches: value.matches.map(v => ({
|
|
312
|
+
text: v.text,
|
|
313
|
+
position: mapping.mapPos(v.position)
|
|
314
|
+
}))
|
|
315
|
+
})
|
|
316
|
+
});
|
|
317
|
+
this._highlightMark = Decoration.mark({ class: 'cm-searching' });
|
|
318
|
+
this._highlightField = StateField.define({
|
|
319
|
+
create: () => {
|
|
320
|
+
return Decoration.none;
|
|
321
|
+
},
|
|
322
|
+
update: (highlights, transaction) => {
|
|
323
|
+
highlights = highlights.map(transaction.changes);
|
|
324
|
+
for (let ef of transaction.effects) {
|
|
325
|
+
if (ef.is(this._highlightEffect)) {
|
|
326
|
+
const e = ef;
|
|
327
|
+
if (e.value.matches.length) {
|
|
328
|
+
highlights = highlights.update({
|
|
329
|
+
add: e.value.matches.map(m => this._highlightMark.range(m.position, m.position + m.text.length)),
|
|
330
|
+
// filter out old marks
|
|
331
|
+
filter: () => false
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
else {
|
|
335
|
+
highlights = Decoration.none;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
return highlights;
|
|
340
|
+
},
|
|
341
|
+
provide: f => EditorView.decorations.from(f)
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* The current index of the selected match.
|
|
346
|
+
*/
|
|
347
|
+
get currentIndex() {
|
|
348
|
+
return this._currentIndex;
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* The list of matches
|
|
352
|
+
*/
|
|
353
|
+
get matches() {
|
|
354
|
+
return this._matches;
|
|
355
|
+
}
|
|
356
|
+
set matches(v) {
|
|
357
|
+
if (!JSONExt.deepEqual(this._matches, v)) {
|
|
358
|
+
this._matches = v;
|
|
359
|
+
}
|
|
360
|
+
this._refresh();
|
|
361
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* Clear all highlighted matches
|
|
364
|
+
*/
|
|
365
|
+
clearHighlight() {
|
|
366
|
+
this._currentIndex = null;
|
|
367
|
+
this._highlightCurrentMatch();
|
|
368
|
+
}
|
|
369
|
+
/**
|
|
370
|
+
* Clear the highlighted matches.
|
|
371
|
+
*/
|
|
372
|
+
endQuery() {
|
|
373
|
+
this._currentIndex = null;
|
|
374
|
+
this._matches = [];
|
|
375
|
+
if (this._cm) {
|
|
376
|
+
this._cm.editor.dispatch({
|
|
377
|
+
effects: this._highlightEffect.of({ matches: [] })
|
|
378
|
+
});
|
|
379
|
+
const selection = this._cm.state.selection.main;
|
|
380
|
+
const from = selection.from;
|
|
381
|
+
const to = selection.to;
|
|
382
|
+
// Setting a reverse selection to allow search-as-you-type to maintain the
|
|
383
|
+
// current selected match. See comment in _findNext for more details.
|
|
384
|
+
if (from !== to) {
|
|
385
|
+
this._cm.editor.dispatch({ selection: { anchor: to, head: from } });
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
return Promise.resolve();
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* Highlight the next match
|
|
392
|
+
*
|
|
393
|
+
* @returns The next match if available
|
|
394
|
+
*/
|
|
395
|
+
highlightNext() {
|
|
396
|
+
this._currentIndex = this._findNext(false);
|
|
397
|
+
this._highlightCurrentMatch();
|
|
398
|
+
return Promise.resolve(this._currentIndex !== null
|
|
399
|
+
? this._matches[this._currentIndex]
|
|
400
|
+
: undefined);
|
|
401
|
+
}
|
|
402
|
+
/**
|
|
403
|
+
* Highlight the previous match
|
|
404
|
+
*
|
|
405
|
+
* @returns The previous match if available
|
|
406
|
+
*/
|
|
407
|
+
highlightPrevious() {
|
|
408
|
+
this._currentIndex = this._findNext(true);
|
|
409
|
+
this._highlightCurrentMatch();
|
|
410
|
+
return Promise.resolve(this._currentIndex !== null
|
|
411
|
+
? this._matches[this._currentIndex]
|
|
412
|
+
: undefined);
|
|
413
|
+
}
|
|
414
|
+
/**
|
|
415
|
+
* Set the editor
|
|
416
|
+
*
|
|
417
|
+
* @param editor Editor
|
|
418
|
+
*/
|
|
419
|
+
setEditor(editor) {
|
|
420
|
+
if (this._cm) {
|
|
421
|
+
throw new Error('CodeMirrorEditor already set.');
|
|
422
|
+
}
|
|
423
|
+
else {
|
|
424
|
+
this._cm = editor;
|
|
425
|
+
this._refresh();
|
|
426
|
+
if (this._currentIndex !== null) {
|
|
427
|
+
this._highlightCurrentMatch();
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
_highlightCurrentMatch() {
|
|
432
|
+
if (!this._cm) {
|
|
433
|
+
// no-op
|
|
434
|
+
return;
|
|
435
|
+
}
|
|
436
|
+
// Highlight the current index
|
|
437
|
+
if (this._currentIndex !== null) {
|
|
438
|
+
const match = this.matches[this._currentIndex];
|
|
439
|
+
this._cm.editor.focus();
|
|
440
|
+
this._cm.editor.dispatch({
|
|
441
|
+
selection: {
|
|
442
|
+
anchor: match.position,
|
|
443
|
+
head: match.position + match.text.length
|
|
444
|
+
},
|
|
445
|
+
scrollIntoView: true
|
|
446
|
+
});
|
|
447
|
+
}
|
|
448
|
+
else {
|
|
449
|
+
// Set cursor to remove any selection
|
|
450
|
+
this._cm.editor.dispatch({ selection: { anchor: 0 } });
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
_refresh() {
|
|
454
|
+
if (!this._cm) {
|
|
455
|
+
// no-op
|
|
456
|
+
return;
|
|
457
|
+
}
|
|
458
|
+
let effects = [
|
|
459
|
+
this._highlightEffect.of({ matches: this.matches })
|
|
460
|
+
];
|
|
461
|
+
if (!this._cm.state.field(this._highlightField, false)) {
|
|
462
|
+
effects.push(StateEffect.appendConfig.of([this._highlightField]));
|
|
463
|
+
}
|
|
464
|
+
this._cm.editor.dispatch({ effects });
|
|
465
|
+
}
|
|
466
|
+
_findNext(reverse) {
|
|
467
|
+
if (this._matches.length === 0) {
|
|
468
|
+
// No-op
|
|
469
|
+
return null;
|
|
470
|
+
}
|
|
471
|
+
// In order to support search-as-you-type, we needed a way to allow the first
|
|
472
|
+
// match to be selected when a search is started, but prevent the selected
|
|
473
|
+
// search to move for each new keypress. To do this, when a search is ended,
|
|
474
|
+
// the cursor is reversed, putting the head at the 'from' position. When a new
|
|
475
|
+
// search is started, the cursor we want is at the 'from' position, so that the same
|
|
476
|
+
// match is selected when the next key is entered (if it is still a match).
|
|
477
|
+
//
|
|
478
|
+
// When toggling through a search normally, the cursor is always set in the forward
|
|
479
|
+
// direction, so head is always at the 'to' position. That way, if reverse = false,
|
|
480
|
+
// the search proceeds from the 'to' position during normal toggling. If reverse = true,
|
|
481
|
+
// the search always proceeds from the 'anchor' position, which is at the 'from'.
|
|
482
|
+
const cursor = this._cm.state.selection.main;
|
|
483
|
+
let lastPosition = reverse ? cursor.anchor : cursor.head;
|
|
484
|
+
if (lastPosition === 0 && reverse && this.currentIndex === null) {
|
|
485
|
+
// The default position is (0, 0) but we want to start from the end in that case
|
|
486
|
+
lastPosition = this._cm.doc.length;
|
|
487
|
+
}
|
|
488
|
+
const position = lastPosition;
|
|
489
|
+
let found = Utils.findNext(this._matches, position, 0, this._matches.length - 1);
|
|
490
|
+
if (found === null) {
|
|
491
|
+
// Don't loop
|
|
492
|
+
return reverse ? this._matches.length - 1 : null;
|
|
493
|
+
}
|
|
494
|
+
if (reverse) {
|
|
495
|
+
found -= 1;
|
|
496
|
+
if (found < 0) {
|
|
497
|
+
// Don't loop
|
|
498
|
+
return null;
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
return found;
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
/**
|
|
505
|
+
* Helpers namespace
|
|
506
|
+
*/
|
|
507
|
+
var Utils;
|
|
508
|
+
(function (Utils) {
|
|
509
|
+
/**
|
|
510
|
+
* Find the closest match at `position` just after it.
|
|
511
|
+
*
|
|
512
|
+
* #### Notes
|
|
513
|
+
* Search is done using a binary search algorithm
|
|
514
|
+
*
|
|
515
|
+
* @param matches List of matches
|
|
516
|
+
* @param position Searched position
|
|
517
|
+
* @param lowerBound Lower range index
|
|
518
|
+
* @param higherBound High range index
|
|
519
|
+
* @returns The next match or null if none exists
|
|
520
|
+
*/
|
|
521
|
+
function findNext(matches, position, lowerBound = 0, higherBound = Infinity) {
|
|
522
|
+
higherBound = Math.min(matches.length - 1, higherBound);
|
|
523
|
+
while (lowerBound <= higherBound) {
|
|
524
|
+
let middle = Math.floor(0.5 * (lowerBound + higherBound));
|
|
525
|
+
const currentPosition = matches[middle].position;
|
|
526
|
+
if (currentPosition < position) {
|
|
527
|
+
lowerBound = middle + 1;
|
|
528
|
+
if (lowerBound < matches.length &&
|
|
529
|
+
matches[lowerBound].position > position) {
|
|
530
|
+
return lowerBound;
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
else if (currentPosition > position) {
|
|
534
|
+
higherBound = middle - 1;
|
|
535
|
+
if (higherBound > 0 && matches[higherBound].position < position) {
|
|
536
|
+
return middle;
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
else {
|
|
540
|
+
return middle;
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
// Next could be the first item
|
|
544
|
+
const first = lowerBound > 0 ? lowerBound - 1 : 0;
|
|
545
|
+
const match = matches[first];
|
|
546
|
+
return match.position >= position ? first : null;
|
|
547
|
+
}
|
|
548
|
+
Utils.findNext = findNext;
|
|
549
|
+
})(Utils || (Utils = {}));
|
|
550
|
+
//# sourceMappingURL=searchprovider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"searchprovider.js","sourceRoot":"","sources":["../src/searchprovider.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,2DAA2D;AAgC3D,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAE5C,OAAO,EAAE,WAAW,EAAmB,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC7E,OAAO,EAAE,UAAU,EAAiB,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEzE,OAAO,EACL,qBAAqB,EAIrB,gBAAgB,EACjB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAW,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAGpD;;GAEG;AACH,MAAM,OAAgB,oBAAoB;IAIxC;;OAEG;IACH;QA8TA;;WAEG;QACO,iBAAY,GAAkB,IAAI,CAAC;QAK7C;;WAEG;QACO,UAAK,GAAkB,IAAI,CAAC;QAG9B,cAAS,GAAG,IAAI,CAAC;QACjB,gBAAW,GAAG,KAAK,CAAC;QACpB,eAAU,GAAuC,IAAI,CAAC;QA7U5D,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC;QACzB,IAAI,CAAC,aAAa,GAAG,IAAI,MAAM,CAA4B,IAAI,CAAC,CAAC;IACnE,CAA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OAAO,MAAM,CAAC;aACf;SACF;QAED,+BAA+B;QAC/B,MAAM,KAAK,GAAG,UAAU,GAAG,CAAC,CAAC,CAAC,CAAC,UAAU,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAClD,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;QAC7B,OAAO,KAAK,CAAC,QAAQ,IAAI,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;IACnD,CAAC;IAlCe,cAAQ,WAkCvB,CAAA;AACH,CAAC,EAhDS,KAAK,KAAL,KAAK,QAgDd"}
|
package/lib/theme.d.ts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { HighlightStyle } from '@codemirror/language';
|
|
2
|
+
import { Extension } from '@codemirror/state';
|
|
3
|
+
import { ITranslator } from '@jupyterlab/translation';
|
|
4
|
+
import { IEditorTheme, IEditorThemeRegistry } from './token';
|
|
5
|
+
export declare const jupyterEditorTheme: Extension;
|
|
6
|
+
export declare const jupyterHighlightStyle: HighlightStyle;
|
|
7
|
+
/**
|
|
8
|
+
* JupyterLab CodeMirror 6 theme
|
|
9
|
+
*/
|
|
10
|
+
export declare const jupyterTheme: Extension;
|
|
11
|
+
/**
|
|
12
|
+
* CodeMirror 6 theme registry
|
|
13
|
+
*/
|
|
14
|
+
export declare class EditorThemeRegistry implements IEditorThemeRegistry {
|
|
15
|
+
/**
|
|
16
|
+
* CodeMirror 6 themes
|
|
17
|
+
*/
|
|
18
|
+
private _themeMap;
|
|
19
|
+
/**
|
|
20
|
+
* Get all themes
|
|
21
|
+
*/
|
|
22
|
+
get themes(): IEditorTheme[];
|
|
23
|
+
/**
|
|
24
|
+
* Get the default CodeMirror 6 theme for JupyterLab
|
|
25
|
+
*
|
|
26
|
+
* @returns Default theme
|
|
27
|
+
*/
|
|
28
|
+
defaultTheme(): Extension;
|
|
29
|
+
/**
|
|
30
|
+
* Register a new theme.
|
|
31
|
+
*
|
|
32
|
+
* @param theme Codemirror 6 theme
|
|
33
|
+
*/
|
|
34
|
+
addTheme(theme: IEditorTheme): void;
|
|
35
|
+
/**
|
|
36
|
+
* Get a theme.
|
|
37
|
+
*
|
|
38
|
+
* #### Notes
|
|
39
|
+
* It falls back to the default theme
|
|
40
|
+
*
|
|
41
|
+
* @param name Theme name
|
|
42
|
+
* @returns Theme extension
|
|
43
|
+
*/
|
|
44
|
+
getTheme(name: string): Extension;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* EditorThemeRegistry namespace
|
|
48
|
+
*/
|
|
49
|
+
export declare namespace EditorThemeRegistry {
|
|
50
|
+
/**
|
|
51
|
+
* Get the default editor themes.
|
|
52
|
+
*
|
|
53
|
+
* @param translator Application translator
|
|
54
|
+
* @returns Default CodeMirror 6 themes
|
|
55
|
+
*/
|
|
56
|
+
function getDefaultThemes(translator?: ITranslator | null): ReadonlyArray<Readonly<IEditorTheme>>;
|
|
57
|
+
}
|