From c5a4158a65123fd18a973252893215947e1a323d Mon Sep 17 00:00:00 2001 From: SteVen Batten Date: Wed, 2 Jun 2021 13:54:45 -0700 Subject: [PATCH 1/4] fixes #125247 --- .../contrib/workspace/browser/workspace.contribution.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vs/workbench/contrib/workspace/browser/workspace.contribution.ts b/src/vs/workbench/contrib/workspace/browser/workspace.contribution.ts index 8dc23294e09..a84ee805975 100644 --- a/src/vs/workbench/contrib/workspace/browser/workspace.contribution.ts +++ b/src/vs/workbench/contrib/workspace/browser/workspace.contribution.ts @@ -93,7 +93,7 @@ export class WorkspaceTrustRequestHandler extends Disposable implements IWorkben this.createStatusbarEntry(); // Set empty workspace trust state - this.setEmptyWorkspaceTrustState(); + await this.setEmptyWorkspaceTrustState(); // Show modal dialog if (this.hostService.hasFocus) { From d215fc72380047d9e9034e74ebb3e29953bdb85c Mon Sep 17 00:00:00 2001 From: Matt Bierner Date: Wed, 2 Jun 2021 14:02:59 -0700 Subject: [PATCH 2/4] Fallback to active editor if no webview is focused Fixes #65310 On windows or linux while using our custom title bar, triggering context menus causes the webview element to no longer be focused. This causes the `copy` and `paste` commands to stop working The fix is to also check the `activeEditor` when dispatching copy/paste --- .../contrib/webview/browser/webview.contribution.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/vs/workbench/contrib/webview/browser/webview.contribution.ts b/src/vs/workbench/contrib/webview/browser/webview.contribution.ts index 6c4675e7e9d..ddb5e97ac30 100644 --- a/src/vs/workbench/contrib/webview/browser/webview.contribution.ts +++ b/src/vs/workbench/contrib/webview/browser/webview.contribution.ts @@ -8,6 +8,8 @@ import { CopyAction, CutAction, PasteAction } from 'vs/editor/contrib/clipboard/ import * as nls from 'vs/nls'; import { MenuId, MenuRegistry } from 'vs/platform/actions/common/actions'; import { IWebviewService, Webview } from 'vs/workbench/contrib/webview/browser/webview'; +import { WebviewInput } from 'vs/workbench/contrib/webviewPanel/browser/webviewEditorInput'; +import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; const PRIORITY = 100; @@ -20,6 +22,13 @@ function overrideCommandForWebview(command: MultiCommand | undefined, f: (webvie f(webview); return true; } + + const editorService = accessor.get(IEditorService); + if (editorService.activeEditor instanceof WebviewInput) { + f(editorService.activeEditor.webview); + return true; + } + return false; }); } From 26cd18321bd7ad322177b1af74e42a93b3c72424 Mon Sep 17 00:00:00 2001 From: rebornix Date: Wed, 2 Jun 2021 14:12:13 -0700 Subject: [PATCH 3/4] remove backwards compatible tests. --- .../vscode-api-tests/src/singlefolder-tests/notebook.test.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/extensions/vscode-api-tests/src/singlefolder-tests/notebook.test.ts b/extensions/vscode-api-tests/src/singlefolder-tests/notebook.test.ts index 28ca6061375..aa34893ec7a 100644 --- a/extensions/vscode-api-tests/src/singlefolder-tests/notebook.test.ts +++ b/extensions/vscode-api-tests/src/singlefolder-tests/notebook.test.ts @@ -478,7 +478,6 @@ suite('Notebook API tests', function () { const secondCell = vscode.window.activeNotebookEditor!.document.cellAt(1); assert.strictEqual(secondCell!.outputs.length, 1); assert.deepStrictEqual(secondCell!.outputs[0].metadata, { testOutputMetadata: true, ['text/plain']: { testOutputItemMetadata: true } }); - assert.strictEqual((secondCell!.outputs[0]).outputs.length, 1); //todo@jrieken will FAIL once the backwards compatibility is gone assert.strictEqual(secondCell!.outputs[0].items.length, 1); assert.strictEqual(secondCell!.outputs[0].items[0].mime, 'text/plain'); assert.strictEqual(new TextDecoder().decode(secondCell!.outputs[0].items[0].data), 'Hello World'); From 60dd761211bb3f744eb5f591e5643f2fddb55bf6 Mon Sep 17 00:00:00 2001 From: rebornix Date: Wed, 2 Jun 2021 14:56:35 -0700 Subject: [PATCH 4/4] update the layout based on treatment. --- .../contrib/profile/notebookProfile.ts | 57 +++++++++++++++++-- 1 file changed, 52 insertions(+), 5 deletions(-) diff --git a/src/vs/workbench/contrib/notebook/browser/contrib/profile/notebookProfile.ts b/src/vs/workbench/contrib/notebook/browser/contrib/profile/notebookProfile.ts index 1ea0765f964..a13b215651f 100644 --- a/src/vs/workbench/contrib/notebook/browser/contrib/profile/notebookProfile.ts +++ b/src/vs/workbench/contrib/notebook/browser/contrib/profile/notebookProfile.ts @@ -3,11 +3,17 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ +import { Disposable } from 'vs/base/common/lifecycle'; +import { Registry } from 'vs/platform/registry/common/platform'; import { ServicesAccessor } from 'vs/editor/browser/editorExtensions'; import { localize } from 'vs/nls'; import { Action2, registerAction2 } from 'vs/platform/actions/common/actions'; import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; +import { optional } from 'vs/platform/instantiation/common/instantiation'; import { CellToolbarLocation, CompactView, ConsolidatedRunButton, FocusIndicator, GlobalToolbar, InsertToolbarPosition, ShowCellStatusBarAfterExecuteKey, ShowCellStatusBarKey, UndoRedoPerCell } from 'vs/workbench/contrib/notebook/common/notebookCommon'; +import { ITASExperimentService } from 'vs/workbench/services/experiment/common/experimentService'; +import { Extensions as WorkbenchExtensions, IWorkbenchContributionsRegistry } from 'vs/workbench/common/contributions'; +import { LifecyclePhase } from 'vs/workbench/services/lifecycle/common/lifecycle'; export enum NotebookProfileType { default = 'default', @@ -24,7 +30,8 @@ const profiles = { [CompactView]: true, [ShowCellStatusBarKey]: true, [ShowCellStatusBarAfterExecuteKey]: false, - [ConsolidatedRunButton]: true + [ConsolidatedRunButton]: true, + [UndoRedoPerCell]: false }, [NotebookProfileType.jupyter]: { [FocusIndicator]: 'gutter', @@ -43,12 +50,12 @@ const profiles = { [CellToolbarLocation]: { default: 'right' }, [CompactView]: false, [ShowCellStatusBarKey]: false, - [ConsolidatedRunButton]: true + [ConsolidatedRunButton]: true, + [UndoRedoPerCell]: false } }; -async function applyProfile(accessor: ServicesAccessor, profile: Record): Promise { - const configService = accessor.get(IConfigurationService); +async function applyProfile(configService: IConfigurationService, profile: Record): Promise { const promises = []; for (let settingKey in profile) { promises.push(configService.updateValue(settingKey, profile[settingKey])); @@ -74,7 +81,8 @@ registerAction2(class extends Action2 { return; } - return applyProfile(accessor, profiles[args.profile]); + const configService = accessor.get(IConfigurationService); + return applyProfile(configService, profiles[args.profile]); } }); @@ -84,3 +92,42 @@ function isSetProfileArgs(args: unknown): args is ISetProfileArgs { setProfileArgs.profile === NotebookProfileType.default || setProfileArgs.profile === NotebookProfileType.jupyter; } + +export class NotebookProfileContribution extends Disposable { + constructor(@IConfigurationService configService: IConfigurationService, @optional(ITASExperimentService) private readonly experimentService: ITASExperimentService) { + super(); + + if (this.experimentService) { + this.experimentService.getTreatment('notebookprofile').then(treatment => { + if (treatment === undefined) { + return; + } else { + // check if settings are already modified + const focusIndicator = configService.getValue(FocusIndicator); + const insertToolbarPosition = configService.getValue(InsertToolbarPosition); + const globalToolbar = configService.getValue(GlobalToolbar); + // const cellToolbarLocation = configService.getValue(CellToolbarLocation); + const compactView = configService.getValue(CompactView); + const showCellStatusBarKey = configService.getValue(ShowCellStatusBarKey); + const showCellStatusBarAfterExecuteKey = configService.getValue(ShowCellStatusBarAfterExecuteKey); + const consolidatedRunButton = configService.getValue(ConsolidatedRunButton); + if (focusIndicator === 'border' + && insertToolbarPosition === 'both' + && globalToolbar === false + // && cellToolbarLocation === undefined + && compactView === true + && showCellStatusBarKey === true + && showCellStatusBarAfterExecuteKey === false + && consolidatedRunButton === true + ) { + applyProfile(configService, profiles[treatment] ?? profiles[NotebookProfileType.default]); + } + } + }); + } + } +} + +const workbenchContributionsRegistry = Registry.as(WorkbenchExtensions.Workbench); +workbenchContributionsRegistry.registerWorkbenchContribution(NotebookProfileContribution, LifecyclePhase.Ready); +