Fix Pretty-Print Infobar not working

This CL fixes the Pretty-Print Infobar not formatting the source file
when the Pretty-Print button is pressed. The bug was caused by a subtle
change to the button delegate when it was updated to support TypeScript
causing it to no longer invoke the format function.

The CL slightly modifies the ScriptFormatterEditorAction to have button
a event handler to absorb the unused 'event' argument, so the Infobar
does not need to pass one to toggleFormatScriptSource.

Bug: 1159531
Change-Id: I8e1876e8ce0ebc1e498e81a619a905a007cabdf5
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2596121
Reviewed-by: Paul Lewis <aerotwist@chromium.org>
Commit-Queue: Brian Cui <brcui@microsoft.com>
This commit is contained in:
Brian Cui
2020-12-21 18:13:26 +00:00
committed by Commit Bot
parent e02962c02f
commit 37fb5ece29
2 changed files with 7 additions and 3 deletions
+1 -1
View File
@@ -1781,7 +1781,7 @@ export class DebuggerPlugin extends Plugin {
if (!editorAction.isCurrentUISourceCodeFormatable()) {
return;
}
formatterCallback = () => editorAction.toggleFormatScriptSource.bind(editorAction);
formatterCallback = editorAction.toggleFormatScriptSource.bind(editorAction);
break;
}
}
@@ -88,7 +88,7 @@ export class ScriptFormatterEditorAction {
});
this._button = new UI.Toolbar.ToolbarButton(Common.UIString.UIString('Pretty print'), 'largeicon-pretty-print');
this._button.addEventListener(UI.Toolbar.ToolbarButton.Events.Click, this.toggleFormatScriptSource, this);
this._button.addEventListener(UI.Toolbar.ToolbarButton.Events.Click, this._onFormatScriptButtonClicked, this);
this._updateButton(sourcesView.currentUISourceCode());
return this._button;
@@ -125,7 +125,11 @@ export class ScriptFormatterEditorAction {
/**
* @param {!Common.EventTarget.EventTargetEvent} event
*/
toggleFormatScriptSource(event) {
_onFormatScriptButtonClicked(event) {
this.toggleFormatScriptSource();
}
toggleFormatScriptSource() {
const uiSourceCode = this._sourcesView.currentUISourceCode();
if (!uiSourceCode || !this._isFormatableScript(uiSourceCode)) {
return;