Add emoji helper support to LLTextEditor

meow-7.2.2
Kitty Barnett 2022-10-23 16:18:22 +02:00
parent dad25bcb1e
commit 3acb4caa0f
2 changed files with 20 additions and 3 deletions

View File

@ -676,6 +676,21 @@ void LLTextEditor::selectByCursorPosition(S32 prev_cursor_pos, S32 next_cursor_p
endSelection();
}
void LLTextEditor::handleEmojiCommit(const LLWString& wstr)
{
LLWString wtext(getWText()); S32 shortCodePos;
if (LLEmojiHelper::isCursorInEmojiCode(wtext, mCursorPos, &shortCodePos))
{
remove(shortCodePos, mCursorPos - shortCodePos, true);
auto styleParams = LLStyle::Params();
styleParams.font = LLFontGL::getFontEmoji();
insert(shortCodePos, wstr, false, new LLEmojiTextSegment(new LLStyle(styleParams), shortCodePos, shortCodePos + wstr.size(), *this));
setCursorPos(shortCodePos + 1);
}
}
BOOL LLTextEditor::handleMouseDown(S32 x, S32 y, MASK mask)
{
BOOL handled = FALSE;
@ -1147,9 +1162,9 @@ void LLTextEditor::addChar(llwchar wc)
LLWString wtext(getWText()); S32 shortCodePos;
if (LLEmojiHelper::isCursorInEmojiCode(wtext, mCursorPos, &shortCodePos))
{
const LLRect cursorRect = getLocalRectFromDocIndex(mCursorPos);
const LLWString shortCode = wtext.substr(shortCodePos, mCursorPos);
LLEmojiHelper::instance().showHelper(this, cursorRect.mLeft, cursorRect.mTop, wstring_to_utf8str(shortCode));
const LLRect cursorRect = getLocalRectFromDocIndex(mCursorPos - 1);
const LLWString shortCode = wtext.substr(shortCodePos, mCursorPos - shortCodePos);
LLEmojiHelper::instance().showHelper(this, cursorRect.mLeft, cursorRect.mTop, wstring_to_utf8str(shortCode), std::bind(&LLTextEditor::handleEmojiCommit, this, std::placeholders::_1));
}
}

View File

@ -92,6 +92,8 @@ public:
static S32 spacesPerTab();
void handleEmojiCommit(const LLWString& wstr);
// mousehandler overrides
virtual BOOL handleMouseDown(S32 x, S32 y, MASK mask);
virtual BOOL handleMouseUp(S32 x, S32 y, MASK mask);