@jupyterlab/fileeditor-extension 4.0.0-alpha.19 → 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/commands.d.ts +7 -2
- package/lib/commands.js +187 -94
- package/lib/commands.js.map +1 -1
- package/lib/index.js +88 -24
- 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 +32 -30
- package/schema/plugin.json +48 -119
- package/src/commands.ts +1388 -0
- package/src/index.ts +671 -0
- package/src/syntaxstatus.ts +64 -0
- package/style/index.css +2 -2
- package/style/index.js +2 -2
package/lib/commands.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { JupyterFrontEnd } from '@jupyterlab/application';
|
|
2
2
|
import { ICommandPalette, ISessionContextDialogs, MainAreaWidget, WidgetTracker } from '@jupyterlab/apputils';
|
|
3
3
|
import { CodeViewerWidget, IEditorServices } from '@jupyterlab/codeeditor';
|
|
4
|
+
import { IEditorExtensionRegistry, IEditorLanguageRegistry, IEditorThemeRegistry } from '@jupyterlab/codemirror';
|
|
4
5
|
import { ICompletionProviderManager } from '@jupyterlab/completer';
|
|
5
6
|
import { IConsoleTracker } from '@jupyterlab/console';
|
|
6
7
|
import { IDocumentWidget } from '@jupyterlab/docregistry';
|
|
7
|
-
import { IDefaultFileBrowser
|
|
8
|
+
import { IDefaultFileBrowser } from '@jupyterlab/filebrowser';
|
|
8
9
|
import { FileEditor, IEditorTracker } from '@jupyterlab/fileeditor';
|
|
9
10
|
import { ILauncher } from '@jupyterlab/launcher';
|
|
10
11
|
import { IMainMenu } from '@jupyterlab/mainmenu';
|
|
@@ -43,6 +44,10 @@ export declare namespace CommandIDs {
|
|
|
43
44
|
const invokeCompleter = "completer:invoke-file";
|
|
44
45
|
const selectCompleter = "completer:select-file";
|
|
45
46
|
const openCodeViewer = "code-viewer:open";
|
|
47
|
+
const changeTheme = "fileeditor:change-theme";
|
|
48
|
+
const changeLanguage = "fileeditor:change-language";
|
|
49
|
+
const find = "fileeditor:find";
|
|
50
|
+
const goToLine = "fileeditor:go-to-line";
|
|
46
51
|
}
|
|
47
52
|
export interface IFileTypeData extends ReadonlyJSONObject {
|
|
48
53
|
fileExt: string;
|
|
@@ -76,7 +81,7 @@ export declare namespace Commands {
|
|
|
76
81
|
/**
|
|
77
82
|
* Wrapper function for adding the default File Editor commands
|
|
78
83
|
*/
|
|
79
|
-
function addCommands(commands: CommandRegistry, settingRegistry: ISettingRegistry, trans: TranslationBundle, id: string, isEnabled: () => boolean, tracker: WidgetTracker<IDocumentWidget<FileEditor>>, defaultBrowser: IDefaultFileBrowser,
|
|
84
|
+
function addCommands(commands: CommandRegistry, settingRegistry: ISettingRegistry, trans: TranslationBundle, id: string, isEnabled: () => boolean, tracker: WidgetTracker<IDocumentWidget<FileEditor>>, defaultBrowser: IDefaultFileBrowser, extensions: IEditorExtensionRegistry, languages: IEditorLanguageRegistry, themes: IEditorThemeRegistry, consoleTracker: IConsoleTracker | null, sessionDialogs: ISessionContextDialogs | null, mainMenu: IMainMenu | null): void;
|
|
80
85
|
function addCompleterCommands(commands: CommandRegistry, editorTracker: IEditorTracker, manager: ICompletionProviderManager, translator: ITranslator | null): void;
|
|
81
86
|
/**
|
|
82
87
|
* Wrapper function for adding the default launcher items for File Editor
|
package/lib/commands.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
// Copyright (c) Jupyter Development Team.
|
|
2
2
|
// Distributed under the terms of the Modified BSD License.
|
|
3
|
+
import { selectAll } from '@codemirror/commands';
|
|
4
|
+
import { findNext, gotoLine } from '@codemirror/search';
|
|
3
5
|
import { Clipboard, MainAreaWidget, sessionContextDialogs } from '@jupyterlab/apputils';
|
|
4
|
-
import {
|
|
6
|
+
import { CodeViewerWidget } from '@jupyterlab/codeeditor';
|
|
5
7
|
import { MarkdownCodeBlocks, PathExt } from '@jupyterlab/coreutils';
|
|
6
8
|
import { nullTranslator } from '@jupyterlab/translation';
|
|
7
9
|
import { consoleIcon, copyIcon, cutIcon, LabIcon, markdownIcon, pasteIcon, redoIcon, textEditorIcon, undoIcon } from '@jupyterlab/ui-components';
|
|
8
10
|
import { find } from '@lumino/algorithm';
|
|
9
|
-
import { selectAll } from '@codemirror/commands';
|
|
10
11
|
const autoClosingBracketsNotebook = 'notebook:toggle-autoclosing-brackets';
|
|
11
12
|
const autoClosingBracketsConsole = 'console:toggle-autoclosing-brackets';
|
|
12
13
|
/**
|
|
@@ -41,57 +42,37 @@ export var CommandIDs;
|
|
|
41
42
|
CommandIDs.invokeCompleter = 'completer:invoke-file';
|
|
42
43
|
CommandIDs.selectCompleter = 'completer:select-file';
|
|
43
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';
|
|
44
49
|
})(CommandIDs || (CommandIDs = {}));
|
|
45
50
|
/**
|
|
46
51
|
* The name of the factory that creates editor widgets.
|
|
47
52
|
*/
|
|
48
53
|
export const FACTORY = 'Editor';
|
|
49
|
-
const userSettings = [
|
|
50
|
-
'autoClosingBrackets',
|
|
51
|
-
'codeFolding',
|
|
52
|
-
'cursorBlinkRate',
|
|
53
|
-
'fontFamily',
|
|
54
|
-
'fontSize',
|
|
55
|
-
'insertSpaces',
|
|
56
|
-
'lineHeight',
|
|
57
|
-
'lineNumbers',
|
|
58
|
-
'lineWrap',
|
|
59
|
-
'matchBrackets',
|
|
60
|
-
'readOnly',
|
|
61
|
-
'rulers',
|
|
62
|
-
'showTrailingSpace',
|
|
63
|
-
'tabSize',
|
|
64
|
-
'wordWrapColumn'
|
|
65
|
-
];
|
|
66
|
-
function filterUserSettings(config) {
|
|
67
|
-
const filteredConfig = { ...config };
|
|
68
|
-
// Delete parts of the config that are not user settings (like handlePaste).
|
|
69
|
-
for (let k of Object.keys(config)) {
|
|
70
|
-
if (!userSettings.includes(k)) {
|
|
71
|
-
delete config[k];
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
return filteredConfig;
|
|
75
|
-
}
|
|
76
|
-
let config = filterUserSettings(CodeEditor.defaultConfig);
|
|
77
54
|
/**
|
|
78
55
|
* A utility class for adding commands and menu items,
|
|
79
56
|
* for use by the File Editor extension or other Editor extensions.
|
|
80
57
|
*/
|
|
81
58
|
export var Commands;
|
|
82
59
|
(function (Commands) {
|
|
60
|
+
let config = {};
|
|
61
|
+
let scrollPastEnd = true;
|
|
83
62
|
/**
|
|
84
63
|
* Accessor function that returns the createConsole function for use by Create Console commands
|
|
85
64
|
*/
|
|
86
|
-
function getCreateConsoleFunction(commands) {
|
|
65
|
+
function getCreateConsoleFunction(commands, languages) {
|
|
87
66
|
return async function createConsole(widget, args) {
|
|
88
|
-
var _a;
|
|
67
|
+
var _a, _b, _c;
|
|
89
68
|
const options = args || {};
|
|
90
69
|
const console = await commands.execute('console:create', {
|
|
91
70
|
activate: options['activate'],
|
|
92
71
|
name: (_a = widget.context.contentsModel) === null || _a === void 0 ? void 0 : _a.name,
|
|
93
72
|
path: widget.context.path,
|
|
94
|
-
|
|
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 : ''),
|
|
95
76
|
ref: widget.id,
|
|
96
77
|
insertMode: 'split-bottom'
|
|
97
78
|
});
|
|
@@ -106,12 +87,20 @@ export var Commands;
|
|
|
106
87
|
* Update the setting values.
|
|
107
88
|
*/
|
|
108
89
|
function updateSettings(settings, commands) {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
90
|
+
var _a;
|
|
91
|
+
config =
|
|
92
|
+
(_a = settings.get('editorConfig').composite) !== null && _a !== void 0 ? _a : {};
|
|
93
|
+
scrollPastEnd = settings.get('scrollPasteEnd').composite;
|
|
113
94
|
// Trigger a refresh of the rendered commands
|
|
114
|
-
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);
|
|
115
104
|
}
|
|
116
105
|
Commands.updateSettings = updateSettings;
|
|
117
106
|
/**
|
|
@@ -129,18 +118,19 @@ export var Commands;
|
|
|
129
118
|
*/
|
|
130
119
|
function updateWidget(widget) {
|
|
131
120
|
const editor = widget.editor;
|
|
132
|
-
editor.setOptions({ ...config });
|
|
121
|
+
editor.setOptions({ ...config, scrollPastEnd });
|
|
133
122
|
}
|
|
134
123
|
Commands.updateWidget = updateWidget;
|
|
135
124
|
/**
|
|
136
125
|
* Wrapper function for adding the default File Editor commands
|
|
137
126
|
*/
|
|
138
|
-
function addCommands(commands, settingRegistry, trans, id, isEnabled, tracker, defaultBrowser,
|
|
127
|
+
function addCommands(commands, settingRegistry, trans, id, isEnabled, tracker, defaultBrowser, extensions, languages, themes, consoleTracker, sessionDialogs, mainMenu) {
|
|
139
128
|
/**
|
|
140
129
|
* Add a command to change font size for File Editor
|
|
141
130
|
*/
|
|
142
131
|
commands.addCommand(CommandIDs.changeFontSize, {
|
|
143
132
|
execute: args => {
|
|
133
|
+
var _a;
|
|
144
134
|
const delta = Number(args['delta']);
|
|
145
135
|
if (Number.isNaN(delta)) {
|
|
146
136
|
console.error(`${CommandIDs.changeFontSize}: delta arg must be a number`);
|
|
@@ -148,7 +138,8 @@ export var Commands;
|
|
|
148
138
|
}
|
|
149
139
|
const style = window.getComputedStyle(document.documentElement);
|
|
150
140
|
const cssSize = parseInt(style.getPropertyValue('--jp-code-font-size'), 10);
|
|
151
|
-
const currentSize = config.fontSize ||
|
|
141
|
+
const currentSize = ((_a = config['customStyles']['fontSize']) !== null && _a !== void 0 ? _a : extensions.baseConfiguration['customStyles']['fontSize']) ||
|
|
142
|
+
cssSize;
|
|
152
143
|
config.fontSize = currentSize + delta;
|
|
153
144
|
return settingRegistry
|
|
154
145
|
.set(id, 'editorConfig', config)
|
|
@@ -157,8 +148,11 @@ export var Commands;
|
|
|
157
148
|
});
|
|
158
149
|
},
|
|
159
150
|
label: args => {
|
|
160
|
-
|
|
161
|
-
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) {
|
|
162
156
|
return args.isMenu
|
|
163
157
|
? trans.__('Increase Text Editor Font Size')
|
|
164
158
|
: trans.__('Increase Font Size');
|
|
@@ -174,20 +168,23 @@ export var Commands;
|
|
|
174
168
|
* Add the Line Numbers command
|
|
175
169
|
*/
|
|
176
170
|
commands.addCommand(CommandIDs.lineNumbers, {
|
|
177
|
-
execute: () => {
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
.
|
|
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) {
|
|
182
178
|
console.error(`Failed to set ${id}: ${reason.message}`);
|
|
183
|
-
}
|
|
179
|
+
}
|
|
184
180
|
},
|
|
185
181
|
isEnabled,
|
|
186
|
-
isToggled: () => config.lineNumbers,
|
|
187
|
-
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')
|
|
188
184
|
});
|
|
189
185
|
commands.addCommand(CommandIDs.currentLineNumbers, {
|
|
190
186
|
label: trans.__('Show Line Numbers'),
|
|
187
|
+
caption: trans.__('Show the line numbers for the current file.'),
|
|
191
188
|
execute: () => {
|
|
192
189
|
const widget = tracker.currentWidget;
|
|
193
190
|
if (!widget) {
|
|
@@ -200,44 +197,48 @@ export var Commands;
|
|
|
200
197
|
isToggled: () => {
|
|
201
198
|
var _a;
|
|
202
199
|
const widget = tracker.currentWidget;
|
|
203
|
-
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);
|
|
204
201
|
}
|
|
205
202
|
});
|
|
206
203
|
/**
|
|
207
204
|
* Add the Word Wrap command
|
|
208
205
|
*/
|
|
209
206
|
commands.addCommand(CommandIDs.lineWrap, {
|
|
210
|
-
execute: args => {
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
.
|
|
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) {
|
|
215
214
|
console.error(`Failed to set ${id}: ${reason.message}`);
|
|
216
|
-
}
|
|
215
|
+
}
|
|
217
216
|
},
|
|
218
217
|
isEnabled,
|
|
219
218
|
isToggled: args => {
|
|
220
|
-
|
|
221
|
-
|
|
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));
|
|
222
223
|
},
|
|
223
224
|
label: trans.__('Word Wrap')
|
|
224
225
|
});
|
|
225
226
|
commands.addCommand(CommandIDs.currentLineWrap, {
|
|
226
227
|
label: trans.__('Wrap Words'),
|
|
228
|
+
caption: trans.__('Wrap words for the current file.'),
|
|
227
229
|
execute: () => {
|
|
228
230
|
const widget = tracker.currentWidget;
|
|
229
231
|
if (!widget) {
|
|
230
232
|
return;
|
|
231
233
|
}
|
|
232
234
|
const oldValue = widget.content.editor.getOption('lineWrap');
|
|
233
|
-
|
|
234
|
-
widget.content.editor.setOption('lineWrap', newValue);
|
|
235
|
+
widget.content.editor.setOption('lineWrap', !oldValue);
|
|
235
236
|
},
|
|
236
237
|
isEnabled,
|
|
237
238
|
isToggled: () => {
|
|
238
239
|
var _a;
|
|
239
240
|
const widget = tracker.currentWidget;
|
|
240
|
-
return (_a =
|
|
241
|
+
return ((_a = widget === null || widget === void 0 ? void 0 : widget.content.editor.getOption('lineWrap')) !== null && _a !== void 0 ? _a : false);
|
|
241
242
|
}
|
|
242
243
|
});
|
|
243
244
|
/**
|
|
@@ -246,46 +247,55 @@ export var Commands;
|
|
|
246
247
|
commands.addCommand(CommandIDs.changeTabs, {
|
|
247
248
|
label: args => {
|
|
248
249
|
var _a;
|
|
249
|
-
if (args.
|
|
250
|
-
return trans.__('Spaces: %1', (_a = args.size) !== null && _a !== void 0 ? _a :
|
|
250
|
+
if (args.size) {
|
|
251
|
+
return trans.__('Spaces: %1', (_a = args.size) !== null && _a !== void 0 ? _a : '');
|
|
251
252
|
}
|
|
252
253
|
else {
|
|
253
254
|
return trans.__('Indent with Tab');
|
|
254
255
|
}
|
|
255
256
|
},
|
|
256
|
-
execute: args => {
|
|
257
|
-
|
|
258
|
-
config.
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
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) {
|
|
262
267
|
console.error(`Failed to set ${id}: ${reason.message}`);
|
|
263
|
-
}
|
|
268
|
+
}
|
|
264
269
|
},
|
|
265
270
|
isToggled: args => {
|
|
266
|
-
|
|
267
|
-
const
|
|
268
|
-
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;
|
|
269
276
|
}
|
|
270
277
|
});
|
|
271
278
|
/**
|
|
272
279
|
* Add the Match Brackets command
|
|
273
280
|
*/
|
|
274
281
|
commands.addCommand(CommandIDs.matchBrackets, {
|
|
275
|
-
execute: () => {
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
.
|
|
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) {
|
|
280
289
|
console.error(`Failed to set ${id}: ${reason.message}`);
|
|
281
|
-
}
|
|
290
|
+
}
|
|
282
291
|
},
|
|
283
292
|
label: trans.__('Match Brackets'),
|
|
284
293
|
isEnabled,
|
|
285
|
-
isToggled: () => config.matchBrackets
|
|
294
|
+
isToggled: () => { var _a; return (_a = config.matchBrackets) !== null && _a !== void 0 ? _a : extensions.baseConfiguration.matchBrackets; }
|
|
286
295
|
});
|
|
287
296
|
commands.addCommand(CommandIDs.currentMatchBrackets, {
|
|
288
297
|
label: trans.__('Match Brackets'),
|
|
298
|
+
caption: trans.__('Change match brackets for the current file.'),
|
|
289
299
|
execute: () => {
|
|
290
300
|
const widget = tracker.currentWidget;
|
|
291
301
|
if (!widget) {
|
|
@@ -298,24 +308,28 @@ export var Commands;
|
|
|
298
308
|
isToggled: () => {
|
|
299
309
|
var _a;
|
|
300
310
|
const widget = tracker.currentWidget;
|
|
301
|
-
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);
|
|
302
312
|
}
|
|
303
313
|
});
|
|
304
314
|
/**
|
|
305
315
|
* Add the Auto Close Brackets for Text Editor command
|
|
306
316
|
*/
|
|
307
317
|
commands.addCommand(CommandIDs.autoClosingBrackets, {
|
|
308
|
-
execute: args => {
|
|
309
|
-
var _a;
|
|
310
|
-
config.autoClosingBrackets = !!((_a = args['force']) !== null && _a !== void 0 ? _a : !config.autoClosingBrackets);
|
|
311
|
-
|
|
312
|
-
.set(id, 'editorConfig', config)
|
|
313
|
-
|
|
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) {
|
|
314
325
|
console.error(`Failed to set ${id}: ${reason.message}`);
|
|
315
|
-
}
|
|
326
|
+
}
|
|
316
327
|
},
|
|
317
328
|
label: trans.__('Auto Close Brackets in Text Editor'),
|
|
318
|
-
isToggled: () =>
|
|
329
|
+
isToggled: () => {
|
|
330
|
+
var _a;
|
|
331
|
+
return (_a = config.autoClosingBrackets) !== null && _a !== void 0 ? _a : extensions.baseConfiguration.autoClosingBrackets;
|
|
332
|
+
}
|
|
319
333
|
});
|
|
320
334
|
commands.addCommand(CommandIDs.autoClosingBracketsUniversal, {
|
|
321
335
|
execute: () => {
|
|
@@ -344,6 +358,87 @@ export var Commands;
|
|
|
344
358
|
commands.isToggled(autoClosingBracketsNotebook) ||
|
|
345
359
|
commands.isToggled(autoClosingBracketsConsole)
|
|
346
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
|
+
});
|
|
347
442
|
/**
|
|
348
443
|
* Add the replace selection for text editor command
|
|
349
444
|
*/
|
|
@@ -369,7 +464,7 @@ export var Commands;
|
|
|
369
464
|
if (!widget) {
|
|
370
465
|
return;
|
|
371
466
|
}
|
|
372
|
-
return getCreateConsoleFunction(commands)(widget, args);
|
|
467
|
+
return getCreateConsoleFunction(commands, languages)(widget, args);
|
|
373
468
|
},
|
|
374
469
|
isEnabled,
|
|
375
470
|
icon: consoleIcon,
|
|
@@ -834,14 +929,12 @@ export var Commands;
|
|
|
834
929
|
function addChangeTabsCommandsToPalette(palette, trans) {
|
|
835
930
|
const paletteCategory = trans.__('Text Editor');
|
|
836
931
|
const args = {
|
|
837
|
-
insertSpaces: false,
|
|
838
932
|
size: 4
|
|
839
933
|
};
|
|
840
934
|
const command = CommandIDs.changeTabs;
|
|
841
935
|
palette.addItem({ command, args, category: paletteCategory });
|
|
842
936
|
for (const size of [1, 2, 4, 8]) {
|
|
843
937
|
const args = {
|
|
844
|
-
insertSpaces: true,
|
|
845
938
|
size
|
|
846
939
|
};
|
|
847
940
|
palette.addItem({ command, args, category: paletteCategory });
|