From fc3f4c9f2d38ffe8b074188566f45554c519beb6 Mon Sep 17 00:00:00 2001 From: Jason Grout Date: Fri, 11 Oct 2019 23:56:29 -0700 Subject: [PATCH] Backport PR #7334: reset log display and count when non-notebook tab gets activated --- packages/logconsole-extension/src/index.tsx | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/packages/logconsole-extension/src/index.tsx b/packages/logconsole-extension/src/index.tsx index c387b5e76edc..1c6e5113a28e 100644 --- a/packages/logconsole-extension/src/index.tsx +++ b/packages/logconsole-extension/src/index.tsx @@ -2,6 +2,7 @@ // Distributed under the terms of the Modified BSD License. import { + ILabShell, JupyterFrontEnd, JupyterFrontEndPlugin, ILayoutRestorer @@ -55,6 +56,7 @@ const logConsolePlugin: JupyterFrontEndPlugin = { id: LOG_CONSOLE_PLUGIN_ID, provides: ILoggerRegistry, requires: [ + ILabShell, IMainMenu, ICommandPalette, INotebookTracker, @@ -373,6 +375,7 @@ export namespace LogConsoleStatus { */ function activateLogConsole( app: JupyterFrontEnd, + labShell: ILabShell, mainMenu: IMainMenu, palette: ICommandPalette, nbtracker: INotebookTracker, @@ -556,6 +559,21 @@ function activateLogConsole( } ); + labShell.currentChanged.connect((_, change) => { + const newValue = change.newValue; + + // if a new tab is activated which is not a notebook, + // then reset log display and count + if (newValue && newValue !== logConsoleWidget && !nbtracker.has(newValue)) { + if (logConsoleWidget) { + logConsoleWidget.content.activeSource = null; + void tracker.save(logConsoleWidget); + } + + status.model.activeSource = null; + } + }); + if (settingRegistry) { const updateSettings = (settings: ISettingRegistry.ISettings): void => { const maxLogEntries = settings.get('maxLogEntries').composite as number;