From 17a3924a28770e6910022ad8f627bb8e2b667730 Mon Sep 17 00:00:00 2001
From: Kitty Barnett <develop@catznip.com>
Date: Tue, 8 Nov 2022 01:10:09 +0100
Subject: [PATCH] Add proper mouse down handler to the emoji complete panel  
 -> the previous commit didn't properly set mFrontChild after restoring the
 topmost floaters   -> additionally we don't want mouse clicks in "can't steal
 focus from frontmost" floaters to set focus to them

---
 indra/llui/llfloater.cpp               | 23 ++++++++++++--------
 indra/newview/llpanelemojicomplete.cpp | 30 +++++++++++++++++++++++---
 indra/newview/llpanelemojicomplete.h   |  3 +++
 3 files changed, 44 insertions(+), 12 deletions(-)

diff --git a/indra/llui/llfloater.cpp b/indra/llui/llfloater.cpp
index 04f6b11b7c7..6f341bc0cdd 100644
--- a/indra/llui/llfloater.cpp
+++ b/indra/llui/llfloater.cpp
@@ -2486,7 +2486,7 @@ void LLFloaterView::bringToFront(LLFloater* child, BOOL give_focus, BOOL restore
 
 	if (mFrontChild == child)
 	{
-		if (give_focus && !gFocusMgr.childHasKeyboardFocus(child))
+		if (give_focus && child->canFocusStealFrontmost() && !gFocusMgr.childHasKeyboardFocus(child))
 		{
 			child->setFocus(TRUE);
 		}
@@ -3042,24 +3042,29 @@ void LLFloaterView::syncFloaterTabOrder()
                 if (mFrontChild != floaterp)
                 {
                     // Grab a list of the top floaters that want to stay on top of the focused floater
-					std::list<LLView*> listTop;
+					std::list<LLFloater*> listTop;
 					if (mFrontChild && !mFrontChild->canFocusStealFrontmost())
                     {
-                        for (LLView* childfloaterp : *getChildList())
+                        for (LLView* childp : *getChildList())
                         {
-                            if (static_cast<LLFloater*>(childfloaterp)->canFocusStealFrontmost())
+							LLFloater* child_floaterp = static_cast<LLFloater*>(childp);
+                            if (child_floaterp->canFocusStealFrontmost())
                                 break;
-							listTop.push_back(childfloaterp);
+							listTop.push_back(child_floaterp);
                         }
                     }
 
                     bringToFront(floaterp, FALSE);
 
                     // Restore top floaters
-                    for (LLView* childp :listTop)
-                    {
-                        sendChildToFront(childp);
-                    }
+					if (!listTop.empty())
+					{
+						for (LLView* childp : listTop)
+						{
+							sendChildToFront(childp);
+						}
+						mFrontChild = listTop.back();
+					}
                 }
 
 				break;
diff --git a/indra/newview/llpanelemojicomplete.cpp b/indra/newview/llpanelemojicomplete.cpp
index f890a14e8ed..8b89e3aa140 100644
--- a/indra/newview/llpanelemojicomplete.cpp
+++ b/indra/newview/llpanelemojicomplete.cpp
@@ -120,9 +120,6 @@ BOOL LLPanelEmojiComplete::handleKey(KEY key, MASK mask, BOOL called_from_parent
 			case KEY_RETURN:
 				if (!mEmojis.empty())
 				{
-					LLWString wstr;
-					wstr.push_back(mEmojis.at(mCurSelected));
-					setValue(wstring_to_utf8str(wstr));
 					onCommit();
 					handled = true;
 				}
@@ -137,6 +134,33 @@ BOOL LLPanelEmojiComplete::handleKey(KEY key, MASK mask, BOOL called_from_parent
 	return LLUICtrl::handleKey(key, mask, called_from_parent);
 }
 
+BOOL LLPanelEmojiComplete::handleMouseDown(S32 x, S32 y, MASK mask)
+{
+	mCurSelected = posToIndex(x, y);
+	mLastHover = LLVector2(x, y);
+
+	return TRUE;
+}
+
+BOOL LLPanelEmojiComplete::handleMouseUp(S32 x, S32 y, MASK mask)
+{
+	mCurSelected = posToIndex(x, y);
+	onCommit();
+
+	return TRUE;
+}
+
+void LLPanelEmojiComplete::onCommit()
+{
+	if (npos != mCurSelected)
+	{
+		LLWString wstr;
+		wstr.push_back(mEmojis.at(mCurSelected));
+		setValue(wstring_to_utf8str(wstr));
+		LLUICtrl::onCommit();
+	}
+}
+
 void LLPanelEmojiComplete::reshape(S32 width, S32 height, BOOL called_from_parent)
 {
 	LLUICtrl::reshape(width, height, called_from_parent);
diff --git a/indra/newview/llpanelemojicomplete.h b/indra/newview/llpanelemojicomplete.h
index 138cc465baf..2116b350bec 100644
--- a/indra/newview/llpanelemojicomplete.h
+++ b/indra/newview/llpanelemojicomplete.h
@@ -56,6 +56,9 @@ class LLPanelEmojiComplete : public LLUICtrl
 	void draw() override;
 	BOOL handleHover(S32 x, S32 y, MASK mask) override;
 	BOOL handleKey(KEY key, MASK mask, BOOL called_from_parent) override;
+	BOOL handleMouseDown(S32 x, S32 y, MASK mask) override;
+	BOOL handleMouseUp(S32 x, S32 y, MASK mask) override;
+	void onCommit() override;
 	void reshape(S32 width, S32 height, BOOL called_from_parent) override;
 
 public:
-- 
GitLab