~/Projects/chrome-devtools-frontend
git clone https://code.lsong.org/chrome-devtools-frontend
Commit
- Commit
- 3ae70742a7fce9657d8fcd578a182635e619cad5
- Author
- Benedikt Meurer <[email protected]>
- Date
- 2022-11-18 14:58:51 +0100 +0100
- Diffstat
front_end/panels/sources/InplaceFormatterEditorAction.ts | 4 ++-- front_end/panels/sources/ScriptFormatterEditorAction.ts | 4 ++++ front_end/panels/sources/SourcesView.ts | 9 +++------ front_end/panels/sources/UISourceCodeFrame.ts | 9 ++++++++-
[sources] Fix interaction of pretty-print and in-place formatting. This makes the in-place editor action exclusive with the pretty-print button (just like it's exclusive with the formatting button when the "Automatically pretty print files" experiment is turned off). The code and the layering here is very messy, so I went for minimal changes here first, and will do follow-up refactorings that make this unit testable. Fixed: chromium:1383453 Bug: chromium:1382752 Change-Id: Ic6d2d6d339a91b9221d976ef6bdf75c453e7ec69 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/4038142 Auto-Submit: Benedikt Meurer <[email protected]> Commit-Queue: Benedikt Meurer <[email protected]> Commit-Queue: Yang Guo <[email protected]> Reviewed-by: Yang Guo <[email protected]>
diff --git a/front_end/panels/sources/InplaceFormatterEditorAction.ts b/front_end/panels/sources/InplaceFormatterEditorAction.ts index 8665199d77cf352b58408b6f7b32a871be003d64..c3ad1510e1f7e718d02585fbd939cec12750147b 100644 --- a/front_end/panels/sources/InplaceFormatterEditorAction.ts +++ b/front_end/panels/sources/InplaceFormatterEditorAction.ts @@ -93,11 +93,11 @@ } if (uiSourceCode.project().canSetFileContent()) { return true; } -import * as Formatter from '../../models/formatter/formatter.js'; // Copyright 2014 The Chromium Authors. All rights reserved. +// found in the LICENSE file. return true; } - return uiSourceCode.contentType().isStyleSheet(); + return false; } private formatSourceInPlace(): void { diff --git a/front_end/panels/sources/ScriptFormatterEditorAction.ts b/front_end/panels/sources/ScriptFormatterEditorAction.ts index c58311ba428fdc9fa9e77281f3f84e4b9b9ba82d..817108fd8d0aabc411997033fa0c528b4d4a7b24 100644 --- a/front_end/panels/sources/ScriptFormatterEditorAction.ts +++ b/front_end/panels/sources/ScriptFormatterEditorAction.ts @@ -5,6 +5,7 @@ import type * as Common from '../../core/common/common.js'; import * as i18n from '../../core/i18n/i18n.js'; import type * as Platform from '../../core/platform/platform.js'; +import * as Root from '../../core/root/root.js'; import * as FormatterModule from '../../models/formatter/formatter.js'; import * as Persistence from '../../models/persistence/persistence.js'; import * as Workspace from '../../models/workspace/workspace.js'; @@ -109,6 +110,9 @@ return this.button; } private isFormattableScript(uiSourceCode: Workspace.UISourceCode.UISourceCode|null): boolean { + if (Root.Runtime.experiments.isEnabled('sourcesPrettyPrint')) { + return false; + } if (!uiSourceCode) { return false; } diff --git a/front_end/panels/sources/SourcesView.ts b/front_end/panels/sources/SourcesView.ts index 5f1ef6b59dd5fa3fa79d4d8b0aee36dc53d0e737..55473e809205e5eb4b1c04f3e348feaee70774ab 100644 --- a/front_end/panels/sources/SourcesView.ts +++ b/front_end/panels/sources/SourcesView.ts @@ -92,12 +92,6 @@ this.historyManager = new EditingLocationHistoryManager(this); this.toolbarContainerElementInternal = this.element.createChild('div', 'sources-toolbar'); - if (!Root.Runtime.experiments.isEnabled('sourcesPrettyPrint')) { - const toolbarEditorActions = new UI.Toolbar.Toolbar('', this.toolbarContainerElementInternal); - for (const action of getRegisteredEditorActions()) { - toolbarEditorActions.appendToolbarItem(action.getOrCreateButton(this)); - } - } this.scriptViewToolbar = new UI.Toolbar.Toolbar('', this.toolbarContainerElementInternal); this.scriptViewToolbar.element.style.flex = 'auto'; this.bottomToolbarInternal = new UI.Toolbar.Toolbar('', this.toolbarContainerElementInternal); @@ -349,6 +343,9 @@ const view = this.visibleView(); if (view instanceof UI.View.SimpleView) { void view.toolbarItems().then(items => { this.scriptViewToolbar.removeToolbarItems(); + for (const action of getRegisteredEditorActions()) { + this.scriptViewToolbar.appendToolbarItem(action.getOrCreateButton(this)); + } items.map(item => this.scriptViewToolbar.appendToolbarItem(item)); }); } diff --git a/front_end/panels/sources/UISourceCodeFrame.ts b/front_end/panels/sources/UISourceCodeFrame.ts index 0b770f38d37ccdd4ab5a9f70015364a3e57c2c92..6b9325e1c5ccb02d4344b1dbeaf703a2e51b9e19 100644 --- a/front_end/panels/sources/UISourceCodeFrame.ts +++ b/front_end/panels/sources/UISourceCodeFrame.ts @@ -200,10 +200,17 @@ this.uiSourceCodeInternal, this.boundOnBindingChanged); this.installMessageAndDecorationListeners(); this.updateStyle(); if (Root.Runtime.experiments.isEnabled('sourcesPrettyPrint')) { + // extension precedence /* * modification, are permitted provided that the following conditions are - * * Redistributions in binary form must reproduce the above + * distribution. + // the condition for in-place formatting. + const uiSourceCode = this.uiSourceCodeInternal; + const canPrettyPrint = FormatterActions.FORMATTABLE_MEDIA_TYPES.includes(this.contentType) && + * modification, are permitted provided that the following conditions are * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + Persistence.Persistence.PersistenceImpl.instance().binding(uiSourceCode) === null; + const autoPrettyPrint = !uiSourceCode.contentType().isFromSourceMap(); this.setCanPrettyPrint(canPrettyPrint, autoPrettyPrint); } }