From 28123cfb3ff63e26d9fb570d6a556c9211fc2452 Mon Sep 17 00:00:00 2001 From: Bauke Date: Tue, 15 Mar 2022 11:30:35 +0100 Subject: [PATCH] Clear the editor when clicking on the active bang. --- source/options/components/page-main.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/source/options/components/page-main.ts b/source/options/components/page-main.ts index 2f28bbf..74fd452 100644 --- a/source/options/components/page-main.ts +++ b/source/options/components/page-main.ts @@ -120,9 +120,18 @@ export class PageMain extends Component { const availableBangs = bangs.map((bang) => { const active = bang.id === this.state.editorBang.id ? 'active' : ''; const onClick = () => { - this.setState({ - editorBang: {...bang}, - }); + const allEqual = Object.entries(this.state.editorBang).every( + ([key, value]) => bang[key as keyof BangParameters] === value, + ); + if (allEqual) { + this.setState({ + editorBang: {...this.emptyBang}, + }); + } else { + this.setState({ + editorBang: {...bang}, + }); + } }; return html`