From 37fb5ece29fd09e5da06b508477b84b8bce58df3 Mon Sep 17 00:00:00 2001 From: Brian Cui Date: Wed, 16 Dec 2020 13:00:06 -0800 Subject: [PATCH] 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 Commit-Queue: Brian Cui --- front_end/sources/DebuggerPlugin.js | 2 +- front_end/sources/ScriptFormatterEditorAction.js | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/front_end/sources/DebuggerPlugin.js b/front_end/sources/DebuggerPlugin.js index 0388dc0955..9beb51a294 100644 --- a/front_end/sources/DebuggerPlugin.js +++ b/front_end/sources/DebuggerPlugin.js @@ -1781,7 +1781,7 @@ export class DebuggerPlugin extends Plugin { if (!editorAction.isCurrentUISourceCodeFormatable()) { return; } - formatterCallback = () => editorAction.toggleFormatScriptSource.bind(editorAction); + formatterCallback = editorAction.toggleFormatScriptSource.bind(editorAction); break; } } diff --git a/front_end/sources/ScriptFormatterEditorAction.js b/front_end/sources/ScriptFormatterEditorAction.js index a9b95d6e7a..6f1fb193c4 100644 --- a/front_end/sources/ScriptFormatterEditorAction.js +++ b/front_end/sources/ScriptFormatterEditorAction.js @@ -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;