@jupyterlab/fileeditor-extension 4.0.0-alpha.8 → 4.0.0-beta.0
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/commands.d.ts +14 -5
- package/lib/commands.js +255 -115
- package/lib/commands.js.map +1 -1
- package/lib/index.js +178 -40
- package/lib/index.js.map +1 -1
- package/lib/syntaxstatus.d.ts +5 -0
- package/lib/syntaxstatus.js +44 -0
- package/lib/syntaxstatus.js.map +1 -0
- package/package.json +33 -26
- package/schema/plugin.json +48 -119
- package/src/commands.ts +1382 -0
- package/src/index.ts +673 -0
- package/src/syntaxstatus.ts +64 -0
- package/style/index.css +4 -1
- package/style/index.js +4 -1
package/lib/commands.js
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
// Copyright (c) Jupyter Development Team.
|
|
2
2
|
// Distributed under the terms of the Modified BSD License.
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { selectAll } from '@codemirror/commands';
|
|
4
|
+
import { findNext, gotoLine } from '@codemirror/search';
|
|
5
|
+
import { Clipboard, MainAreaWidget } from '@jupyterlab/apputils';
|
|
6
|
+
import { CodeViewerWidget } from '@jupyterlab/codeeditor';
|
|
5
7
|
import { MarkdownCodeBlocks, PathExt } from '@jupyterlab/coreutils';
|
|
8
|
+
import { nullTranslator } from '@jupyterlab/translation';
|
|
6
9
|
import { consoleIcon, copyIcon, cutIcon, LabIcon, markdownIcon, pasteIcon, redoIcon, textEditorIcon, undoIcon } from '@jupyterlab/ui-components';
|
|
10
|
+
import { find } from '@lumino/algorithm';
|
|
7
11
|
const autoClosingBracketsNotebook = 'notebook:toggle-autoclosing-brackets';
|
|
8
12
|
const autoClosingBracketsConsole = 'console:toggle-autoclosing-brackets';
|
|
9
13
|
/**
|
|
@@ -37,57 +41,38 @@ export var CommandIDs;
|
|
|
37
41
|
CommandIDs.selectAll = 'fileeditor:select-all';
|
|
38
42
|
CommandIDs.invokeCompleter = 'completer:invoke-file';
|
|
39
43
|
CommandIDs.selectCompleter = 'completer:select-file';
|
|
44
|
+
CommandIDs.openCodeViewer = 'code-viewer:open';
|
|
45
|
+
CommandIDs.changeTheme = 'fileeditor:change-theme';
|
|
46
|
+
CommandIDs.changeLanguage = 'fileeditor:change-language';
|
|
47
|
+
CommandIDs.find = 'fileeditor:find';
|
|
48
|
+
CommandIDs.goToLine = 'fileeditor:go-to-line';
|
|
40
49
|
})(CommandIDs || (CommandIDs = {}));
|
|
41
50
|
/**
|
|
42
51
|
* The name of the factory that creates editor widgets.
|
|
43
52
|
*/
|
|
44
53
|
export const FACTORY = 'Editor';
|
|
45
|
-
const userSettings = [
|
|
46
|
-
'autoClosingBrackets',
|
|
47
|
-
'codeFolding',
|
|
48
|
-
'cursorBlinkRate',
|
|
49
|
-
'fontFamily',
|
|
50
|
-
'fontSize',
|
|
51
|
-
'insertSpaces',
|
|
52
|
-
'lineHeight',
|
|
53
|
-
'lineNumbers',
|
|
54
|
-
'lineWrap',
|
|
55
|
-
'matchBrackets',
|
|
56
|
-
'readOnly',
|
|
57
|
-
'rulers',
|
|
58
|
-
'showTrailingSpace',
|
|
59
|
-
'tabSize',
|
|
60
|
-
'wordWrapColumn'
|
|
61
|
-
];
|
|
62
|
-
function filterUserSettings(config) {
|
|
63
|
-
const filteredConfig = Object.assign({}, config);
|
|
64
|
-
// Delete parts of the config that are not user settings (like handlePaste).
|
|
65
|
-
for (let k of Object.keys(config)) {
|
|
66
|
-
if (!userSettings.includes(k)) {
|
|
67
|
-
delete config[k];
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
return filteredConfig;
|
|
71
|
-
}
|
|
72
|
-
let config = filterUserSettings(CodeEditor.defaultConfig);
|
|
73
54
|
/**
|
|
74
55
|
* A utility class for adding commands and menu items,
|
|
75
56
|
* for use by the File Editor extension or other Editor extensions.
|
|
76
57
|
*/
|
|
77
58
|
export var Commands;
|
|
78
59
|
(function (Commands) {
|
|
60
|
+
let config = {};
|
|
61
|
+
let scrollPastEnd = true;
|
|
79
62
|
/**
|
|
80
63
|
* Accessor function that returns the createConsole function for use by Create Console commands
|
|
81
64
|
*/
|
|
82
|
-
function getCreateConsoleFunction(commands) {
|
|
65
|
+
function getCreateConsoleFunction(commands, languages) {
|
|
83
66
|
return async function createConsole(widget, args) {
|
|
84
|
-
var _a;
|
|
67
|
+
var _a, _b, _c;
|
|
85
68
|
const options = args || {};
|
|
86
69
|
const console = await commands.execute('console:create', {
|
|
87
70
|
activate: options['activate'],
|
|
88
71
|
name: (_a = widget.context.contentsModel) === null || _a === void 0 ? void 0 : _a.name,
|
|
89
72
|
path: widget.context.path,
|
|
90
|
-
|
|
73
|
+
// Default value is an empty string -> using OR operator
|
|
74
|
+
preferredLanguage: widget.context.model.defaultKernelLanguage ||
|
|
75
|
+
((_c = (_b = languages.findByFileName(widget.context.path)) === null || _b === void 0 ? void 0 : _b.name) !== null && _c !== void 0 ? _c : ''),
|
|
91
76
|
ref: widget.id,
|
|
92
77
|
insertMode: 'split-bottom'
|
|
93
78
|
});
|
|
@@ -102,9 +87,20 @@ export var Commands;
|
|
|
102
87
|
* Update the setting values.
|
|
103
88
|
*/
|
|
104
89
|
function updateSettings(settings, commands) {
|
|
105
|
-
|
|
90
|
+
var _a;
|
|
91
|
+
config =
|
|
92
|
+
(_a = settings.get('editorConfig').composite) !== null && _a !== void 0 ? _a : {};
|
|
93
|
+
scrollPastEnd = settings.get('scrollPasteEnd').composite;
|
|
106
94
|
// Trigger a refresh of the rendered commands
|
|
107
|
-
commands.notifyCommandChanged();
|
|
95
|
+
commands.notifyCommandChanged(CommandIDs.lineNumbers);
|
|
96
|
+
commands.notifyCommandChanged(CommandIDs.currentLineNumbers);
|
|
97
|
+
commands.notifyCommandChanged(CommandIDs.lineWrap);
|
|
98
|
+
commands.notifyCommandChanged(CommandIDs.currentLineWrap);
|
|
99
|
+
commands.notifyCommandChanged(CommandIDs.changeTabs);
|
|
100
|
+
commands.notifyCommandChanged(CommandIDs.matchBrackets);
|
|
101
|
+
commands.notifyCommandChanged(CommandIDs.currentMatchBrackets);
|
|
102
|
+
commands.notifyCommandChanged(CommandIDs.autoClosingBrackets);
|
|
103
|
+
commands.notifyCommandChanged(CommandIDs.changeLanguage);
|
|
108
104
|
}
|
|
109
105
|
Commands.updateSettings = updateSettings;
|
|
110
106
|
/**
|
|
@@ -122,18 +118,19 @@ export var Commands;
|
|
|
122
118
|
*/
|
|
123
119
|
function updateWidget(widget) {
|
|
124
120
|
const editor = widget.editor;
|
|
125
|
-
editor.setOptions(
|
|
121
|
+
editor.setOptions({ ...config, scrollPastEnd });
|
|
126
122
|
}
|
|
127
123
|
Commands.updateWidget = updateWidget;
|
|
128
124
|
/**
|
|
129
125
|
* Wrapper function for adding the default File Editor commands
|
|
130
126
|
*/
|
|
131
|
-
function addCommands(commands, settingRegistry, trans, id, isEnabled, tracker,
|
|
127
|
+
function addCommands(commands, settingRegistry, trans, id, isEnabled, tracker, defaultBrowser, extensions, languages, consoleTracker, sessionDialogs) {
|
|
132
128
|
/**
|
|
133
129
|
* Add a command to change font size for File Editor
|
|
134
130
|
*/
|
|
135
131
|
commands.addCommand(CommandIDs.changeFontSize, {
|
|
136
132
|
execute: args => {
|
|
133
|
+
var _a;
|
|
137
134
|
const delta = Number(args['delta']);
|
|
138
135
|
if (Number.isNaN(delta)) {
|
|
139
136
|
console.error(`${CommandIDs.changeFontSize}: delta arg must be a number`);
|
|
@@ -141,7 +138,8 @@ export var Commands;
|
|
|
141
138
|
}
|
|
142
139
|
const style = window.getComputedStyle(document.documentElement);
|
|
143
140
|
const cssSize = parseInt(style.getPropertyValue('--jp-code-font-size'), 10);
|
|
144
|
-
const currentSize = config.fontSize ||
|
|
141
|
+
const currentSize = ((_a = config['customStyles']['fontSize']) !== null && _a !== void 0 ? _a : extensions.baseConfiguration['customStyles']['fontSize']) ||
|
|
142
|
+
cssSize;
|
|
145
143
|
config.fontSize = currentSize + delta;
|
|
146
144
|
return settingRegistry
|
|
147
145
|
.set(id, 'editorConfig', config)
|
|
@@ -150,8 +148,11 @@ export var Commands;
|
|
|
150
148
|
});
|
|
151
149
|
},
|
|
152
150
|
label: args => {
|
|
153
|
-
|
|
154
|
-
if ((
|
|
151
|
+
const delta = Number(args['delta']);
|
|
152
|
+
if (Number.isNaN(delta)) {
|
|
153
|
+
console.error(`${CommandIDs.changeFontSize}: delta arg must be a number`);
|
|
154
|
+
}
|
|
155
|
+
if (delta > 0) {
|
|
155
156
|
return args.isMenu
|
|
156
157
|
? trans.__('Increase Text Editor Font Size')
|
|
157
158
|
: trans.__('Increase Font Size');
|
|
@@ -167,20 +168,23 @@ export var Commands;
|
|
|
167
168
|
* Add the Line Numbers command
|
|
168
169
|
*/
|
|
169
170
|
commands.addCommand(CommandIDs.lineNumbers, {
|
|
170
|
-
execute: () => {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
.
|
|
171
|
+
execute: async () => {
|
|
172
|
+
var _a;
|
|
173
|
+
config.lineNumbers = !((_a = config.lineNumbers) !== null && _a !== void 0 ? _a : extensions.baseConfiguration.lineNumbers);
|
|
174
|
+
try {
|
|
175
|
+
return await settingRegistry.set(id, 'editorConfig', config);
|
|
176
|
+
}
|
|
177
|
+
catch (reason) {
|
|
175
178
|
console.error(`Failed to set ${id}: ${reason.message}`);
|
|
176
|
-
}
|
|
179
|
+
}
|
|
177
180
|
},
|
|
178
181
|
isEnabled,
|
|
179
|
-
isToggled: () => config.lineNumbers,
|
|
180
|
-
label: trans.__('Line Numbers')
|
|
182
|
+
isToggled: () => { var _a; return (_a = config.lineNumbers) !== null && _a !== void 0 ? _a : extensions.baseConfiguration.lineNumbers; },
|
|
183
|
+
label: trans.__('Show Line Numbers')
|
|
181
184
|
});
|
|
182
185
|
commands.addCommand(CommandIDs.currentLineNumbers, {
|
|
183
186
|
label: trans.__('Show Line Numbers'),
|
|
187
|
+
caption: trans.__('Show the line numbers for the current file.'),
|
|
184
188
|
execute: () => {
|
|
185
189
|
const widget = tracker.currentWidget;
|
|
186
190
|
if (!widget) {
|
|
@@ -193,44 +197,48 @@ export var Commands;
|
|
|
193
197
|
isToggled: () => {
|
|
194
198
|
var _a;
|
|
195
199
|
const widget = tracker.currentWidget;
|
|
196
|
-
return (_a = widget === null || widget === void 0 ? void 0 : widget.content.editor.getOption('lineNumbers')) !== null && _a !== void 0 ? _a : false;
|
|
200
|
+
return ((_a = widget === null || widget === void 0 ? void 0 : widget.content.editor.getOption('lineNumbers')) !== null && _a !== void 0 ? _a : false);
|
|
197
201
|
}
|
|
198
202
|
});
|
|
199
203
|
/**
|
|
200
204
|
* Add the Word Wrap command
|
|
201
205
|
*/
|
|
202
206
|
commands.addCommand(CommandIDs.lineWrap, {
|
|
203
|
-
execute: args => {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
.
|
|
207
|
+
execute: async (args) => {
|
|
208
|
+
var _a;
|
|
209
|
+
config.lineWrap = (_a = args['mode']) !== null && _a !== void 0 ? _a : false;
|
|
210
|
+
try {
|
|
211
|
+
return await settingRegistry.set(id, 'editorConfig', config);
|
|
212
|
+
}
|
|
213
|
+
catch (reason) {
|
|
208
214
|
console.error(`Failed to set ${id}: ${reason.message}`);
|
|
209
|
-
}
|
|
215
|
+
}
|
|
210
216
|
},
|
|
211
217
|
isEnabled,
|
|
212
218
|
isToggled: args => {
|
|
213
|
-
|
|
214
|
-
|
|
219
|
+
var _a, _b;
|
|
220
|
+
const lineWrap = (_a = args['mode']) !== null && _a !== void 0 ? _a : false;
|
|
221
|
+
return (lineWrap ===
|
|
222
|
+
((_b = config.lineWrap) !== null && _b !== void 0 ? _b : extensions.baseConfiguration.lineWrap));
|
|
215
223
|
},
|
|
216
224
|
label: trans.__('Word Wrap')
|
|
217
225
|
});
|
|
218
226
|
commands.addCommand(CommandIDs.currentLineWrap, {
|
|
219
227
|
label: trans.__('Wrap Words'),
|
|
228
|
+
caption: trans.__('Wrap words for the current file.'),
|
|
220
229
|
execute: () => {
|
|
221
230
|
const widget = tracker.currentWidget;
|
|
222
231
|
if (!widget) {
|
|
223
232
|
return;
|
|
224
233
|
}
|
|
225
234
|
const oldValue = widget.content.editor.getOption('lineWrap');
|
|
226
|
-
|
|
227
|
-
widget.content.editor.setOption('lineWrap', newValue);
|
|
235
|
+
widget.content.editor.setOption('lineWrap', !oldValue);
|
|
228
236
|
},
|
|
229
237
|
isEnabled,
|
|
230
238
|
isToggled: () => {
|
|
231
239
|
var _a;
|
|
232
240
|
const widget = tracker.currentWidget;
|
|
233
|
-
return (_a =
|
|
241
|
+
return ((_a = widget === null || widget === void 0 ? void 0 : widget.content.editor.getOption('lineWrap')) !== null && _a !== void 0 ? _a : false);
|
|
234
242
|
}
|
|
235
243
|
});
|
|
236
244
|
/**
|
|
@@ -239,46 +247,55 @@ export var Commands;
|
|
|
239
247
|
commands.addCommand(CommandIDs.changeTabs, {
|
|
240
248
|
label: args => {
|
|
241
249
|
var _a;
|
|
242
|
-
if (args.
|
|
243
|
-
return trans.
|
|
250
|
+
if (args.size) {
|
|
251
|
+
return trans.__('Spaces: %1', (_a = args.size) !== null && _a !== void 0 ? _a : '');
|
|
244
252
|
}
|
|
245
253
|
else {
|
|
246
254
|
return trans.__('Indent with Tab');
|
|
247
255
|
}
|
|
248
256
|
},
|
|
249
|
-
execute: args => {
|
|
250
|
-
|
|
251
|
-
config.
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
257
|
+
execute: async (args) => {
|
|
258
|
+
var _a;
|
|
259
|
+
config.indentUnit =
|
|
260
|
+
args['size'] !== undefined
|
|
261
|
+
? ((_a = args['size']) !== null && _a !== void 0 ? _a : '4').toString()
|
|
262
|
+
: 'Tab';
|
|
263
|
+
try {
|
|
264
|
+
return await settingRegistry.set(id, 'editorConfig', config);
|
|
265
|
+
}
|
|
266
|
+
catch (reason) {
|
|
255
267
|
console.error(`Failed to set ${id}: ${reason.message}`);
|
|
256
|
-
}
|
|
268
|
+
}
|
|
257
269
|
},
|
|
258
270
|
isToggled: args => {
|
|
259
|
-
|
|
260
|
-
const
|
|
261
|
-
return
|
|
271
|
+
var _a;
|
|
272
|
+
const currentIndentUnit = (_a = config.indentUnit) !== null && _a !== void 0 ? _a : extensions.baseConfiguration.indentUnit;
|
|
273
|
+
return args['size']
|
|
274
|
+
? args['size'] === currentIndentUnit
|
|
275
|
+
: 'Tab' == currentIndentUnit;
|
|
262
276
|
}
|
|
263
277
|
});
|
|
264
278
|
/**
|
|
265
279
|
* Add the Match Brackets command
|
|
266
280
|
*/
|
|
267
281
|
commands.addCommand(CommandIDs.matchBrackets, {
|
|
268
|
-
execute: () => {
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
.
|
|
282
|
+
execute: async () => {
|
|
283
|
+
var _a;
|
|
284
|
+
config.matchBrackets = !((_a = config.matchBrackets) !== null && _a !== void 0 ? _a : extensions.baseConfiguration.matchBrackets);
|
|
285
|
+
try {
|
|
286
|
+
return await settingRegistry.set(id, 'editorConfig', config);
|
|
287
|
+
}
|
|
288
|
+
catch (reason) {
|
|
273
289
|
console.error(`Failed to set ${id}: ${reason.message}`);
|
|
274
|
-
}
|
|
290
|
+
}
|
|
275
291
|
},
|
|
276
292
|
label: trans.__('Match Brackets'),
|
|
277
293
|
isEnabled,
|
|
278
|
-
isToggled: () => config.matchBrackets
|
|
294
|
+
isToggled: () => { var _a; return (_a = config.matchBrackets) !== null && _a !== void 0 ? _a : extensions.baseConfiguration.matchBrackets; }
|
|
279
295
|
});
|
|
280
296
|
commands.addCommand(CommandIDs.currentMatchBrackets, {
|
|
281
297
|
label: trans.__('Match Brackets'),
|
|
298
|
+
caption: trans.__('Change match brackets for the current file.'),
|
|
282
299
|
execute: () => {
|
|
283
300
|
const widget = tracker.currentWidget;
|
|
284
301
|
if (!widget) {
|
|
@@ -291,24 +308,28 @@ export var Commands;
|
|
|
291
308
|
isToggled: () => {
|
|
292
309
|
var _a;
|
|
293
310
|
const widget = tracker.currentWidget;
|
|
294
|
-
return (_a = widget === null || widget === void 0 ? void 0 : widget.content.editor.getOption('matchBrackets')) !== null && _a !== void 0 ? _a : false;
|
|
311
|
+
return ((_a = widget === null || widget === void 0 ? void 0 : widget.content.editor.getOption('matchBrackets')) !== null && _a !== void 0 ? _a : false);
|
|
295
312
|
}
|
|
296
313
|
});
|
|
297
314
|
/**
|
|
298
315
|
* Add the Auto Close Brackets for Text Editor command
|
|
299
316
|
*/
|
|
300
317
|
commands.addCommand(CommandIDs.autoClosingBrackets, {
|
|
301
|
-
execute: args => {
|
|
302
|
-
var _a;
|
|
303
|
-
config.autoClosingBrackets = !!((_a = args['force']) !== null && _a !== void 0 ? _a : !config.autoClosingBrackets);
|
|
304
|
-
|
|
305
|
-
.set(id, 'editorConfig', config)
|
|
306
|
-
|
|
318
|
+
execute: async (args) => {
|
|
319
|
+
var _a, _b;
|
|
320
|
+
config.autoClosingBrackets = !!((_a = args['force']) !== null && _a !== void 0 ? _a : !((_b = config.autoClosingBrackets) !== null && _b !== void 0 ? _b : extensions.baseConfiguration.autoClosingBrackets));
|
|
321
|
+
try {
|
|
322
|
+
return await settingRegistry.set(id, 'editorConfig', config);
|
|
323
|
+
}
|
|
324
|
+
catch (reason) {
|
|
307
325
|
console.error(`Failed to set ${id}: ${reason.message}`);
|
|
308
|
-
}
|
|
326
|
+
}
|
|
309
327
|
},
|
|
310
|
-
label: trans.__('Auto Close Brackets
|
|
311
|
-
isToggled: () =>
|
|
328
|
+
label: trans.__('Auto Close Brackets in Text Editor'),
|
|
329
|
+
isToggled: () => {
|
|
330
|
+
var _a;
|
|
331
|
+
return (_a = config.autoClosingBrackets) !== null && _a !== void 0 ? _a : extensions.baseConfiguration.autoClosingBrackets;
|
|
332
|
+
}
|
|
312
333
|
});
|
|
313
334
|
commands.addCommand(CommandIDs.autoClosingBracketsUniversal, {
|
|
314
335
|
execute: () => {
|
|
@@ -337,6 +358,87 @@ export var Commands;
|
|
|
337
358
|
commands.isToggled(autoClosingBracketsNotebook) ||
|
|
338
359
|
commands.isToggled(autoClosingBracketsConsole)
|
|
339
360
|
});
|
|
361
|
+
/**
|
|
362
|
+
* Create a menu for the editor.
|
|
363
|
+
*/
|
|
364
|
+
commands.addCommand(CommandIDs.changeTheme, {
|
|
365
|
+
label: args => {
|
|
366
|
+
var _a, _b, _c, _d;
|
|
367
|
+
return (_d = (_c = (_b = ((_a = args.displayName) !== null && _a !== void 0 ? _a : args.theme)) !== null && _b !== void 0 ? _b : config.theme) !== null && _c !== void 0 ? _c : extensions.baseConfiguration.theme) !== null && _d !== void 0 ? _d : trans.__('Editor Theme');
|
|
368
|
+
},
|
|
369
|
+
execute: async (args) => {
|
|
370
|
+
var _a;
|
|
371
|
+
config.theme = (_a = args['theme']) !== null && _a !== void 0 ? _a : config.theme;
|
|
372
|
+
try {
|
|
373
|
+
return await settingRegistry.set(id, 'editorConfig', config);
|
|
374
|
+
}
|
|
375
|
+
catch (reason) {
|
|
376
|
+
console.error(`Failed to set theme - ${reason.message}`);
|
|
377
|
+
}
|
|
378
|
+
},
|
|
379
|
+
isToggled: args => { var _a; return args['theme'] === ((_a = config.theme) !== null && _a !== void 0 ? _a : extensions.baseConfiguration.theme); }
|
|
380
|
+
});
|
|
381
|
+
commands.addCommand(CommandIDs.find, {
|
|
382
|
+
label: trans.__('Find…'),
|
|
383
|
+
execute: () => {
|
|
384
|
+
const widget = tracker.currentWidget;
|
|
385
|
+
if (!widget) {
|
|
386
|
+
return;
|
|
387
|
+
}
|
|
388
|
+
const editor = widget.content.editor;
|
|
389
|
+
editor.execCommand(findNext);
|
|
390
|
+
},
|
|
391
|
+
isEnabled
|
|
392
|
+
});
|
|
393
|
+
commands.addCommand(CommandIDs.goToLine, {
|
|
394
|
+
label: trans.__('Go to Line…'),
|
|
395
|
+
execute: args => {
|
|
396
|
+
const widget = tracker.currentWidget;
|
|
397
|
+
if (!widget) {
|
|
398
|
+
return;
|
|
399
|
+
}
|
|
400
|
+
const editor = widget.content.editor;
|
|
401
|
+
const line = args['line'];
|
|
402
|
+
const column = args['column'];
|
|
403
|
+
if (line !== undefined || column !== undefined) {
|
|
404
|
+
editor.setCursorPosition({
|
|
405
|
+
line: (line !== null && line !== void 0 ? line : 1) - 1,
|
|
406
|
+
column: (column !== null && column !== void 0 ? column : 1) - 1
|
|
407
|
+
});
|
|
408
|
+
}
|
|
409
|
+
else {
|
|
410
|
+
editor.execCommand(gotoLine);
|
|
411
|
+
}
|
|
412
|
+
},
|
|
413
|
+
isEnabled
|
|
414
|
+
});
|
|
415
|
+
commands.addCommand(CommandIDs.changeLanguage, {
|
|
416
|
+
label: args => {
|
|
417
|
+
var _a, _b;
|
|
418
|
+
return (_b = ((_a = args['displayName']) !== null && _a !== void 0 ? _a : args['name'])) !== null && _b !== void 0 ? _b : trans.__('Change editor language.');
|
|
419
|
+
},
|
|
420
|
+
execute: args => {
|
|
421
|
+
const name = args['name'];
|
|
422
|
+
const widget = tracker.currentWidget;
|
|
423
|
+
if (name && widget) {
|
|
424
|
+
const spec = languages.findByName(name);
|
|
425
|
+
if (spec) {
|
|
426
|
+
widget.content.model.mimeType = spec.mime;
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
},
|
|
430
|
+
isEnabled,
|
|
431
|
+
isToggled: args => {
|
|
432
|
+
const widget = tracker.currentWidget;
|
|
433
|
+
if (!widget) {
|
|
434
|
+
return false;
|
|
435
|
+
}
|
|
436
|
+
const mime = widget.content.model.mimeType;
|
|
437
|
+
const spec = languages.findByMIME(mime);
|
|
438
|
+
const name = spec && spec.name;
|
|
439
|
+
return args['name'] === name;
|
|
440
|
+
}
|
|
441
|
+
});
|
|
340
442
|
/**
|
|
341
443
|
* Add the replace selection for text editor command
|
|
342
444
|
*/
|
|
@@ -362,7 +464,7 @@ export var Commands;
|
|
|
362
464
|
if (!widget) {
|
|
363
465
|
return;
|
|
364
466
|
}
|
|
365
|
-
return getCreateConsoleFunction(commands)(widget, args);
|
|
467
|
+
return getCreateConsoleFunction(commands, languages)(widget, args);
|
|
366
468
|
},
|
|
367
469
|
isEnabled,
|
|
368
470
|
icon: consoleIcon,
|
|
@@ -380,7 +482,7 @@ export var Commands;
|
|
|
380
482
|
}
|
|
381
483
|
const widget = consoleTracker.find(widget => { var _a; return ((_a = widget.sessionContext.session) === null || _a === void 0 ? void 0 : _a.path) === current.context.path; });
|
|
382
484
|
if (widget) {
|
|
383
|
-
return
|
|
485
|
+
return sessionDialogs.restart(widget.sessionContext);
|
|
384
486
|
}
|
|
385
487
|
},
|
|
386
488
|
label: trans.__('Restart Kernel'),
|
|
@@ -408,10 +510,10 @@ export var Commands;
|
|
|
408
510
|
// Get the selected code from the editor.
|
|
409
511
|
const start = editor.getOffsetAt(selection.start);
|
|
410
512
|
const end = editor.getOffsetAt(selection.end);
|
|
411
|
-
code = editor.model.
|
|
513
|
+
code = editor.model.sharedModel.getSource().substring(start, end);
|
|
412
514
|
}
|
|
413
515
|
else if (MarkdownCodeBlocks.isMarkdown(extension)) {
|
|
414
|
-
const
|
|
516
|
+
const text = editor.model.sharedModel.getSource();
|
|
415
517
|
const blocks = MarkdownCodeBlocks.findMarkdownCodeBlocks(text);
|
|
416
518
|
for (const block of blocks) {
|
|
417
519
|
if (block.startLine <= start.line && start.line <= block.endLine) {
|
|
@@ -426,8 +528,8 @@ export var Commands;
|
|
|
426
528
|
code = editor.getLine(selection.start.line);
|
|
427
529
|
const cursor = editor.getCursorPosition();
|
|
428
530
|
if (cursor.line + 1 === editor.lineCount) {
|
|
429
|
-
const text = editor.model.
|
|
430
|
-
editor.model.
|
|
531
|
+
const text = editor.model.sharedModel.getSource();
|
|
532
|
+
editor.model.sharedModel.setSource(text + '\n');
|
|
431
533
|
}
|
|
432
534
|
editor.setCursorPosition({
|
|
433
535
|
line: cursor.line + 1,
|
|
@@ -457,7 +559,7 @@ export var Commands;
|
|
|
457
559
|
}
|
|
458
560
|
let code = '';
|
|
459
561
|
const editor = widget.editor;
|
|
460
|
-
const text = editor.model.
|
|
562
|
+
const text = editor.model.sharedModel.getSource();
|
|
461
563
|
const path = widget.context.path;
|
|
462
564
|
const extension = PathExt.extname(path);
|
|
463
565
|
if (MarkdownCodeBlocks.isMarkdown(extension)) {
|
|
@@ -529,7 +631,7 @@ export var Commands;
|
|
|
529
631
|
},
|
|
530
632
|
execute: args => {
|
|
531
633
|
var _a;
|
|
532
|
-
const cwd = args.cwd ||
|
|
634
|
+
const cwd = args.cwd || defaultBrowser.model.path;
|
|
533
635
|
return createNew(commands, cwd, (_a = args.fileExt) !== null && _a !== void 0 ? _a : 'txt');
|
|
534
636
|
}
|
|
535
637
|
});
|
|
@@ -543,7 +645,7 @@ export var Commands;
|
|
|
543
645
|
caption: trans.__('Create a new markdown file'),
|
|
544
646
|
icon: args => (args['isPalette'] ? undefined : markdownIcon),
|
|
545
647
|
execute: args => {
|
|
546
|
-
const cwd = args['cwd'] ||
|
|
648
|
+
const cwd = args['cwd'] || defaultBrowser.model.path;
|
|
547
649
|
return createNew(commands, cwd, 'md');
|
|
548
650
|
}
|
|
549
651
|
});
|
|
@@ -696,15 +798,17 @@ export var Commands;
|
|
|
696
798
|
return;
|
|
697
799
|
}
|
|
698
800
|
const editor = widget.editor;
|
|
699
|
-
editor.execCommand(
|
|
801
|
+
editor.execCommand(selectAll);
|
|
700
802
|
},
|
|
701
803
|
isEnabled: () => { var _a; return Boolean(isEnabled() && ((_a = tracker.currentWidget) === null || _a === void 0 ? void 0 : _a.content)); },
|
|
702
804
|
label: trans.__('Select All')
|
|
703
805
|
});
|
|
704
806
|
}
|
|
705
807
|
Commands.addCommands = addCommands;
|
|
706
|
-
function addCompleterCommands(commands, editorTracker, manager) {
|
|
808
|
+
function addCompleterCommands(commands, editorTracker, manager, translator) {
|
|
809
|
+
const trans = (translator !== null && translator !== void 0 ? translator : nullTranslator).load('jupyterlab');
|
|
707
810
|
commands.addCommand(CommandIDs.invokeCompleter, {
|
|
811
|
+
label: trans.__('Display the completion helper.'),
|
|
708
812
|
execute: () => {
|
|
709
813
|
const id = editorTracker.currentWidget && editorTracker.currentWidget.id;
|
|
710
814
|
if (id) {
|
|
@@ -713,6 +817,7 @@ export var Commands;
|
|
|
713
817
|
}
|
|
714
818
|
});
|
|
715
819
|
commands.addCommand(CommandIDs.selectCompleter, {
|
|
820
|
+
label: trans.__('Select the completion suggestion.'),
|
|
716
821
|
execute: () => {
|
|
717
822
|
const id = editorTracker.currentWidget && editorTracker.currentWidget.id;
|
|
718
823
|
if (id) {
|
|
@@ -743,27 +848,26 @@ export var Commands;
|
|
|
743
848
|
const selectionObj = editor.getSelection();
|
|
744
849
|
const start = editor.getOffsetAt(selectionObj.start);
|
|
745
850
|
const end = editor.getOffsetAt(selectionObj.end);
|
|
746
|
-
const text = editor.model.
|
|
851
|
+
const text = editor.model.sharedModel.getSource().substring(start, end);
|
|
747
852
|
return text;
|
|
748
853
|
}
|
|
749
854
|
/**
|
|
750
855
|
* Function to create a new untitled text file, given the current working directory.
|
|
751
856
|
*/
|
|
752
|
-
function createNew(commands, cwd, ext = 'txt') {
|
|
753
|
-
|
|
754
|
-
.execute('docmanager:new-untitled', {
|
|
857
|
+
async function createNew(commands, cwd, ext = 'txt') {
|
|
858
|
+
const model = await commands.execute('docmanager:new-untitled', {
|
|
755
859
|
path: cwd,
|
|
756
860
|
type: 'file',
|
|
757
861
|
ext
|
|
758
|
-
})
|
|
759
|
-
.then(model => {
|
|
760
|
-
if (model != undefined) {
|
|
761
|
-
return commands.execute('docmanager:open', {
|
|
762
|
-
path: model.path,
|
|
763
|
-
factory: FACTORY
|
|
764
|
-
});
|
|
765
|
-
}
|
|
766
862
|
});
|
|
863
|
+
if (model != undefined) {
|
|
864
|
+
const widget = (await commands.execute('docmanager:open', {
|
|
865
|
+
path: model.path,
|
|
866
|
+
factory: FACTORY
|
|
867
|
+
}));
|
|
868
|
+
widget.isUntitled = true;
|
|
869
|
+
return widget;
|
|
870
|
+
}
|
|
767
871
|
}
|
|
768
872
|
/**
|
|
769
873
|
* Wrapper function for adding the default launcher items for File Editor
|
|
@@ -825,14 +929,12 @@ export var Commands;
|
|
|
825
929
|
function addChangeTabsCommandsToPalette(palette, trans) {
|
|
826
930
|
const paletteCategory = trans.__('Text Editor');
|
|
827
931
|
const args = {
|
|
828
|
-
insertSpaces: false,
|
|
829
932
|
size: 4
|
|
830
933
|
};
|
|
831
934
|
const command = CommandIDs.changeTabs;
|
|
832
935
|
palette.addItem({ command, args, category: paletteCategory });
|
|
833
936
|
for (const size of [1, 2, 4, 8]) {
|
|
834
937
|
const args = {
|
|
835
|
-
insertSpaces: true,
|
|
836
938
|
size
|
|
837
939
|
};
|
|
838
940
|
palette.addItem({ command, args, category: paletteCategory });
|
|
@@ -883,7 +985,7 @@ export var Commands;
|
|
|
883
985
|
for (let ext of availableKernelFileTypes) {
|
|
884
986
|
palette.addItem({
|
|
885
987
|
command: CommandIDs.createNew,
|
|
886
|
-
args:
|
|
988
|
+
args: { ...ext, isPalette: true },
|
|
887
989
|
category: paletteCategory
|
|
888
990
|
});
|
|
889
991
|
}
|
|
@@ -959,5 +1061,43 @@ export var Commands;
|
|
|
959
1061
|
});
|
|
960
1062
|
}
|
|
961
1063
|
Commands.addCodeRunnersToRunMenu = addCodeRunnersToRunMenu;
|
|
1064
|
+
function addOpenCodeViewerCommand(app, editorServices, tracker, trans) {
|
|
1065
|
+
const openCodeViewer = async (args) => {
|
|
1066
|
+
var _a;
|
|
1067
|
+
const func = editorServices.factoryService.newDocumentEditor;
|
|
1068
|
+
const factory = options => {
|
|
1069
|
+
return func(options);
|
|
1070
|
+
};
|
|
1071
|
+
// Derive mimetype from extension
|
|
1072
|
+
let mimetype = args.mimeType;
|
|
1073
|
+
if (!mimetype && args.extension) {
|
|
1074
|
+
mimetype = editorServices.mimeTypeService.getMimeTypeByFilePath(`temp.${args.extension.replace(/\\.$/, '')}`);
|
|
1075
|
+
}
|
|
1076
|
+
const widget = CodeViewerWidget.createCodeViewer({
|
|
1077
|
+
factory,
|
|
1078
|
+
content: args.content,
|
|
1079
|
+
mimeType: mimetype
|
|
1080
|
+
});
|
|
1081
|
+
widget.title.label = args.label || trans.__('Code Viewer');
|
|
1082
|
+
widget.title.caption = widget.title.label;
|
|
1083
|
+
// Get the fileType based on the mimetype to determine the icon
|
|
1084
|
+
const fileType = find(app.docRegistry.fileTypes(), fileType => mimetype ? fileType.mimeTypes.includes(mimetype) : false);
|
|
1085
|
+
widget.title.icon = (_a = fileType === null || fileType === void 0 ? void 0 : fileType.icon) !== null && _a !== void 0 ? _a : textEditorIcon;
|
|
1086
|
+
if (args.widgetId) {
|
|
1087
|
+
widget.id = args.widgetId;
|
|
1088
|
+
}
|
|
1089
|
+
const main = new MainAreaWidget({ content: widget });
|
|
1090
|
+
await tracker.add(main);
|
|
1091
|
+
app.shell.add(main, 'main');
|
|
1092
|
+
return widget;
|
|
1093
|
+
};
|
|
1094
|
+
app.commands.addCommand(CommandIDs.openCodeViewer, {
|
|
1095
|
+
label: trans.__('Open Code Viewer'),
|
|
1096
|
+
execute: (args) => {
|
|
1097
|
+
return openCodeViewer(args);
|
|
1098
|
+
}
|
|
1099
|
+
});
|
|
1100
|
+
}
|
|
1101
|
+
Commands.addOpenCodeViewerCommand = addOpenCodeViewerCommand;
|
|
962
1102
|
})(Commands || (Commands = {}));
|
|
963
1103
|
//# sourceMappingURL=commands.js.map
|