Browse Source

Revert "Don’t activate the notebook widget when getting it as the current widget."

This reverts commit ed11dc9960bac0f3bd2f2870a3e6865d82cdb6c4.

Changing the behavior of getting the current widget this close to release is an risky thing. We can take a look at it after the release to more thoroughly examine the ramifications.
Jason Grout 6 years ago
parent
commit
895a566eec
1 changed files with 71 additions and 67 deletions
  1. 71 67
      packages/notebook-extension/src/index.ts

+ 71 - 67
packages/notebook-extension/src/index.ts

@@ -690,12 +690,16 @@ function activateNotebookHandler(app: JupyterLab, mainMenu: IMainMenu, palette:
 function addCommands(app: JupyterLab, services: ServiceManager, tracker: NotebookTracker): void {
 function addCommands(app: JupyterLab, services: ServiceManager, tracker: NotebookTracker): void {
   const { commands, shell } = app;
   const { commands, shell } = app;
 
 
-  /**
-   * Get the current NotebookPanel widget
-   */
   // Get the current widget and activate unless the args specify otherwise.
   // Get the current widget and activate unless the args specify otherwise.
-  function getCurrent(): NotebookPanel | null {
-    return tracker.currentWidget;
+  function getCurrent(args: ReadonlyJSONObject): NotebookPanel | null {
+    const widget = tracker.currentWidget;
+    const activate = args['activate'] !== false;
+
+    if (activate && widget) {
+      shell.activateById(widget.id);
+    }
+
+    return widget;
   }
   }
 
 
   /**
   /**
@@ -726,7 +730,7 @@ function addCommands(app: JupyterLab, services: ServiceManager, tracker: Noteboo
   commands.addCommand(CommandIDs.runAndAdvance, {
   commands.addCommand(CommandIDs.runAndAdvance, {
     label: 'Run Selected Cells',
     label: 'Run Selected Cells',
     execute: args => {
     execute: args => {
-      const current = getCurrent();
+      const current = getCurrent(args);
 
 
       if (current) {
       if (current) {
         const { context, content } = current;
         const { context, content } = current;
@@ -739,7 +743,7 @@ function addCommands(app: JupyterLab, services: ServiceManager, tracker: Noteboo
   commands.addCommand(CommandIDs.run, {
   commands.addCommand(CommandIDs.run, {
     label: 'Run Selected Cells and Don\'t Advance',
     label: 'Run Selected Cells and Don\'t Advance',
     execute: args => {
     execute: args => {
-      const current = getCurrent();
+      const current = getCurrent(args);
 
 
       if (current) {
       if (current) {
         const { context, content } = current;
         const { context, content } = current;
@@ -752,7 +756,7 @@ function addCommands(app: JupyterLab, services: ServiceManager, tracker: Noteboo
   commands.addCommand(CommandIDs.runAndInsert, {
   commands.addCommand(CommandIDs.runAndInsert, {
     label: 'Run Selected Cells and Insert Below',
     label: 'Run Selected Cells and Insert Below',
     execute: args => {
     execute: args => {
-      const current = getCurrent();
+      const current = getCurrent(args);
 
 
       if (current) {
       if (current) {
         const { context, content } = current;
         const { context, content } = current;
@@ -765,7 +769,7 @@ function addCommands(app: JupyterLab, services: ServiceManager, tracker: Noteboo
   commands.addCommand(CommandIDs.runInConsole, {
   commands.addCommand(CommandIDs.runInConsole, {
     label: 'Run Selected Text or Current Line in Console',
     label: 'Run Selected Text or Current Line in Console',
     execute: args => {
     execute: args => {
-      const current = getCurrent();
+      const current = getCurrent(args);
 
 
       if (current) {
       if (current) {
         const { context, content } = current;
         const { context, content } = current;
@@ -823,7 +827,7 @@ function addCommands(app: JupyterLab, services: ServiceManager, tracker: Noteboo
   commands.addCommand(CommandIDs.runAll, {
   commands.addCommand(CommandIDs.runAll, {
     label: 'Run All Cells',
     label: 'Run All Cells',
     execute: args => {
     execute: args => {
-      const current = getCurrent();
+      const current = getCurrent(args);
 
 
       if (current) {
       if (current) {
         const { context, content } = current;
         const { context, content } = current;
@@ -836,7 +840,7 @@ function addCommands(app: JupyterLab, services: ServiceManager, tracker: Noteboo
   commands.addCommand(CommandIDs.runAllAbove, {
   commands.addCommand(CommandIDs.runAllAbove, {
     label: 'Run All Above Selected Cell',
     label: 'Run All Above Selected Cell',
     execute: args => {
     execute: args => {
-      const current = getCurrent();
+      const current = getCurrent(args);
 
 
       if (current) {
       if (current) {
         const { context, content } = current;
         const { context, content } = current;
@@ -854,7 +858,7 @@ function addCommands(app: JupyterLab, services: ServiceManager, tracker: Noteboo
   commands.addCommand(CommandIDs.runAllBelow, {
   commands.addCommand(CommandIDs.runAllBelow, {
     label: 'Run Selected Cell and All Below',
     label: 'Run Selected Cell and All Below',
     execute: args => {
     execute: args => {
-      const current = getCurrent();
+      const current = getCurrent(args);
 
 
       if (current) {
       if (current) {
         const { context, content } = current;
         const { context, content } = current;
@@ -873,7 +877,7 @@ function addCommands(app: JupyterLab, services: ServiceManager, tracker: Noteboo
   commands.addCommand(CommandIDs.restart, {
   commands.addCommand(CommandIDs.restart, {
     label: 'Restart Kernel…',
     label: 'Restart Kernel…',
     execute: args => {
     execute: args => {
-      const current = getCurrent();
+      const current = getCurrent(args);
 
 
       if (current) {
       if (current) {
         return current.session.restart();
         return current.session.restart();
@@ -884,7 +888,7 @@ function addCommands(app: JupyterLab, services: ServiceManager, tracker: Noteboo
   commands.addCommand(CommandIDs.closeAndShutdown, {
   commands.addCommand(CommandIDs.closeAndShutdown, {
     label: 'Close and Shutdown',
     label: 'Close and Shutdown',
     execute: args => {
     execute: args => {
-      const current = getCurrent();
+      const current = getCurrent(args);
 
 
       if (!current) {
       if (!current) {
         return;
         return;
@@ -908,7 +912,7 @@ function addCommands(app: JupyterLab, services: ServiceManager, tracker: Noteboo
   commands.addCommand(CommandIDs.trust, {
   commands.addCommand(CommandIDs.trust, {
     label: () => 'Trust Notebook',
     label: () => 'Trust Notebook',
     execute: args => {
     execute: args => {
-      const current = getCurrent();
+      const current = getCurrent(args);
 
 
       if (current) {
       if (current) {
         const { context, content } = current;
         const { context, content } = current;
@@ -925,7 +929,7 @@ function addCommands(app: JupyterLab, services: ServiceManager, tracker: Noteboo
         return (args['isPalette'] ? 'Export Notebook to ' : '') + formatLabel;
         return (args['isPalette'] ? 'Export Notebook to ' : '') + formatLabel;
     },
     },
     execute: args => {
     execute: args => {
-      const current = getCurrent();
+      const current = getCurrent(args);
 
 
       if (!current) {
       if (!current) {
         return;
         return;
@@ -955,7 +959,7 @@ function addCommands(app: JupyterLab, services: ServiceManager, tracker: Noteboo
   commands.addCommand(CommandIDs.restartClear, {
   commands.addCommand(CommandIDs.restartClear, {
     label: 'Restart Kernel and Clear All Outputs…',
     label: 'Restart Kernel and Clear All Outputs…',
     execute: args => {
     execute: args => {
-      const current = getCurrent();
+      const current = getCurrent(args);
 
 
       if (current) {
       if (current) {
         const { content, session } = current;
         const { content, session } = current;
@@ -969,7 +973,7 @@ function addCommands(app: JupyterLab, services: ServiceManager, tracker: Noteboo
   commands.addCommand(CommandIDs.restartRunAll, {
   commands.addCommand(CommandIDs.restartRunAll, {
     label: 'Restart Kernel and Run All Cells…',
     label: 'Restart Kernel and Run All Cells…',
     execute: args => {
     execute: args => {
-      const current = getCurrent();
+      const current = getCurrent(args);
 
 
       if (current) {
       if (current) {
         const { context, content, session } = current;
         const { context, content, session } = current;
@@ -987,7 +991,7 @@ function addCommands(app: JupyterLab, services: ServiceManager, tracker: Noteboo
   commands.addCommand(CommandIDs.clearAllOutputs, {
   commands.addCommand(CommandIDs.clearAllOutputs, {
     label: 'Clear All Outputs',
     label: 'Clear All Outputs',
     execute: args => {
     execute: args => {
-      const current = getCurrent();
+      const current = getCurrent(args);
 
 
       if (current) {
       if (current) {
         return NotebookActions.clearAllOutputs(current.content);
         return NotebookActions.clearAllOutputs(current.content);
@@ -998,7 +1002,7 @@ function addCommands(app: JupyterLab, services: ServiceManager, tracker: Noteboo
   commands.addCommand(CommandIDs.clearOutputs, {
   commands.addCommand(CommandIDs.clearOutputs, {
     label: 'Clear Outputs',
     label: 'Clear Outputs',
     execute: args => {
     execute: args => {
-      const current = getCurrent();
+      const current = getCurrent(args);
 
 
       if (current) {
       if (current) {
         return NotebookActions.clearOutputs(current.content);
         return NotebookActions.clearOutputs(current.content);
@@ -1009,7 +1013,7 @@ function addCommands(app: JupyterLab, services: ServiceManager, tracker: Noteboo
   commands.addCommand(CommandIDs.interrupt, {
   commands.addCommand(CommandIDs.interrupt, {
     label: 'Interrupt Kernel',
     label: 'Interrupt Kernel',
     execute: args => {
     execute: args => {
-      const current = getCurrent();
+      const current = getCurrent(args);
 
 
       if (!current) {
       if (!current) {
         return;
         return;
@@ -1026,7 +1030,7 @@ function addCommands(app: JupyterLab, services: ServiceManager, tracker: Noteboo
   commands.addCommand(CommandIDs.toCode, {
   commands.addCommand(CommandIDs.toCode, {
     label: 'Change to Code Cell Type',
     label: 'Change to Code Cell Type',
     execute: args => {
     execute: args => {
-      const current = getCurrent({ activate: !!args['activate'] });
+      const current = getCurrent(args);
 
 
       if (current) {
       if (current) {
         return NotebookActions.changeCellType(current.content, 'code');
         return NotebookActions.changeCellType(current.content, 'code');
@@ -1037,7 +1041,7 @@ function addCommands(app: JupyterLab, services: ServiceManager, tracker: Noteboo
   commands.addCommand(CommandIDs.toMarkdown, {
   commands.addCommand(CommandIDs.toMarkdown, {
     label: 'Change to Markdown Cell Type',
     label: 'Change to Markdown Cell Type',
     execute: args => {
     execute: args => {
-      const current = getCurrent();
+      const current = getCurrent(args);
 
 
       if (current) {
       if (current) {
         return NotebookActions.changeCellType(current.content, 'markdown');
         return NotebookActions.changeCellType(current.content, 'markdown');
@@ -1048,7 +1052,7 @@ function addCommands(app: JupyterLab, services: ServiceManager, tracker: Noteboo
   commands.addCommand(CommandIDs.toRaw, {
   commands.addCommand(CommandIDs.toRaw, {
     label: 'Change to Raw Cell Type',
     label: 'Change to Raw Cell Type',
     execute: args => {
     execute: args => {
-      const current = getCurrent();
+      const current = getCurrent(args);
 
 
       if (current) {
       if (current) {
         return NotebookActions.changeCellType(current.content, 'raw');
         return NotebookActions.changeCellType(current.content, 'raw');
@@ -1059,7 +1063,7 @@ function addCommands(app: JupyterLab, services: ServiceManager, tracker: Noteboo
   commands.addCommand(CommandIDs.cut, {
   commands.addCommand(CommandIDs.cut, {
     label: 'Cut Cells',
     label: 'Cut Cells',
     execute: args => {
     execute: args => {
-      const current = getCurrent();
+      const current = getCurrent(args);
 
 
       if (current) {
       if (current) {
         return NotebookActions.cut(current.content);
         return NotebookActions.cut(current.content);
@@ -1070,7 +1074,7 @@ function addCommands(app: JupyterLab, services: ServiceManager, tracker: Noteboo
   commands.addCommand(CommandIDs.copy, {
   commands.addCommand(CommandIDs.copy, {
     label: 'Copy Cells',
     label: 'Copy Cells',
     execute: args => {
     execute: args => {
-      const current = getCurrent();
+      const current = getCurrent(args);
 
 
       if (current) {
       if (current) {
         return NotebookActions.copy(current.content);
         return NotebookActions.copy(current.content);
@@ -1081,7 +1085,7 @@ function addCommands(app: JupyterLab, services: ServiceManager, tracker: Noteboo
   commands.addCommand(CommandIDs.pasteBelow, {
   commands.addCommand(CommandIDs.pasteBelow, {
     label: 'Paste Cells Below',
     label: 'Paste Cells Below',
     execute: args => {
     execute: args => {
-      const current = getCurrent();
+      const current = getCurrent(args);
 
 
       if (current) {
       if (current) {
         return NotebookActions.paste(current.content, 'below');
         return NotebookActions.paste(current.content, 'below');
@@ -1092,7 +1096,7 @@ function addCommands(app: JupyterLab, services: ServiceManager, tracker: Noteboo
   commands.addCommand(CommandIDs.pasteAbove, {
   commands.addCommand(CommandIDs.pasteAbove, {
     label: 'Paste Cells Above',
     label: 'Paste Cells Above',
     execute: args => {
     execute: args => {
-      const current = getCurrent();
+      const current = getCurrent(args);
 
 
       if (current) {
       if (current) {
         return NotebookActions.paste(current.content, 'above');
         return NotebookActions.paste(current.content, 'above');
@@ -1103,7 +1107,7 @@ function addCommands(app: JupyterLab, services: ServiceManager, tracker: Noteboo
   commands.addCommand(CommandIDs.pasteAndReplace, {
   commands.addCommand(CommandIDs.pasteAndReplace, {
     label: 'Paste Cells and Replace',
     label: 'Paste Cells and Replace',
     execute: args => {
     execute: args => {
-      const current = getCurrent();
+      const current = getCurrent(args);
 
 
       if (current) {
       if (current) {
         return NotebookActions.paste(current.content, 'replace');
         return NotebookActions.paste(current.content, 'replace');
@@ -1114,7 +1118,7 @@ function addCommands(app: JupyterLab, services: ServiceManager, tracker: Noteboo
   commands.addCommand(CommandIDs.deleteCell, {
   commands.addCommand(CommandIDs.deleteCell, {
     label: 'Delete Cells',
     label: 'Delete Cells',
     execute: args => {
     execute: args => {
-      const current = getCurrent();
+      const current = getCurrent(args);
 
 
       if (current) {
       if (current) {
         return NotebookActions.deleteCells(current.content);
         return NotebookActions.deleteCells(current.content);
@@ -1125,7 +1129,7 @@ function addCommands(app: JupyterLab, services: ServiceManager, tracker: Noteboo
   commands.addCommand(CommandIDs.split, {
   commands.addCommand(CommandIDs.split, {
     label: 'Split Cell',
     label: 'Split Cell',
     execute: args => {
     execute: args => {
-      const current = getCurrent();
+      const current = getCurrent(args);
 
 
       if (current) {
       if (current) {
         return NotebookActions.splitCell(current.content);
         return NotebookActions.splitCell(current.content);
@@ -1136,7 +1140,7 @@ function addCommands(app: JupyterLab, services: ServiceManager, tracker: Noteboo
   commands.addCommand(CommandIDs.merge, {
   commands.addCommand(CommandIDs.merge, {
     label: 'Merge Selected Cells',
     label: 'Merge Selected Cells',
     execute: args => {
     execute: args => {
-      const current = getCurrent();
+      const current = getCurrent(args);
 
 
       if (current) {
       if (current) {
         return NotebookActions.mergeCells(current.content);
         return NotebookActions.mergeCells(current.content);
@@ -1147,7 +1151,7 @@ function addCommands(app: JupyterLab, services: ServiceManager, tracker: Noteboo
   commands.addCommand(CommandIDs.insertAbove, {
   commands.addCommand(CommandIDs.insertAbove, {
     label: 'Insert Cell Above',
     label: 'Insert Cell Above',
     execute: args => {
     execute: args => {
-      const current = getCurrent();
+      const current = getCurrent(args);
 
 
       if (current) {
       if (current) {
         return NotebookActions.insertAbove(current.content);
         return NotebookActions.insertAbove(current.content);
@@ -1158,7 +1162,7 @@ function addCommands(app: JupyterLab, services: ServiceManager, tracker: Noteboo
   commands.addCommand(CommandIDs.insertBelow, {
   commands.addCommand(CommandIDs.insertBelow, {
     label: 'Insert Cell Below',
     label: 'Insert Cell Below',
     execute: args => {
     execute: args => {
-      const current = getCurrent();
+      const current = getCurrent(args);
 
 
       if (current) {
       if (current) {
         return NotebookActions.insertBelow(current.content);
         return NotebookActions.insertBelow(current.content);
@@ -1169,7 +1173,7 @@ function addCommands(app: JupyterLab, services: ServiceManager, tracker: Noteboo
   commands.addCommand(CommandIDs.selectAbove, {
   commands.addCommand(CommandIDs.selectAbove, {
     label: 'Select Cell Above',
     label: 'Select Cell Above',
     execute: args => {
     execute: args => {
-      const current = getCurrent();
+      const current = getCurrent(args);
 
 
       if (current) {
       if (current) {
         return NotebookActions.selectAbove(current.content);
         return NotebookActions.selectAbove(current.content);
@@ -1180,7 +1184,7 @@ function addCommands(app: JupyterLab, services: ServiceManager, tracker: Noteboo
   commands.addCommand(CommandIDs.selectBelow, {
   commands.addCommand(CommandIDs.selectBelow, {
     label: 'Select Cell Below',
     label: 'Select Cell Below',
     execute: args => {
     execute: args => {
-      const current = getCurrent();
+      const current = getCurrent(args);
 
 
       if (current) {
       if (current) {
         return NotebookActions.selectBelow(current.content);
         return NotebookActions.selectBelow(current.content);
@@ -1191,7 +1195,7 @@ function addCommands(app: JupyterLab, services: ServiceManager, tracker: Noteboo
   commands.addCommand(CommandIDs.extendAbove, {
   commands.addCommand(CommandIDs.extendAbove, {
     label: 'Extend Selection Above',
     label: 'Extend Selection Above',
     execute: args => {
     execute: args => {
-      const current = getCurrent();
+      const current = getCurrent(args);
 
 
       if (current) {
       if (current) {
         return NotebookActions.extendSelectionAbove(current.content);
         return NotebookActions.extendSelectionAbove(current.content);
@@ -1202,7 +1206,7 @@ function addCommands(app: JupyterLab, services: ServiceManager, tracker: Noteboo
   commands.addCommand(CommandIDs.extendBelow, {
   commands.addCommand(CommandIDs.extendBelow, {
     label: 'Extend Selection Below',
     label: 'Extend Selection Below',
     execute: args => {
     execute: args => {
-      const current = getCurrent();
+      const current = getCurrent(args);
 
 
       if (current) {
       if (current) {
         return NotebookActions.extendSelectionBelow(current.content);
         return NotebookActions.extendSelectionBelow(current.content);
@@ -1213,7 +1217,7 @@ function addCommands(app: JupyterLab, services: ServiceManager, tracker: Noteboo
   commands.addCommand(CommandIDs.selectAll, {
   commands.addCommand(CommandIDs.selectAll, {
     label: 'Select All Cells',
     label: 'Select All Cells',
     execute: args => {
     execute: args => {
-      const current = getCurrent();
+      const current = getCurrent(args);
 
 
       if (current) {
       if (current) {
         return NotebookActions.selectAll(current.content);
         return NotebookActions.selectAll(current.content);
@@ -1224,7 +1228,7 @@ function addCommands(app: JupyterLab, services: ServiceManager, tracker: Noteboo
   commands.addCommand(CommandIDs.deselectAll, {
   commands.addCommand(CommandIDs.deselectAll, {
     label: 'Deselect All Cells',
     label: 'Deselect All Cells',
     execute: args => {
     execute: args => {
-      const current = getCurrent();
+      const current = getCurrent(args);
 
 
       if (current) {
       if (current) {
         return NotebookActions.deselectAll(current.content);
         return NotebookActions.deselectAll(current.content);
@@ -1235,7 +1239,7 @@ function addCommands(app: JupyterLab, services: ServiceManager, tracker: Noteboo
   commands.addCommand(CommandIDs.moveUp, {
   commands.addCommand(CommandIDs.moveUp, {
     label: 'Move Cells Up',
     label: 'Move Cells Up',
     execute: args => {
     execute: args => {
-      const current = getCurrent();
+      const current = getCurrent(args);
 
 
       if (current) {
       if (current) {
         return NotebookActions.moveUp(current.content);
         return NotebookActions.moveUp(current.content);
@@ -1246,7 +1250,7 @@ function addCommands(app: JupyterLab, services: ServiceManager, tracker: Noteboo
   commands.addCommand(CommandIDs.moveDown, {
   commands.addCommand(CommandIDs.moveDown, {
     label: 'Move Cells Down',
     label: 'Move Cells Down',
     execute: args => {
     execute: args => {
-      const current = getCurrent();
+      const current = getCurrent(args);
 
 
       if (current) {
       if (current) {
         return NotebookActions.moveDown(current.content);
         return NotebookActions.moveDown(current.content);
@@ -1257,7 +1261,7 @@ function addCommands(app: JupyterLab, services: ServiceManager, tracker: Noteboo
   commands.addCommand(CommandIDs.toggleAllLines, {
   commands.addCommand(CommandIDs.toggleAllLines, {
     label: 'Toggle All Line Numbers',
     label: 'Toggle All Line Numbers',
     execute: args => {
     execute: args => {
-      const current = getCurrent();
+      const current = getCurrent(args);
 
 
       if (current) {
       if (current) {
         return NotebookActions.toggleAllLineNumbers(current.content);
         return NotebookActions.toggleAllLineNumbers(current.content);
@@ -1268,7 +1272,7 @@ function addCommands(app: JupyterLab, services: ServiceManager, tracker: Noteboo
   commands.addCommand(CommandIDs.commandMode, {
   commands.addCommand(CommandIDs.commandMode, {
     label: 'Enter Command Mode',
     label: 'Enter Command Mode',
     execute: args => {
     execute: args => {
-      const current = getCurrent();
+      const current = getCurrent(args);
 
 
       if (current) {
       if (current) {
         current.content.mode = 'command';
         current.content.mode = 'command';
@@ -1279,7 +1283,7 @@ function addCommands(app: JupyterLab, services: ServiceManager, tracker: Noteboo
   commands.addCommand(CommandIDs.editMode, {
   commands.addCommand(CommandIDs.editMode, {
     label: 'Enter Edit Mode',
     label: 'Enter Edit Mode',
     execute: args => {
     execute: args => {
-      const current = getCurrent();
+      const current = getCurrent(args);
 
 
       if (current) {
       if (current) {
         current.content.mode = 'edit';
         current.content.mode = 'edit';
@@ -1290,7 +1294,7 @@ function addCommands(app: JupyterLab, services: ServiceManager, tracker: Noteboo
   commands.addCommand(CommandIDs.undoCellAction, {
   commands.addCommand(CommandIDs.undoCellAction, {
     label: 'Undo Cell Operation',
     label: 'Undo Cell Operation',
     execute: args => {
     execute: args => {
-      const current = getCurrent();
+      const current = getCurrent(args);
 
 
       if (current) {
       if (current) {
         return NotebookActions.undo(current.content);
         return NotebookActions.undo(current.content);
@@ -1301,7 +1305,7 @@ function addCommands(app: JupyterLab, services: ServiceManager, tracker: Noteboo
   commands.addCommand(CommandIDs.redoCellAction, {
   commands.addCommand(CommandIDs.redoCellAction, {
     label: 'Redo Cell Operation',
     label: 'Redo Cell Operation',
     execute: args => {
     execute: args => {
-      const current = getCurrent();
+      const current = getCurrent(args);
 
 
       if (current) {
       if (current) {
         return NotebookActions.redo(current.content);
         return NotebookActions.redo(current.content);
@@ -1312,7 +1316,7 @@ function addCommands(app: JupyterLab, services: ServiceManager, tracker: Noteboo
   commands.addCommand(CommandIDs.changeKernel, {
   commands.addCommand(CommandIDs.changeKernel, {
     label: 'Change Kernel…',
     label: 'Change Kernel…',
     execute: args => {
     execute: args => {
-      const current = getCurrent();
+      const current = getCurrent(args);
 
 
       if (current) {
       if (current) {
         return current.context.session.selectKernel();
         return current.context.session.selectKernel();
@@ -1323,7 +1327,7 @@ function addCommands(app: JupyterLab, services: ServiceManager, tracker: Noteboo
   commands.addCommand(CommandIDs.reconnectToKernel, {
   commands.addCommand(CommandIDs.reconnectToKernel, {
     label: 'Reconnect To Kernel',
     label: 'Reconnect To Kernel',
     execute: args => {
     execute: args => {
-      const current = getCurrent();
+      const current = getCurrent(args);
 
 
       if (!current) {
       if (!current) {
         return;
         return;
@@ -1363,7 +1367,7 @@ function addCommands(app: JupyterLab, services: ServiceManager, tracker: Noteboo
   commands.addCommand(CommandIDs.createConsole, {
   commands.addCommand(CommandIDs.createConsole, {
     label: 'New Console for Notebook',
     label: 'New Console for Notebook',
     execute: args => {
     execute: args => {
-      const current = getCurrent();
+      const current = getCurrent({ ...args, activate: false });
       const widget = tracker.currentWidget;
       const widget = tracker.currentWidget;
 
 
       if (!current || !widget) {
       if (!current || !widget) {
@@ -1385,7 +1389,7 @@ function addCommands(app: JupyterLab, services: ServiceManager, tracker: Noteboo
   commands.addCommand(CommandIDs.markdown1, {
   commands.addCommand(CommandIDs.markdown1, {
     label: 'Change to Heading 1',
     label: 'Change to Heading 1',
     execute: args => {
     execute: args => {
-      const current = getCurrent();
+      const current = getCurrent(args);
 
 
       if (current) {
       if (current) {
         return NotebookActions.setMarkdownHeader(current.content, 1);
         return NotebookActions.setMarkdownHeader(current.content, 1);
@@ -1396,7 +1400,7 @@ function addCommands(app: JupyterLab, services: ServiceManager, tracker: Noteboo
   commands.addCommand(CommandIDs.markdown2, {
   commands.addCommand(CommandIDs.markdown2, {
     label: 'Change to Heading 2',
     label: 'Change to Heading 2',
     execute: args => {
     execute: args => {
-      const current = getCurrent();
+      const current = getCurrent(args);
 
 
       if (current) {
       if (current) {
         return NotebookActions.setMarkdownHeader(current.content, 2);
         return NotebookActions.setMarkdownHeader(current.content, 2);
@@ -1407,7 +1411,7 @@ function addCommands(app: JupyterLab, services: ServiceManager, tracker: Noteboo
   commands.addCommand(CommandIDs.markdown3, {
   commands.addCommand(CommandIDs.markdown3, {
     label: 'Change to Heading 3',
     label: 'Change to Heading 3',
     execute: args => {
     execute: args => {
-      const current = getCurrent();
+      const current = getCurrent(args);
 
 
       if (current) {
       if (current) {
         return NotebookActions.setMarkdownHeader(current.content, 3);
         return NotebookActions.setMarkdownHeader(current.content, 3);
@@ -1418,7 +1422,7 @@ function addCommands(app: JupyterLab, services: ServiceManager, tracker: Noteboo
   commands.addCommand(CommandIDs.markdown4, {
   commands.addCommand(CommandIDs.markdown4, {
     label: 'Change to Heading 4',
     label: 'Change to Heading 4',
     execute: args => {
     execute: args => {
-      const current = getCurrent();
+      const current = getCurrent(args);
 
 
       if (current) {
       if (current) {
         return NotebookActions.setMarkdownHeader(current.content, 4);
         return NotebookActions.setMarkdownHeader(current.content, 4);
@@ -1429,7 +1433,7 @@ function addCommands(app: JupyterLab, services: ServiceManager, tracker: Noteboo
   commands.addCommand(CommandIDs.markdown5, {
   commands.addCommand(CommandIDs.markdown5, {
     label: 'Change to Heading 5',
     label: 'Change to Heading 5',
     execute: args => {
     execute: args => {
-      const current = getCurrent();
+      const current = getCurrent(args);
 
 
       if (current) {
       if (current) {
         return NotebookActions.setMarkdownHeader(current.content, 5);
         return NotebookActions.setMarkdownHeader(current.content, 5);
@@ -1440,7 +1444,7 @@ function addCommands(app: JupyterLab, services: ServiceManager, tracker: Noteboo
   commands.addCommand(CommandIDs.markdown6, {
   commands.addCommand(CommandIDs.markdown6, {
     label: 'Change to Heading 6',
     label: 'Change to Heading 6',
     execute: args => {
     execute: args => {
-      const current = getCurrent();
+      const current = getCurrent(args);
 
 
       if (current) {
       if (current) {
         return NotebookActions.setMarkdownHeader(current.content, 6);
         return NotebookActions.setMarkdownHeader(current.content, 6);
@@ -1451,7 +1455,7 @@ function addCommands(app: JupyterLab, services: ServiceManager, tracker: Noteboo
   commands.addCommand(CommandIDs.hideCode, {
   commands.addCommand(CommandIDs.hideCode, {
     label: 'Collapse Selected Code',
     label: 'Collapse Selected Code',
     execute: args => {
     execute: args => {
-      const current = getCurrent();
+      const current = getCurrent(args);
 
 
       if (current) {
       if (current) {
         return NotebookActions.hideCode(current.content);
         return NotebookActions.hideCode(current.content);
@@ -1462,7 +1466,7 @@ function addCommands(app: JupyterLab, services: ServiceManager, tracker: Noteboo
   commands.addCommand(CommandIDs.showCode, {
   commands.addCommand(CommandIDs.showCode, {
     label: 'Expand Selected Code',
     label: 'Expand Selected Code',
     execute: args => {
     execute: args => {
-      const current = getCurrent();
+      const current = getCurrent(args);
 
 
       if (current) {
       if (current) {
         return NotebookActions.showCode(current.content);
         return NotebookActions.showCode(current.content);
@@ -1473,7 +1477,7 @@ function addCommands(app: JupyterLab, services: ServiceManager, tracker: Noteboo
   commands.addCommand(CommandIDs.hideAllCode, {
   commands.addCommand(CommandIDs.hideAllCode, {
     label: 'Collapse All Code',
     label: 'Collapse All Code',
     execute: args => {
     execute: args => {
-      const current = getCurrent();
+      const current = getCurrent(args);
 
 
       if (current) {
       if (current) {
         return NotebookActions.hideAllCode(current.content);
         return NotebookActions.hideAllCode(current.content);
@@ -1484,7 +1488,7 @@ function addCommands(app: JupyterLab, services: ServiceManager, tracker: Noteboo
   commands.addCommand(CommandIDs.showAllCode, {
   commands.addCommand(CommandIDs.showAllCode, {
     label: 'Expand All Code',
     label: 'Expand All Code',
     execute: args => {
     execute: args => {
-      const current = getCurrent();
+      const current = getCurrent(args);
 
 
       if (current) {
       if (current) {
         return NotebookActions.showAllCode(current.content);
         return NotebookActions.showAllCode(current.content);
@@ -1495,7 +1499,7 @@ function addCommands(app: JupyterLab, services: ServiceManager, tracker: Noteboo
   commands.addCommand(CommandIDs.hideOutput, {
   commands.addCommand(CommandIDs.hideOutput, {
     label: 'Collapse Selected Outputs',
     label: 'Collapse Selected Outputs',
     execute: args => {
     execute: args => {
-      const current = getCurrent();
+      const current = getCurrent(args);
 
 
       if (current) {
       if (current) {
         return NotebookActions.hideOutput(current.content);
         return NotebookActions.hideOutput(current.content);
@@ -1506,7 +1510,7 @@ function addCommands(app: JupyterLab, services: ServiceManager, tracker: Noteboo
   commands.addCommand(CommandIDs.showOutput, {
   commands.addCommand(CommandIDs.showOutput, {
     label: 'Expand Selected Outputs',
     label: 'Expand Selected Outputs',
     execute: args => {
     execute: args => {
-      const current = getCurrent();
+      const current = getCurrent(args);
 
 
       if (current) {
       if (current) {
         return NotebookActions.showOutput(current.content);
         return NotebookActions.showOutput(current.content);
@@ -1517,7 +1521,7 @@ function addCommands(app: JupyterLab, services: ServiceManager, tracker: Noteboo
   commands.addCommand(CommandIDs.hideAllOutputs, {
   commands.addCommand(CommandIDs.hideAllOutputs, {
     label: 'Collapse All Outputs',
     label: 'Collapse All Outputs',
     execute: args => {
     execute: args => {
-      const current = getCurrent();
+      const current = getCurrent(args);
 
 
       if (current) {
       if (current) {
         return NotebookActions.hideAllOutputs(current.content);
         return NotebookActions.hideAllOutputs(current.content);
@@ -1528,7 +1532,7 @@ function addCommands(app: JupyterLab, services: ServiceManager, tracker: Noteboo
   commands.addCommand(CommandIDs.showAllOutputs, {
   commands.addCommand(CommandIDs.showAllOutputs, {
     label: 'Expand All Outputs',
     label: 'Expand All Outputs',
     execute: args => {
     execute: args => {
-      const current = getCurrent();
+      const current = getCurrent(args);
 
 
       if (current) {
       if (current) {
         return NotebookActions.showAllOutputs(current.content);
         return NotebookActions.showAllOutputs(current.content);
@@ -1539,7 +1543,7 @@ function addCommands(app: JupyterLab, services: ServiceManager, tracker: Noteboo
   commands.addCommand(CommandIDs.enableOutputScrolling, {
   commands.addCommand(CommandIDs.enableOutputScrolling, {
     label: 'Enable Scrolling for Outputs',
     label: 'Enable Scrolling for Outputs',
     execute: args => {
     execute: args => {
-      const current = getCurrent();
+      const current = getCurrent(args);
 
 
       if (current) {
       if (current) {
         return NotebookActions.enableOutputScrolling(current.content);
         return NotebookActions.enableOutputScrolling(current.content);
@@ -1550,7 +1554,7 @@ function addCommands(app: JupyterLab, services: ServiceManager, tracker: Noteboo
   commands.addCommand(CommandIDs.disableOutputScrolling, {
   commands.addCommand(CommandIDs.disableOutputScrolling, {
     label: 'Disable Scrolling for Outputs',
     label: 'Disable Scrolling for Outputs',
     execute: args => {
     execute: args => {
-      const current = getCurrent();
+      const current = getCurrent(args);
 
 
       if (current) {
       if (current) {
         return NotebookActions.disableOutputScrolling(current.content);
         return NotebookActions.disableOutputScrolling(current.content);
@@ -1561,7 +1565,7 @@ function addCommands(app: JupyterLab, services: ServiceManager, tracker: Noteboo
   commands.addCommand(CommandIDs.saveWithView, {
   commands.addCommand(CommandIDs.saveWithView, {
     label: 'Save Notebook with View State',
     label: 'Save Notebook with View State',
     execute: args => {
     execute: args => {
-      const current = getCurrent();
+      const current = getCurrent(args);
 
 
       if (current) {
       if (current) {
         NotebookActions.persistViewState(current.content);
         NotebookActions.persistViewState(current.content);