@jupyterlab/notebook-extension 4.0.0-alpha.1 → 4.0.0-alpha.10

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/index.js CHANGED
@@ -5,23 +5,26 @@
5
5
  * @module notebook-extension
6
6
  */
7
7
  import { ILabShell, ILayoutRestorer } from '@jupyterlab/application';
8
- import { createToolbarFactory, Dialog, ICommandPalette, InputDialog, ISessionContextDialogs, IToolbarWidgetRegistry, MainAreaWidget, sessionContextDialogs, showDialog, Toolbar, WidgetTracker } from '@jupyterlab/apputils';
8
+ import { createToolbarFactory, Dialog, ICommandPalette, IKernelStatusModel, InputDialog, ISanitizer, ISessionContextDialogs, IToolbarWidgetRegistry, MainAreaWidget, sessionContextDialogs, showDialog, Toolbar, WidgetTracker } from '@jupyterlab/apputils';
9
9
  import { MarkdownCell } from '@jupyterlab/cells';
10
- import { IEditorServices } from '@jupyterlab/codeeditor';
10
+ import { IEditorServices, IPositionModel } from '@jupyterlab/codeeditor';
11
11
  import { PageConfig } from '@jupyterlab/coreutils';
12
12
  import { IDocumentManager } from '@jupyterlab/docmanager';
13
13
  import { ToolbarItems as DocToolbarItems } from '@jupyterlab/docmanager-extension';
14
+ import { ISearchProviderRegistry } from '@jupyterlab/documentsearch';
14
15
  import { IFileBrowserFactory } from '@jupyterlab/filebrowser';
15
16
  import { ILauncher } from '@jupyterlab/launcher';
16
17
  import { IMainMenu } from '@jupyterlab/mainmenu';
17
- import { CommandEditStatus, ExecutionIndicator, INotebookTools, INotebookTracker, INotebookWidgetFactory, NotebookActions, NotebookModelFactory, NotebookPanel, NotebookTools, NotebookTracker, NotebookTrustStatus, NotebookWidgetFactory, StaticNotebook, ToolbarItems } from '@jupyterlab/notebook';
18
+ import { CommandEditStatus, ExecutionIndicator, INotebookTools, INotebookTracker, INotebookWidgetFactory, NotebookActions, NotebookModelFactory, NotebookPanel, NotebookSearchProvider, NotebookToCFactory, NotebookTools, NotebookTracker, NotebookTrustStatus, NotebookWidgetFactory, StaticNotebook, ToolbarItems } from '@jupyterlab/notebook';
18
19
  import { IPropertyInspectorProvider } from '@jupyterlab/property-inspector';
19
- import { IRenderMimeRegistry } from '@jupyterlab/rendermime';
20
+ import { IMarkdownParser, IRenderMimeRegistry } from '@jupyterlab/rendermime';
20
21
  import { ISettingRegistry } from '@jupyterlab/settingregistry';
21
22
  import { IStateDB } from '@jupyterlab/statedb';
22
23
  import { IStatusBar } from '@jupyterlab/statusbar';
24
+ import { ITableOfContentsRegistry } from '@jupyterlab/toc';
23
25
  import { ITranslator, nullTranslator } from '@jupyterlab/translation';
24
- import { addIcon, buildIcon, copyIcon, cutIcon, notebookIcon, pasteIcon } from '@jupyterlab/ui-components';
26
+ import { addAboveIcon, addBelowIcon, buildIcon, copyIcon, cutIcon, duplicateIcon, moveDownIcon, moveUpIcon, notebookIcon, pasteIcon } from '@jupyterlab/ui-components';
27
+ import { ICompletionProviderManager } from '@jupyterlab/completer';
25
28
  import { ArrayExt } from '@lumino/algorithm';
26
29
  import { JSONExt, UUID } from '@lumino/coreutils';
27
30
  import { DisposableSet } from '@lumino/disposable';
@@ -64,6 +67,7 @@ var CommandIDs;
64
67
  CommandIDs.copy = 'notebook:copy-cell';
65
68
  CommandIDs.pasteAbove = 'notebook:paste-cell-above';
66
69
  CommandIDs.pasteBelow = 'notebook:paste-cell-below';
70
+ CommandIDs.duplicateBelow = 'notebook:duplicate-below';
67
71
  CommandIDs.pasteAndReplace = 'notebook:paste-and-replace-cell';
68
72
  CommandIDs.moveUp = 'notebook:move-cell-up';
69
73
  CommandIDs.moveDown = 'notebook:move-cell-down';
@@ -73,6 +77,10 @@ var CommandIDs;
73
77
  CommandIDs.insertBelow = 'notebook:insert-cell-below';
74
78
  CommandIDs.selectAbove = 'notebook:move-cursor-up';
75
79
  CommandIDs.selectBelow = 'notebook:move-cursor-down';
80
+ CommandIDs.selectHeadingAboveOrCollapse = 'notebook:move-cursor-heading-above-or-collapse';
81
+ CommandIDs.selectHeadingBelowOrExpand = 'notebook:move-cursor-heading-below-or-expand';
82
+ CommandIDs.insertHeadingAbove = 'notebook:insert-heading-above';
83
+ CommandIDs.insertHeadingBelow = 'notebook:insert-heading-below';
76
84
  CommandIDs.extendAbove = 'notebook:extend-marked-cells-above';
77
85
  CommandIDs.extendTop = 'notebook:extend-marked-cells-top';
78
86
  CommandIDs.extendBelow = 'notebook:extend-marked-cells-below';
@@ -104,17 +112,20 @@ var CommandIDs;
104
112
  CommandIDs.showOutput = 'notebook:show-cell-outputs';
105
113
  CommandIDs.hideAllOutputs = 'notebook:hide-all-cell-outputs';
106
114
  CommandIDs.showAllOutputs = 'notebook:show-all-cell-outputs';
107
- CommandIDs.toggleRenderSideBySide = 'notebook:toggle-render-side-by-side';
115
+ CommandIDs.toggleRenderSideBySideCurrentNotebook = 'notebook:toggle-render-side-by-side-current';
108
116
  CommandIDs.setSideBySideRatio = 'notebook:set-side-by-side-ratio';
109
117
  CommandIDs.enableOutputScrolling = 'notebook:enable-output-scrolling';
110
118
  CommandIDs.disableOutputScrolling = 'notebook:disable-output-scrolling';
111
119
  CommandIDs.selectLastRunCell = 'notebook:select-last-run-cell';
112
120
  CommandIDs.replaceSelection = 'notebook:replace-selection';
113
121
  CommandIDs.autoClosingBrackets = 'notebook:toggle-autoclosing-brackets';
114
- CommandIDs.toggleCollapseCmd = 'Collapsible_Headings:Toggle_Collapse';
115
- CommandIDs.collapseAllCmd = 'Collapsible_Headings:Collapse_All';
116
- CommandIDs.expandAllCmd = 'Collapsible_Headings:Expand_All';
122
+ CommandIDs.toggleCollapseCmd = 'notebook:toggle-heading-collapse';
123
+ CommandIDs.collapseAllCmd = 'notebook:collapse-all-headings';
124
+ CommandIDs.expandAllCmd = 'notebook:expand-all-headings';
117
125
  CommandIDs.copyToClipboard = 'notebook:copy-to-clipboard';
126
+ CommandIDs.invokeCompleter = 'completer:invoke-notebook';
127
+ CommandIDs.selectCompleter = 'completer:select-notebook';
128
+ CommandIDs.tocRunCells = 'toc:run-cells';
118
129
  })(CommandIDs || (CommandIDs = {}));
119
130
  /**
120
131
  * The name of the factory that creates notebooks.
@@ -129,6 +140,10 @@ const FORMAT_EXCLUDE = ['notebook', 'python', 'custom'];
129
140
  * Setting Id storing the customized toolbar definition.
130
141
  */
131
142
  const PANEL_SETTINGS = '@jupyterlab/notebook-extension:panel';
143
+ /**
144
+ * The id to use on the style tag for the side by side margins.
145
+ */
146
+ const SIDE_BY_SIDE_STYLE_ID = 'jp-NotebookExtension-sideBySideMargins';
132
147
  /**
133
148
  * The notebook widget tracker provider.
134
149
  */
@@ -299,6 +314,9 @@ export const exportPlugin = {
299
314
  };
300
315
  commands.addCommand(CommandIDs.exportToFormat, {
301
316
  label: args => {
317
+ if (args.label === undefined) {
318
+ return trans.__('Save and Export Notebook to the given `format`.');
319
+ }
302
320
  const formatLabel = args['label'];
303
321
  return args['isPalette']
304
322
  ? trans.__('Save and Export Notebook: %1', formatLabel)
@@ -446,11 +464,85 @@ const codeConsolePlugin = {
446
464
  * A plugin to copy CodeCell outputs.
447
465
  */
448
466
  const copyOutputPlugin = {
449
- id: '@jupyterlab/notebook-extensions:copy-output',
467
+ id: '@jupyterlab/notebook-extension:copy-output',
450
468
  activate: activateCopyOutput,
451
469
  requires: [ITranslator, INotebookTracker],
452
470
  autoStart: true
453
471
  };
472
+ /**
473
+ * Kernel status indicator.
474
+ */
475
+ const kernelStatus = {
476
+ id: '@jupyterlab/notebook-extension:kernel-status',
477
+ activate: (app, tracker, kernelStatus) => {
478
+ const provider = (widget) => {
479
+ let session = null;
480
+ if (widget && tracker.has(widget)) {
481
+ return widget.sessionContext;
482
+ }
483
+ return session;
484
+ };
485
+ kernelStatus.addSessionProvider(provider);
486
+ },
487
+ requires: [INotebookTracker, IKernelStatusModel],
488
+ autoStart: true
489
+ };
490
+ /**
491
+ * Cursor position.
492
+ */
493
+ const lineColStatus = {
494
+ id: '@jupyterlab/notebook-extension:cursor-position',
495
+ activate: (app, tracker, positionModel) => {
496
+ let previousWidget = null;
497
+ const provider = (widget) => {
498
+ var _a, _b, _c, _d;
499
+ let editor = null;
500
+ if (widget !== previousWidget) {
501
+ previousWidget === null || previousWidget === void 0 ? void 0 : previousWidget.content.activeCellChanged.disconnect(positionModel.update);
502
+ previousWidget = null;
503
+ if (widget && tracker.has(widget)) {
504
+ widget.content.activeCellChanged.connect(positionModel.update);
505
+ editor = (_b = (_a = widget.content.activeCell) === null || _a === void 0 ? void 0 : _a.editor) !== null && _b !== void 0 ? _b : null;
506
+ previousWidget = widget;
507
+ }
508
+ }
509
+ else if (widget) {
510
+ editor = (_d = (_c = widget.content.activeCell) === null || _c === void 0 ? void 0 : _c.editor) !== null && _d !== void 0 ? _d : null;
511
+ }
512
+ return editor;
513
+ };
514
+ positionModel.addEditorProvider(provider);
515
+ },
516
+ requires: [INotebookTracker, IPositionModel],
517
+ autoStart: true
518
+ };
519
+ const completerPlugin = {
520
+ id: '@jupyterlab/notebook-extension:completer',
521
+ requires: [INotebookTracker],
522
+ optional: [ICompletionProviderManager, ITranslator],
523
+ activate: activateNotebookCompleterService,
524
+ autoStart: true
525
+ };
526
+ /**
527
+ * A plugin to search notebook documents
528
+ */
529
+ const searchProvider = {
530
+ id: '@jupyterlab/notebook-extension:search',
531
+ requires: [ISearchProviderRegistry],
532
+ autoStart: true,
533
+ activate: (app, registry) => {
534
+ registry.add('jp-notebookSearchProvider', NotebookSearchProvider);
535
+ }
536
+ };
537
+ const tocPlugin = {
538
+ id: '@jupyterlab/notebook-extension:toc',
539
+ requires: [INotebookTracker, ITableOfContentsRegistry, ISanitizer],
540
+ optional: [IMarkdownParser],
541
+ autoStart: true,
542
+ activate: (app, tracker, tocRegistry, sanitizer, mdParser) => {
543
+ tocRegistry.add(new NotebookToCFactory(tracker, mdParser, sanitizer));
544
+ }
545
+ };
454
546
  /**
455
547
  * Export the plugins as default.
456
548
  */
@@ -466,7 +558,12 @@ const plugins = [
466
558
  logNotebookOutput,
467
559
  clonedOutputsPlugin,
468
560
  codeConsolePlugin,
469
- copyOutputPlugin
561
+ copyOutputPlugin,
562
+ kernelStatus,
563
+ lineColStatus,
564
+ completerPlugin,
565
+ searchProvider,
566
+ tocPlugin
470
567
  ];
471
568
  export default plugins;
472
569
  /**
@@ -479,6 +576,7 @@ function activateNotebookTools(app, tracker, editorServices, state, translator,
479
576
  const activeCellTool = new NotebookTools.ActiveCellTool();
480
577
  const editable = NotebookTools.createEditableToggle(translator);
481
578
  const slideShow = NotebookTools.createSlideShowSelector(translator);
579
+ const tocBaseNumbering = NotebookTools.createToCBaseNumbering(translator);
482
580
  const editorFactory = editorServices.factoryService.newInlineEditor;
483
581
  const cellMetadataEditor = new NotebookTools.CellMetadataEditorTool({
484
582
  editorFactory,
@@ -548,6 +646,7 @@ function activateNotebookTools(app, tracker, editorServices, state, translator,
548
646
  notebookTools.addItem({ tool: activeCellTool, section: 'common', rank: 1 });
549
647
  notebookTools.addItem({ tool: editable, section: 'common', rank: 2 });
550
648
  notebookTools.addItem({ tool: slideShow, section: 'common', rank: 3 });
649
+ notebookTools.addItem({ tool: tocBaseNumbering, section: 'common', rank: 4 });
551
650
  notebookTools.addItem({
552
651
  tool: cellMetadataEditor,
553
652
  section: 'advanced',
@@ -571,13 +670,16 @@ function activateNotebookTools(app, tracker, editorServices, state, translator,
571
670
  * Activate the notebook widget factory.
572
671
  */
573
672
  function activateWidgetFactory(app, contentFactory, editorServices, rendermime, sessionContextDialogs, toolbarRegistry, translator, settingRegistry) {
673
+ const preferKernelOption = PageConfig.getOption('notebookStartsKernel');
674
+ // If the option is not set, assume `true`
675
+ const preferKernelValue = preferKernelOption === '' || preferKernelOption.toLowerCase() === 'true';
574
676
  const { commands } = app;
575
677
  let toolbarFactory;
576
678
  // Register notebook toolbar widgets
577
- toolbarRegistry.registerFactory(FACTORY, 'save', panel => DocToolbarItems.createSaveButton(commands, panel.context.fileChanged));
578
- toolbarRegistry.registerFactory(FACTORY, 'cellType', panel => ToolbarItems.createCellTypeItem(panel, translator));
579
- toolbarRegistry.registerFactory(FACTORY, 'kernelName', panel => Toolbar.createKernelNameItem(panel.sessionContext, sessionContextDialogs, translator));
580
- toolbarRegistry.registerFactory(FACTORY, 'executionProgress', panel => {
679
+ toolbarRegistry.addFactory(FACTORY, 'save', panel => DocToolbarItems.createSaveButton(commands, panel.context.fileChanged));
680
+ toolbarRegistry.addFactory(FACTORY, 'cellType', panel => ToolbarItems.createCellTypeItem(panel, translator));
681
+ toolbarRegistry.addFactory(FACTORY, 'kernelName', panel => Toolbar.createKernelNameItem(panel.sessionContext, sessionContextDialogs, translator));
682
+ toolbarRegistry.addFactory(FACTORY, 'executionProgress', panel => {
581
683
  return ExecutionIndicator.createExecutionIndicatorItem(panel, translator, settingRegistry === null || settingRegistry === void 0 ? void 0 : settingRegistry.load(trackerPlugin.id));
582
684
  });
583
685
  if (settingRegistry) {
@@ -591,7 +693,7 @@ function activateWidgetFactory(app, contentFactory, editorServices, rendermime,
591
693
  fileTypes: ['notebook'],
592
694
  modelName: 'notebook',
593
695
  defaultFor: ['notebook'],
594
- preferKernel: true,
696
+ preferKernel: preferKernelValue,
595
697
  canStartKernel: true,
596
698
  rendermime,
597
699
  contentFactory,
@@ -629,7 +731,7 @@ function activateClonedOutputs(app, docManager, notebookTracker, translator, res
629
731
  return Private.isEnabledAndSingleSelected(shell, notebookTracker);
630
732
  };
631
733
  commands.addCommand(CommandIDs.createOutputView, {
632
- label: trans.__('Create New View for Output'),
734
+ label: trans.__('Create New View for Cell Output'),
633
735
  execute: async (args) => {
634
736
  var _a;
635
737
  let cell;
@@ -662,7 +764,8 @@ function activateClonedOutputs(app, docManager, notebookTracker, translator, res
662
764
  const widget = new MainAreaWidget({ content });
663
765
  current.context.addSibling(widget, {
664
766
  ref: current.id,
665
- mode: 'split-bottom'
767
+ mode: 'split-bottom',
768
+ type: 'Cloned Output'
666
769
  });
667
770
  const updateCloned = () => {
668
771
  void clonedOutputs.save(widget);
@@ -879,48 +982,48 @@ function activateNotebookHandler(app, factory, translator, palette, browserFacto
879
982
  const fetchSettings = settingRegistry
880
983
  ? settingRegistry.load(trackerPlugin.id)
881
984
  : Promise.reject(new Error(`No setting registry for ${trackerPlugin.id}`));
882
- // Handle state restoration.
883
- if (restorer) {
884
- fetchSettings
885
- .then(settings => {
985
+ fetchSettings
986
+ .then(settings => {
987
+ updateConfig(settings);
988
+ settings.changed.connect(() => {
886
989
  updateConfig(settings);
887
- settings.changed.connect(() => {
888
- updateConfig(settings);
889
- });
890
- commands.addCommand(CommandIDs.autoClosingBrackets, {
891
- execute: args => {
892
- var _a;
893
- const codeConfig = settings.get('codeCellConfig')
894
- .composite;
895
- const markdownConfig = settings.get('markdownCellConfig')
896
- .composite;
897
- const rawConfig = settings.get('rawCellConfig')
898
- .composite;
899
- const anyToggled = codeConfig.autoClosingBrackets ||
900
- markdownConfig.autoClosingBrackets ||
901
- rawConfig.autoClosingBrackets;
902
- const toggled = !!((_a = args['force']) !== null && _a !== void 0 ? _a : !anyToggled);
903
- [
904
- codeConfig.autoClosingBrackets,
905
- markdownConfig.autoClosingBrackets,
906
- rawConfig.autoClosingBrackets
907
- ] = [toggled, toggled, toggled];
908
- void settings.set('codeCellConfig', codeConfig);
909
- void settings.set('markdownCellConfig', markdownConfig);
910
- void settings.set('rawCellConfig', rawConfig);
911
- },
912
- label: trans.__('Auto Close Brackets for All Notebook Cell Types'),
913
- isToggled: () => ['codeCellConfig', 'markdownCellConfig', 'rawCellConfig'].some(x => settings.get(x).composite.autoClosingBrackets)
914
- });
915
- })
916
- .catch((reason) => {
917
- console.warn(reason.message);
918
- updateTracker({
919
- editorConfig: factory.editorConfig,
920
- notebookConfig: factory.notebookConfig,
921
- kernelShutdown: factory.shutdownOnClose
922
- });
923
990
  });
991
+ commands.addCommand(CommandIDs.autoClosingBrackets, {
992
+ execute: args => {
993
+ var _a;
994
+ const codeConfig = settings.get('codeCellConfig')
995
+ .composite;
996
+ const markdownConfig = settings.get('markdownCellConfig')
997
+ .composite;
998
+ const rawConfig = settings.get('rawCellConfig')
999
+ .composite;
1000
+ const anyToggled = codeConfig.autoClosingBrackets ||
1001
+ markdownConfig.autoClosingBrackets ||
1002
+ rawConfig.autoClosingBrackets;
1003
+ const toggled = !!((_a = args['force']) !== null && _a !== void 0 ? _a : !anyToggled);
1004
+ [
1005
+ codeConfig.autoClosingBrackets,
1006
+ markdownConfig.autoClosingBrackets,
1007
+ rawConfig.autoClosingBrackets
1008
+ ] = [toggled, toggled, toggled];
1009
+ void settings.set('codeCellConfig', codeConfig);
1010
+ void settings.set('markdownCellConfig', markdownConfig);
1011
+ void settings.set('rawCellConfig', rawConfig);
1012
+ },
1013
+ label: trans.__('Auto Close Brackets for All Notebook Cell Types'),
1014
+ isToggled: () => ['codeCellConfig', 'markdownCellConfig', 'rawCellConfig'].some(x => settings.get(x).composite.autoClosingBrackets)
1015
+ });
1016
+ })
1017
+ .catch((reason) => {
1018
+ console.warn(reason.message);
1019
+ updateTracker({
1020
+ editorConfig: factory.editorConfig,
1021
+ notebookConfig: factory.notebookConfig,
1022
+ kernelShutdown: factory.shutdownOnClose
1023
+ });
1024
+ });
1025
+ // Handle state restoration.
1026
+ if (restorer) {
924
1027
  void restorer.restore(tracker, {
925
1028
  command: 'docmanager:open',
926
1029
  args: panel => ({ path: panel.context.path, factory: FACTORY }),
@@ -978,19 +1081,32 @@ function activateNotebookHandler(app, factory, translator, palette, browserFacto
978
1081
  recordTiming: settings.get('recordTiming').composite,
979
1082
  numberCellsToRenderDirectly: settings.get('numberCellsToRenderDirectly')
980
1083
  .composite,
1084
+ remainingTimeBeforeRescheduling: settings.get('remainingTimeBeforeRescheduling').composite,
981
1085
  renderCellOnIdle: settings.get('renderCellOnIdle').composite,
982
1086
  observedTopMargin: settings.get('observedTopMargin').composite,
983
1087
  observedBottomMargin: settings.get('observedBottomMargin')
984
1088
  .composite,
985
1089
  maxNumberOutputs: settings.get('maxNumberOutputs').composite,
986
- disableDocumentWideUndoRedo: settings.get('experimentalDisableDocumentWideUndoRedo').composite
1090
+ showEditorForReadOnlyMarkdown: settings.get('showEditorForReadOnlyMarkdown').composite,
1091
+ disableDocumentWideUndoRedo: settings.get('experimentalDisableDocumentWideUndoRedo').composite,
1092
+ renderingLayout: settings.get('renderingLayout').composite,
1093
+ sideBySideLeftMarginOverride: settings.get('sideBySideLeftMarginOverride')
1094
+ .composite,
1095
+ sideBySideRightMarginOverride: settings.get('sideBySideRightMarginOverride').composite
987
1096
  };
1097
+ const sideBySideMarginStyle = `.jp-mod-sideBySide.jp-Notebook .jp-Notebook-cell {
1098
+ margin-left: ${factory.notebookConfig.sideBySideLeftMarginOverride} !important;
1099
+ margin-right: ${factory.notebookConfig.sideBySideRightMarginOverride} !important;`;
1100
+ const sideBySideMarginTag = document.getElementById(SIDE_BY_SIDE_STYLE_ID);
1101
+ if (sideBySideMarginTag) {
1102
+ sideBySideMarginTag.innerText = sideBySideMarginStyle;
1103
+ }
1104
+ else {
1105
+ document.head.insertAdjacentHTML('beforeend', `<style id="${SIDE_BY_SIDE_STYLE_ID}">${sideBySideMarginStyle}}</style>`);
1106
+ }
988
1107
  factory.shutdownOnClose = settings.get('kernelShutdown')
989
1108
  .composite;
990
1109
  modelFactory.disableDocumentWideUndoRedo = settings.get('experimentalDisableDocumentWideUndoRedo').composite;
991
- Private.renderSideBySide = !settings.get('sideBySideRendering')
992
- .composite;
993
- commands.execute(CommandIDs.toggleRenderSideBySide);
994
1110
  updateTracker({
995
1111
  editorConfig: factory.editorConfig,
996
1112
  notebookConfig: factory.notebookConfig,
@@ -1073,6 +1189,71 @@ function activateNotebookHandler(app, factory, translator, palette, browserFacto
1073
1189
  }
1074
1190
  return tracker;
1075
1191
  }
1192
+ /**
1193
+ * Activate the completer service for notebook.
1194
+ */
1195
+ function activateNotebookCompleterService(app, notebooks, manager, translator) {
1196
+ if (!manager) {
1197
+ return;
1198
+ }
1199
+ const trans = (translator !== null && translator !== void 0 ? translator : nullTranslator).load('jupyterlab');
1200
+ app.commands.addCommand(CommandIDs.invokeCompleter, {
1201
+ label: trans.__('Display the completion helper.'),
1202
+ execute: args => {
1203
+ var _a;
1204
+ const panel = notebooks.currentWidget;
1205
+ if (panel && ((_a = panel.content.activeCell) === null || _a === void 0 ? void 0 : _a.model.type) === 'code') {
1206
+ manager.invoke(panel.id);
1207
+ }
1208
+ }
1209
+ });
1210
+ app.commands.addCommand(CommandIDs.selectCompleter, {
1211
+ label: trans.__('Select the completion suggestion.'),
1212
+ execute: () => {
1213
+ const id = notebooks.currentWidget && notebooks.currentWidget.id;
1214
+ if (id) {
1215
+ return manager.select(id);
1216
+ }
1217
+ }
1218
+ });
1219
+ app.commands.addKeyBinding({
1220
+ command: CommandIDs.selectCompleter,
1221
+ keys: ['Enter'],
1222
+ selector: '.jp-Notebook .jp-mod-completer-active'
1223
+ });
1224
+ const updateCompleter = async (_, notebook) => {
1225
+ var _a, _b;
1226
+ const completerContext = {
1227
+ editor: (_b = (_a = notebook.content.activeCell) === null || _a === void 0 ? void 0 : _a.editor) !== null && _b !== void 0 ? _b : null,
1228
+ session: notebook.sessionContext.session,
1229
+ widget: notebook
1230
+ };
1231
+ await manager.updateCompleter(completerContext);
1232
+ notebook.content.activeCellChanged.connect((_, cell) => {
1233
+ const newCompleterContext = {
1234
+ editor: cell.editor,
1235
+ session: notebook.sessionContext.session,
1236
+ widget: notebook
1237
+ };
1238
+ manager.updateCompleter(newCompleterContext).catch(console.error);
1239
+ });
1240
+ notebook.sessionContext.sessionChanged.connect(() => {
1241
+ var _a, _b;
1242
+ const newCompleterContext = {
1243
+ editor: (_b = (_a = notebook.content.activeCell) === null || _a === void 0 ? void 0 : _a.editor) !== null && _b !== void 0 ? _b : null,
1244
+ session: notebook.sessionContext.session,
1245
+ widget: notebook
1246
+ };
1247
+ manager.updateCompleter(newCompleterContext).catch(console.error);
1248
+ });
1249
+ };
1250
+ notebooks.widgetAdded.connect(updateCompleter);
1251
+ manager.activeProvidersChanged.connect(() => {
1252
+ notebooks.forEach(panel => {
1253
+ updateCompleter(undefined, panel).catch(e => console.error(e));
1254
+ });
1255
+ });
1256
+ }
1076
1257
  // Get the current widget and activate unless the args specify otherwise.
1077
1258
  function getCurrent(tracker, shell, args) {
1078
1259
  const widget = tracker.currentWidget;
@@ -1266,7 +1447,8 @@ function addCommands(app, tracker, translator, sessionDialogs, isEnabled) {
1266
1447
  isEnabled
1267
1448
  });
1268
1449
  commands.addCommand(CommandIDs.restartClear, {
1269
- label: trans.__('Restart Kernel and Clear All Outputs…'),
1450
+ label: trans.__('Restart Kernel and Clear Outputs of All Cells…'),
1451
+ caption: trans.__('Restart the kernel and clear all outputs of all cells'),
1270
1452
  execute: async () => {
1271
1453
  const restarted = await commands.execute(CommandIDs.restart, {
1272
1454
  activate: false
@@ -1305,7 +1487,8 @@ function addCommands(app, tracker, translator, sessionDialogs, isEnabled) {
1305
1487
  isEnabled
1306
1488
  });
1307
1489
  commands.addCommand(CommandIDs.clearAllOutputs, {
1308
- label: trans.__('Clear All Outputs'),
1490
+ label: trans.__('Clear Outputs of All Cells'),
1491
+ caption: trans.__('Clear all outputs of all cells'),
1309
1492
  execute: args => {
1310
1493
  const current = getCurrent(tracker, shell, args);
1311
1494
  if (current) {
@@ -1315,7 +1498,7 @@ function addCommands(app, tracker, translator, sessionDialogs, isEnabled) {
1315
1498
  isEnabled
1316
1499
  });
1317
1500
  commands.addCommand(CommandIDs.clearOutputs, {
1318
- label: trans.__('Clear Outputs'),
1501
+ label: trans.__('Clear Cell Output'),
1319
1502
  caption: trans.__('Clear outputs for the selected cells'),
1320
1503
  execute: args => {
1321
1504
  const current = getCurrent(tracker, shell, args);
@@ -1416,6 +1599,18 @@ function addCommands(app, tracker, translator, sessionDialogs, isEnabled) {
1416
1599
  },
1417
1600
  isEnabled
1418
1601
  });
1602
+ commands.addCommand(CommandIDs.duplicateBelow, {
1603
+ label: trans.__('Duplicate Cells Below'),
1604
+ caption: trans.__('Copy the selected cells and paste them below the selection'),
1605
+ execute: args => {
1606
+ const current = getCurrent(tracker, shell, args);
1607
+ if (current) {
1608
+ NotebookActions.duplicate(current.content, 'belowSelected');
1609
+ }
1610
+ },
1611
+ icon: args => (args.toolbar ? duplicateIcon : ''),
1612
+ isEnabled
1613
+ });
1419
1614
  commands.addCommand(CommandIDs.pasteAndReplace, {
1420
1615
  label: trans.__('Paste Cells and Replace'),
1421
1616
  execute: args => {
@@ -1484,6 +1679,7 @@ function addCommands(app, tracker, translator, sessionDialogs, isEnabled) {
1484
1679
  return NotebookActions.insertAbove(current.content);
1485
1680
  }
1486
1681
  },
1682
+ icon: args => (args.toolbar ? addAboveIcon : undefined),
1487
1683
  isEnabled
1488
1684
  });
1489
1685
  commands.addCommand(CommandIDs.insertBelow, {
@@ -1495,7 +1691,7 @@ function addCommands(app, tracker, translator, sessionDialogs, isEnabled) {
1495
1691
  return NotebookActions.insertBelow(current.content);
1496
1692
  }
1497
1693
  },
1498
- icon: args => (args.toolbar ? addIcon : undefined),
1694
+ icon: args => (args.toolbar ? addBelowIcon : undefined),
1499
1695
  isEnabled
1500
1696
  });
1501
1697
  commands.addCommand(CommandIDs.selectAbove, {
@@ -1518,6 +1714,46 @@ function addCommands(app, tracker, translator, sessionDialogs, isEnabled) {
1518
1714
  },
1519
1715
  isEnabled
1520
1716
  });
1717
+ commands.addCommand(CommandIDs.insertHeadingAbove, {
1718
+ label: trans.__('Insert Heading Above Current Heading'),
1719
+ execute: args => {
1720
+ const current = getCurrent(tracker, shell, args);
1721
+ if (current) {
1722
+ return NotebookActions.insertSameLevelHeadingAbove(current.content);
1723
+ }
1724
+ },
1725
+ isEnabled
1726
+ });
1727
+ commands.addCommand(CommandIDs.insertHeadingBelow, {
1728
+ label: trans.__('Insert Heading Below Current Heading'),
1729
+ execute: args => {
1730
+ const current = getCurrent(tracker, shell, args);
1731
+ if (current) {
1732
+ return NotebookActions.insertSameLevelHeadingBelow(current.content);
1733
+ }
1734
+ },
1735
+ isEnabled
1736
+ });
1737
+ commands.addCommand(CommandIDs.selectHeadingAboveOrCollapse, {
1738
+ label: trans.__('Select Heading Above or Collapse Heading'),
1739
+ execute: args => {
1740
+ const current = getCurrent(tracker, shell, args);
1741
+ if (current) {
1742
+ return NotebookActions.selectHeadingAboveOrCollapseHeading(current.content);
1743
+ }
1744
+ },
1745
+ isEnabled
1746
+ });
1747
+ commands.addCommand(CommandIDs.selectHeadingBelowOrExpand, {
1748
+ label: trans.__('Select Heading Below or Expand Heading'),
1749
+ execute: args => {
1750
+ const current = getCurrent(tracker, shell, args);
1751
+ if (current) {
1752
+ return NotebookActions.selectHeadingBelowOrExpandHeading(current.content);
1753
+ }
1754
+ },
1755
+ isEnabled
1756
+ });
1521
1757
  commands.addCommand(CommandIDs.extendAbove, {
1522
1758
  label: trans.__('Extend Selection Above'),
1523
1759
  execute: args => {
@@ -1586,7 +1822,8 @@ function addCommands(app, tracker, translator, sessionDialogs, isEnabled) {
1586
1822
  return NotebookActions.moveUp(current.content);
1587
1823
  }
1588
1824
  },
1589
- isEnabled
1825
+ isEnabled,
1826
+ icon: args => (args.toolbar ? moveUpIcon : undefined)
1590
1827
  });
1591
1828
  commands.addCommand(CommandIDs.moveDown, {
1592
1829
  label: trans.__('Move Cells Down'),
@@ -1596,7 +1833,8 @@ function addCommands(app, tracker, translator, sessionDialogs, isEnabled) {
1596
1833
  return NotebookActions.moveDown(current.content);
1597
1834
  }
1598
1835
  },
1599
- isEnabled
1836
+ isEnabled,
1837
+ icon: args => (args.toolbar ? moveDownIcon : undefined)
1600
1838
  });
1601
1839
  commands.addCommand(CommandIDs.toggleAllLines, {
1602
1840
  label: trans.__('Show Line Numbers'),
@@ -1846,26 +2084,27 @@ function addCommands(app, tracker, translator, sessionDialogs, isEnabled) {
1846
2084
  },
1847
2085
  isEnabled
1848
2086
  });
1849
- commands.addCommand(CommandIDs.toggleRenderSideBySide, {
1850
- label: trans.__('Render Side-by-side'),
2087
+ commands.addCommand(CommandIDs.toggleRenderSideBySideCurrentNotebook, {
2088
+ label: trans.__('Render Side-by-Side'),
1851
2089
  execute: args => {
1852
- Private.renderSideBySide = !Private.renderSideBySide;
1853
- tracker.forEach(widget => {
1854
- if (widget) {
1855
- if (Private.renderSideBySide) {
1856
- return NotebookActions.renderSideBySide(widget.content);
1857
- }
1858
- return NotebookActions.renderNotSideBySide(widget.content);
1859
- }
1860
- });
1861
- tracker.currentChanged.connect(() => {
1862
- if (Private.renderSideBySide && tracker.currentWidget) {
1863
- return NotebookActions.renderSideBySide(tracker.currentWidget.content);
2090
+ const current = getCurrent(tracker, shell, args);
2091
+ if (current) {
2092
+ if (current.content.renderingLayout === 'side-by-side') {
2093
+ return NotebookActions.renderDefault(current.content);
1864
2094
  }
1865
- });
2095
+ return NotebookActions.renderSideBySide(current.content);
2096
+ }
1866
2097
  },
1867
- isToggled: () => Private.renderSideBySide,
1868
- isEnabled
2098
+ isEnabled,
2099
+ isToggled: args => {
2100
+ const current = getCurrent(tracker, shell, Object.assign(Object.assign({}, args), { activate: false }));
2101
+ if (current) {
2102
+ return current.content.renderingLayout === 'side-by-side';
2103
+ }
2104
+ else {
2105
+ return false;
2106
+ }
2107
+ }
1869
2108
  });
1870
2109
  commands.addCommand(CommandIDs.setSideBySideRatio, {
1871
2110
  label: trans.__('Set side-by-side ratio'),
@@ -1934,7 +2173,7 @@ function addCommands(app, tracker, translator, sessionDialogs, isEnabled) {
1934
2173
  isEnabled
1935
2174
  });
1936
2175
  commands.addCommand(CommandIDs.toggleCollapseCmd, {
1937
- label: 'Toggle Collapse Notebook Heading',
2176
+ label: trans.__('Toggle Collapse Notebook Heading'),
1938
2177
  execute: args => {
1939
2178
  const current = getCurrent(tracker, shell, args);
1940
2179
  if (current) {
@@ -1944,16 +2183,16 @@ function addCommands(app, tracker, translator, sessionDialogs, isEnabled) {
1944
2183
  isEnabled: isEnabledAndHeadingSelected
1945
2184
  });
1946
2185
  commands.addCommand(CommandIDs.collapseAllCmd, {
1947
- label: 'Collapse All Cells',
2186
+ label: trans.__('Collapse All Headings'),
1948
2187
  execute: args => {
1949
2188
  const current = getCurrent(tracker, shell, args);
1950
2189
  if (current) {
1951
- return NotebookActions.collapseAll(current.content);
2190
+ return NotebookActions.collapseAllHeadings(current.content);
1952
2191
  }
1953
2192
  }
1954
2193
  });
1955
2194
  commands.addCommand(CommandIDs.expandAllCmd, {
1956
- label: 'Expand All Headings',
2195
+ label: trans.__('Expand All Headings'),
1957
2196
  execute: args => {
1958
2197
  const current = getCurrent(tracker, shell, args);
1959
2198
  if (current) {
@@ -1961,6 +2200,33 @@ function addCommands(app, tracker, translator, sessionDialogs, isEnabled) {
1961
2200
  }
1962
2201
  }
1963
2202
  });
2203
+ commands.addCommand(CommandIDs.tocRunCells, {
2204
+ label: trans.__('Select and Run Cell(s) for this Heading'),
2205
+ execute: args => {
2206
+ const current = getCurrent(tracker, shell, Object.assign({ activate: false }, args));
2207
+ if (current === null) {
2208
+ return;
2209
+ }
2210
+ const activeCell = current.content.activeCell;
2211
+ let lastIndex = current.content.activeCellIndex;
2212
+ if (activeCell instanceof MarkdownCell) {
2213
+ const cells = current.content.widgets;
2214
+ const level = activeCell.headingInfo.level;
2215
+ for (let i = current.content.activeCellIndex + 1; i < cells.length; i++) {
2216
+ const cell = cells[i];
2217
+ if (cell instanceof MarkdownCell &&
2218
+ // cell.headingInfo.level === -1 if no heading
2219
+ cell.headingInfo.level >= 0 &&
2220
+ cell.headingInfo.level <= level) {
2221
+ break;
2222
+ }
2223
+ lastIndex = i;
2224
+ }
2225
+ }
2226
+ current.content.extendContiguousSelectionTo(lastIndex);
2227
+ NotebookActions.run(current.content, current.sessionContext);
2228
+ }
2229
+ });
1964
2230
  }
1965
2231
  /**
1966
2232
  * Populate the application's command palette with notebook commands.
@@ -2024,6 +2290,10 @@ function populatePalette(palette, translator) {
2024
2290
  CommandIDs.insertBelow,
2025
2291
  CommandIDs.selectAbove,
2026
2292
  CommandIDs.selectBelow,
2293
+ CommandIDs.selectHeadingAboveOrCollapse,
2294
+ CommandIDs.selectHeadingBelowOrExpand,
2295
+ CommandIDs.insertHeadingAbove,
2296
+ CommandIDs.insertHeadingBelow,
2027
2297
  CommandIDs.extendAbove,
2028
2298
  CommandIDs.extendTop,
2029
2299
  CommandIDs.extendBelow,
@@ -2046,7 +2316,7 @@ function populatePalette(palette, translator) {
2046
2316
  CommandIDs.showOutput,
2047
2317
  CommandIDs.hideAllOutputs,
2048
2318
  CommandIDs.showAllOutputs,
2049
- CommandIDs.toggleRenderSideBySide,
2319
+ CommandIDs.toggleRenderSideBySideCurrentNotebook,
2050
2320
  CommandIDs.setSideBySideRatio,
2051
2321
  CommandIDs.enableOutputScrolling,
2052
2322
  CommandIDs.disableOutputScrolling
@@ -2151,7 +2421,8 @@ var Private;
2151
2421
  preferredLanguage: widget.context.model.defaultKernelLanguage,
2152
2422
  activate: activate,
2153
2423
  ref: widget.id,
2154
- insertMode: 'split-bottom'
2424
+ insertMode: 'split-bottom',
2425
+ type: 'Linked Console'
2155
2426
  };
2156
2427
  return commands.execute('console:create', options);
2157
2428
  }
@@ -2270,6 +2541,5 @@ var Private;
2270
2541
  }
2271
2542
  }
2272
2543
  Private.ClonedOutputArea = ClonedOutputArea;
2273
- Private.renderSideBySide = false;
2274
2544
  })(Private || (Private = {}));
2275
2545
  //# sourceMappingURL=index.js.map