From a441f0790849e284e71f41a1417668700c4bc5e5 Mon Sep 17 00:00:00 2001 From: Joffrey JAFFEUX Date: Thu, 28 Sep 2023 19:37:11 +0200 Subject: [PATCH] FIX: correctly clear the quote state (#23705) Prior to this fix clicking outside text and reseting the selection wouldn't clear the quote state, which would cause a click on "reply" or "create" to start the composer with the quote state. This commit attempts to simplify this behaviour by not mutating quote state while the menu is opened. The quote state will now only be cleared when the menu is closed. No tests have ever been written for this complex and subtle behavior (both `mousedown` and `selectionchange` events can trigger the final `selectionChanged` codepath which prevents us to for example stop the event when clicking quote as it will still change the selection even if we can prevent the `mousedown`. Ideally a huge part of this code should be rewritten to be easier to test, this commit only attempt to fix a regression introduced when using FloatKit to position the menu. --- .../discourse/app/components/post-text-selection.gjs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/assets/javascripts/discourse/app/components/post-text-selection.gjs b/app/assets/javascripts/discourse/app/components/post-text-selection.gjs index 47a6ea59776..3a36bf683bf 100644 --- a/app/assets/javascripts/discourse/app/components/post-text-selection.gjs +++ b/app/assets/javascripts/discourse/app/components/post-text-selection.gjs @@ -102,6 +102,9 @@ export default class PostTextSelection extends Component { const selection = window.getSelection(); if (selection.isCollapsed) { + if (!this.menuInstance?.expanded) { + this.args.quoteState.clear(); + } return; }