summaryrefslogtreecommitdiff
path: root/indra/llui
diff options
context:
space:
mode:
authorAlexander Gavriliuk <alexandrgproductengine@lindenlab.com>2023-05-17 14:28:36 +0200
committerGuru <alexandrgproductengine@lindenlab.com>2023-05-17 19:06:57 +0200
commit671978e3927bc3ba9fc34008bbb7efd6f07b6c81 (patch)
tree63a5bb74ab3a6a78ec6ff4e67b5060c7d304ffde /indra/llui
parentbb96ac2621dd09dbc318d04f7e04ffbc50ec3174 (diff)
SL-19575 Create emoji gallery (fix bug with drawing emojis in chat history)
Diffstat (limited to 'indra/llui')
-rw-r--r--indra/llui/llemojidictionary.cpp11
-rw-r--r--indra/llui/llemojidictionary.h1
-rw-r--r--indra/llui/lltextbase.cpp41
-rw-r--r--indra/llui/lltextbase.h2
4 files changed, 37 insertions, 18 deletions
diff --git a/indra/llui/llemojidictionary.cpp b/indra/llui/llemojidictionary.cpp
index bb5c94689a..179c5d25bf 100644
--- a/indra/llui/llemojidictionary.cpp
+++ b/indra/llui/llemojidictionary.cpp
@@ -199,6 +199,17 @@ std::string LLEmojiDictionary::getNameFromEmoji(llwchar ch) const
return (mEmoji2Descr.end() != it) ? it->second->Name : LLStringUtil::null;
}
+bool LLEmojiDictionary::isEmoji(llwchar ch) const
+{
+ // Currently used codes: A9,AE,203C,2049,2122,...,2B55,3030,303D,3297,3299,1F004,...,1FAF6
+ if (ch == 0xA9 || ch == 0xAE || (ch >= 0x2000 && ch < 0x3300) || (ch >= 0x1F000 && ch < 0x20000))
+ {
+ return mEmoji2Descr.find(ch) != mEmoji2Descr.end();
+ }
+
+ return false;
+}
+
void LLEmojiDictionary::addEmoji(LLEmojiDescriptor&& descr)
{
mEmojis.push_back(descr);
diff --git a/indra/llui/llemojidictionary.h b/indra/llui/llemojidictionary.h
index 88ff5b8300..cc26f75ea3 100644
--- a/indra/llui/llemojidictionary.h
+++ b/indra/llui/llemojidictionary.h
@@ -68,6 +68,7 @@ public:
const LLEmojiDescriptor* getDescriptorFromEmoji(llwchar emoji) const;
const LLEmojiDescriptor* getDescriptorFromShortCode(const std::string& short_code) const;
std::string getNameFromEmoji(llwchar ch) const;
+ bool isEmoji(llwchar ch) const;
const emoji2descr_map_t& getEmoji2Descr() const { return mEmoji2Descr; }
const code2descr_map_t& getShortCode2Descr() const { return mShortCode2Descr; }
diff --git a/indra/llui/lltextbase.cpp b/indra/llui/lltextbase.cpp
index 0066e09cfc..e7273c96c1 100644
--- a/indra/llui/lltextbase.cpp
+++ b/indra/llui/lltextbase.cpp
@@ -29,6 +29,7 @@
#include "lltextbase.h"
+#include "llemojidictionary.h"
#include "llemojihelper.h"
#include "lllocalcliprect.h"
#include "llmenugl.h"
@@ -366,7 +367,7 @@ void LLTextBase::onValueChange(S32 start, S32 end)
{
}
-std::vector<LLRect> LLTextBase::getSelctionRects()
+std::vector<LLRect> LLTextBase::getSelectionRects()
{
// Nor supposed to be called without selection
llassert(hasSelection());
@@ -463,7 +464,7 @@ void LLTextBase::drawSelectionBackground()
// Draw selection even if we don't have keyboard focus for search/replace
if (hasSelection() && !mLineInfoList.empty())
{
- std::vector<LLRect> selection_rects = getSelctionRects();
+ std::vector<LLRect> selection_rects = getSelectionRects();
// Draw the selection box (we're using a box instead of reversing the colors on the selected text).
gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
@@ -904,9 +905,12 @@ S32 LLTextBase::insertStringNoUndo(S32 pos, const LLWString &wstr, LLTextBase::s
// Insert special segments where necessary (insertSegment takes care of splitting normal text segments around them for us)
{
LLStyleSP emoji_style;
+ LLEmojiDictionary* ed = LLEmojiDictionary::instanceExists() ? LLEmojiDictionary::getInstance() : NULL;
for (S32 text_kitty = 0, text_len = wstr.size(); text_kitty < text_len; text_kitty++)
{
- if (LLStringOps::isEmoji(wstr[text_kitty]))
+ llwchar code = wstr[text_kitty];
+ bool isEmoji = ed ? ed->isEmoji(code) : LLStringOps::isEmoji(code);
+ if (isEmoji)
{
if (!emoji_style)
{
@@ -2181,8 +2185,8 @@ void LLTextBase::appendTextImpl(const std::string &new_text, const LLStyle::Para
S32 start=0,end=0;
LLUrlMatch match;
std::string text = new_text;
- while ( LLUrlRegistry::instance().findUrl(text, match,
- boost::bind(&LLTextBase::replaceUrl, this, _1, _2, _3),isContentTrusted() || mAlwaysShowIcons))
+ while (LLUrlRegistry::instance().findUrl(text, match,
+ boost::bind(&LLTextBase::replaceUrl, this, _1, _2, _3), isContentTrusted() || mAlwaysShowIcons))
{
start = match.getStart();
end = match.getEnd()+1;
@@ -2430,18 +2434,18 @@ void LLTextBase::appendAndHighlightTextImpl(const std::string &new_text, S32 hig
LLStyle::Params normal_style_params(style_params);
normal_style_params.font.style("NORMAL");
LLStyleConstSP normal_sp(new LLStyle(normal_style_params));
- segments.push_back(new LLOnHoverChangeableTextSegment(sp, normal_sp, segment_start, segment_end, *this ));
+ segments.push_back(new LLOnHoverChangeableTextSegment(sp, normal_sp, segment_start, segment_end, *this));
}
else
{
- segments.push_back(new LLNormalTextSegment(sp, segment_start, segment_end, *this ));
+ segments.push_back(new LLNormalTextSegment(sp, segment_start, segment_end, *this));
}
insertStringNoUndo(getLength(), wide_text, &segments);
}
// Set the cursor and scroll position
- if( selection_start != selection_end )
+ if (selection_start != selection_end)
{
mSelectionStart = selection_start;
mSelectionEnd = selection_end;
@@ -2449,7 +2453,7 @@ void LLTextBase::appendAndHighlightTextImpl(const std::string &new_text, S32 hig
mIsSelecting = was_selecting;
setCursorPos(cursor_pos);
}
- else if( cursor_was_at_end )
+ else if (cursor_was_at_end)
{
setCursorPos(getLength());
}
@@ -2461,25 +2465,28 @@ void LLTextBase::appendAndHighlightTextImpl(const std::string &new_text, S32 hig
void LLTextBase::appendAndHighlightText(const std::string &new_text, S32 highlight_part, const LLStyle::Params& style_params, bool underline_on_hover_only)
{
- if (new_text.empty()) return;
+ if (new_text.empty())
+ {
+ return;
+ }
std::string::size_type start = 0;
- std::string::size_type pos = new_text.find("\n",start);
+ std::string::size_type pos = new_text.find("\n", start);
- while(pos!=-1)
+ while (pos != std::string::npos)
{
- if(pos!=start)
+ if (pos != start)
{
std::string str = std::string(new_text,start,pos-start);
- appendAndHighlightTextImpl(str,highlight_part, style_params, underline_on_hover_only);
+ appendAndHighlightTextImpl(str, highlight_part, style_params, underline_on_hover_only);
}
appendLineBreakSegment(style_params);
start = pos+1;
- pos = new_text.find("\n",start);
+ pos = new_text.find("\n", start);
}
- std::string str = std::string(new_text,start,new_text.length()-start);
- appendAndHighlightTextImpl(str,highlight_part, style_params, underline_on_hover_only);
+ std::string str = std::string(new_text, start, new_text.length() - start);
+ appendAndHighlightTextImpl(str, highlight_part, style_params, underline_on_hover_only);
}
diff --git a/indra/llui/lltextbase.h b/indra/llui/lltextbase.h
index 9b3691e404..37ab798a1d 100644
--- a/indra/llui/lltextbase.h
+++ b/indra/llui/lltextbase.h
@@ -654,7 +654,7 @@ protected:
return mLabel.getString() + getToolTip();
}
- std::vector<LLRect> getSelctionRects();
+ std::vector<LLRect> getSelectionRects();
protected:
// text segmentation and flow