From 5430efbb31cfc0f57eac7fd130bb43aafa85143a Mon Sep 17 00:00:00 2001
From: Maxim Nikolenko <maximnproductengine@lindenlab.com>
Date: Tue, 15 Aug 2023 20:38:02 +0300
Subject: [PATCH] SL-20139 pressing the Tab key should paste tooltip only when
 hovering functions in LSL editor

---
 indra/llui/lltextbase.cpp   |  2 +-
 indra/llui/lltexteditor.cpp |  3 ++-
 indra/llui/lltooltip.cpp    | 20 ++++++++++++++++----
 indra/llui/lltooltip.h      |  8 +++++++-
 4 files changed, 26 insertions(+), 7 deletions(-)

diff --git a/indra/llui/lltextbase.cpp b/indra/llui/lltextbase.cpp
index 8732a7ce45d..26a38bd541f 100644
--- a/indra/llui/lltextbase.cpp
+++ b/indra/llui/lltextbase.cpp
@@ -3431,7 +3431,7 @@ BOOL LLNormalTextSegment::handleToolTip(S32 x, S32 y, MASK mask)
 	if (mToken && !mToken->getToolTip().empty())
 	{
 		const LLWString& wmsg = mToken->getToolTip();
-		LLToolTipMgr::instance().show(wstring_to_utf8str(wmsg));
+        LLToolTipMgr::instance().show(wstring_to_utf8str(wmsg), (mToken->getType() == LLKeywordToken::TT_FUNCTION));
 		return TRUE;
 	}
 	// or do we have an explicitly set tooltip (e.g., for Urls)
diff --git a/indra/llui/lltexteditor.cpp b/indra/llui/lltexteditor.cpp
index 3d2a4269134..c83ed4c3e1d 100644
--- a/indra/llui/lltexteditor.cpp
+++ b/indra/llui/lltexteditor.cpp
@@ -1779,7 +1779,8 @@ BOOL LLTextEditor::handleKeyHere(KEY key, MASK mask )
 	else 
 	{
 		if (mEnableTooltipPaste &&
-			LLToolTipMgr::instance().toolTipVisible() && 
+			LLToolTipMgr::instance().toolTipVisible() &&
+            LLToolTipMgr::instance().isTooltipPastable() &&
 			KEY_TAB == key)
 		{	// Paste the first line of a tooltip into the editor
 			std::string message;
diff --git a/indra/llui/lltooltip.cpp b/indra/llui/lltooltip.cpp
index 2f56a8b1d0b..c4b132317fe 100644
--- a/indra/llui/lltooltip.cpp
+++ b/indra/llui/lltooltip.cpp
@@ -154,7 +154,8 @@ LLToolTip::Params::Params()
 	text_color("text_color"),
 	time_based_media("time_based_media", false),
 	web_based_media("web_based_media", false),
-	media_playing("media_playing", false)
+	media_playing("media_playing", false),
+    allow_paste_tooltip("allow_paste_tooltip", false)
 {
 	changeDefault(chrome, true);
 }
@@ -166,7 +167,8 @@ LLToolTip::LLToolTip(const LLToolTip::Params& p)
 	mTextBox(NULL),
 	mInfoButton(NULL),
 	mPlayMediaButton(NULL),
-	mHomePageButton(NULL)
+	mHomePageButton(NULL),
+    mIsTooltipPastable(p.allow_paste_tooltip)
 {
 	LLTextBox::Params params;
 	params.name = params.initial_value().asString();
@@ -308,6 +310,8 @@ void LLToolTip::initFromParams(const LLToolTip::Params& p)
 	mTextBox->reshape(mTextBox->getRect().getWidth(), llmax(mTextBox->getRect().getHeight(), tooltip_rect.getHeight() - 2 * mPadding));
 
 	setShape(tooltip_rect);
+
+    mIsTooltipPastable = p.allow_paste_tooltip;
 }
 
 void LLToolTip::setVisible(BOOL visible)
@@ -469,9 +473,9 @@ void LLToolTipMgr::createToolTip(const LLToolTip::Params& params)
 }
 
 
-void LLToolTipMgr::show(const std::string& msg)
+void LLToolTipMgr::show(const std::string& msg, bool allow_paste_tooltip)
 {
-	show(LLToolTip::Params().message(msg));
+    show(LLToolTip::Params().message(msg).allow_paste_tooltip(allow_paste_tooltip));
 }
 
 void LLToolTipMgr::show(const LLToolTip::Params& params)
@@ -612,5 +616,13 @@ void LLToolTipMgr::getToolTipMessage(std::string & message)
 	}
 }
 
+bool LLToolTipMgr::isTooltipPastable()
+{
+    if (toolTipVisible())
+    {
+        return mToolTip->isTooltipPastable();
+    }
+    return false;
+ }
 
 // EOF
diff --git a/indra/llui/lltooltip.h b/indra/llui/lltooltip.h
index 0b1fbe53674..6ff7c0671a6 100644
--- a/indra/llui/lltooltip.h
+++ b/indra/llui/lltooltip.h
@@ -91,6 +91,8 @@ class LLToolTip : public LLPanel
 									padding;
 		Optional<bool>				wrap;
 
+        Optional<bool> allow_paste_tooltip;
+
 		Params();
 	};
 	/*virtual*/ void draw();
@@ -106,6 +108,7 @@ class LLToolTip : public LLPanel
 	void initFromParams(const LLToolTip::Params& params);
 
 	void getToolTipMessage(std::string & message);
+    bool isTooltipPastable() { return mIsTooltipPastable; }
 
 private:
 	class LLTextBox*	mTextBox;
@@ -117,6 +120,8 @@ class LLToolTip : public LLPanel
 	LLFrameTimer	mVisibleTimer;
 	bool			mHasClickCallback;
 	S32				mPadding;	// pixels
+
+    bool mIsTooltipPastable;
 };
 
 // used for the inspector tooltips which need different background images etc.
@@ -134,7 +139,7 @@ class LLToolTipMgr : public LLSingleton<LLToolTipMgr>
 
 public:
 	void show(const LLToolTip::Params& params);
-	void show(const std::string& message);
+	void show(const std::string& message, bool allow_paste_tooltip = false);
 
 	void unblockToolTips();
 	void blockToolTips();
@@ -146,6 +151,7 @@ class LLToolTipMgr : public LLSingleton<LLToolTipMgr>
 	void updateToolTipVisibility();
 
 	void getToolTipMessage(std::string & message);
+    bool isTooltipPastable();
 
 private:
 	void createToolTip(const LLToolTip::Params& params);
-- 
GitLab