From 8694f055b64eb7ce13897e49afe73c4d3295a29a Mon Sep 17 00:00:00 2001 From: Kitty Barnett Date: Sun, 23 Oct 2022 16:09:30 +0200 Subject: Add emoji helper support to LLTextEditor --- indra/llui/lltexteditor.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'indra/llui/lltexteditor.cpp') diff --git a/indra/llui/lltexteditor.cpp b/indra/llui/lltexteditor.cpp index b1f8b00cab..889940cf9a 100644 --- a/indra/llui/lltexteditor.cpp +++ b/indra/llui/lltexteditor.cpp @@ -43,6 +43,7 @@ #include "llmath.h" #include "llclipboard.h" +#include "llemojihelper.h" #include "llscrollbar.h" #include "llstl.h" #include "llstring.h" @@ -238,6 +239,7 @@ LLTextEditor::Params::Params() default_color("default_color"), commit_on_focus_lost("commit_on_focus_lost", false), show_context_menu("show_context_menu"), + show_emoji_helper("show_emoji_helper"), enable_tooltip_paste("enable_tooltip_paste") { addSynonym(prevalidate_callback, "text_type"); @@ -259,6 +261,7 @@ LLTextEditor::LLTextEditor(const LLTextEditor::Params& p) : mPrevalidateFunc(p.prevalidate_callback()), mContextMenu(NULL), mShowContextMenu(p.show_context_menu), + mShowEmojiHelper(p.show_emoji_helper), mEnableTooltipPaste(p.enable_tooltip_paste), mPassDelete(FALSE), mKeepSelectionOnReturn(false) @@ -501,6 +504,15 @@ void LLTextEditor::getSegmentsInRange(LLTextEditor::segment_vec_t& segments_out, } } +void LLTextEditor::setShowEmojiHelper(bool show) { + if (!mShowEmojiHelper) + { + LLEmojiHelper::instance().hideHelper(this); + } + + mShowEmojiHelper = show; +} + BOOL LLTextEditor::selectionContainsLineBreaks() { if (hasSelection()) @@ -930,6 +942,12 @@ BOOL LLTextEditor::handleDoubleClick(S32 x, S32 y, MASK mask) S32 LLTextEditor::execute( TextCmd* cmd ) { + if (!mReadOnly && mShowEmojiHelper) + { + // Any change to our contents should always hide the helper + LLEmojiHelper::instance().hideHelper(this); + } + S32 delta = 0; if( cmd->execute(this, &delta) ) { @@ -1124,6 +1142,17 @@ void LLTextEditor::addChar(llwchar wc) setCursorPos(mCursorPos + addChar( mCursorPos, wc )); + if (!mReadOnly && mShowEmojiHelper) + { + 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)); + } + } + if (!mReadOnly && mAutoreplaceCallback != NULL) { // autoreplace the text, if necessary @@ -1774,6 +1803,11 @@ BOOL LLTextEditor::handleKeyHere(KEY key, MASK mask ) } else { + if (!mReadOnly && mShowEmojiHelper && LLEmojiHelper::instance().handleKey(this, key, mask)) + { + return TRUE; + } + if (mEnableTooltipPaste && LLToolTipMgr::instance().toolTipVisible() && KEY_TAB == key) @@ -1815,6 +1849,12 @@ BOOL LLTextEditor::handleKeyHere(KEY key, MASK mask ) { resetCursorBlink(); needsScroll(); + + if (mShowEmojiHelper) + { + // Dismiss the helper whenever we handled a key that it didn't + LLEmojiHelper::instance().hideHelper(this); + } } return handled; -- cgit v1.2.3 From 3acb4caa0fb9d381be6cfbe1693ace389d90a16c Mon Sep 17 00:00:00 2001 From: Kitty Barnett Date: Sun, 23 Oct 2022 16:18:22 +0200 Subject: Add emoji helper support to LLTextEditor --- indra/llui/lltexteditor.cpp | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'indra/llui/lltexteditor.cpp') diff --git a/indra/llui/lltexteditor.cpp b/indra/llui/lltexteditor.cpp index 889940cf9a..168c260c7d 100644 --- a/indra/llui/lltexteditor.cpp +++ b/indra/llui/lltexteditor.cpp @@ -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)); } } -- cgit v1.2.3 From ff7ebf08922293c1623b7bdb8c9923c14fc9db48 Mon Sep 17 00:00:00 2001 From: Alexander Gavriliuk Date: Fri, 14 Apr 2023 07:44:56 +0200 Subject: SL-19575 Create emoji gallery access icon --- indra/llui/lltexteditor.cpp | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'indra/llui/lltexteditor.cpp') diff --git a/indra/llui/lltexteditor.cpp b/indra/llui/lltexteditor.cpp index a85ac2a5a3..95d8b666ab 100644 --- a/indra/llui/lltexteditor.cpp +++ b/indra/llui/lltexteditor.cpp @@ -680,18 +680,24 @@ void LLTextEditor::selectByCursorPosition(S32 prev_cursor_pos, S32 next_cursor_p endSelection(); } -void LLTextEditor::handleEmojiCommit(const LLWString& wstr) +void LLTextEditor::insertEmoji(llwchar emoji) { - LLWString wtext(getWText()); S32 shortCodePos; - if (LLEmojiHelper::isCursorInEmojiCode(wtext, mCursorPos, &shortCodePos)) + auto styleParams = LLStyle::Params(); + styleParams.font = LLFontGL::getFontEmoji(); + auto segment = new LLEmojiTextSegment(new LLStyle(styleParams), mCursorPos, mCursorPos + 1, *this); + insert(mCursorPos, LLWString(1, emoji), false, segment); + setCursorPos(mCursorPos + 1); +} + +void LLTextEditor::handleEmojiCommit(llwchar emoji) +{ + S32 shortCodePos; + if (LLEmojiHelper::isCursorInEmojiCode(getWText(), mCursorPos, &shortCodePos)) { remove(shortCodePos, mCursorPos - shortCodePos, true); + setCursorPos(shortCodePos); - 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); + insertEmoji(emoji); } } -- cgit v1.2.3 From f36f50462e226308424d57298aa29c4dccfef6e2 Mon Sep 17 00:00:00 2001 From: Alexander Gavriliuk Date: Mon, 2 Oct 2023 14:08:31 +0200 Subject: SL-20387 Show Emoji Completion floater at the beginning of the shortcode --- indra/llui/lltexteditor.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'indra/llui/lltexteditor.cpp') diff --git a/indra/llui/lltexteditor.cpp b/indra/llui/lltexteditor.cpp index 95d8b666ab..4467496146 100644 --- a/indra/llui/lltexteditor.cpp +++ b/indra/llui/lltexteditor.cpp @@ -1169,12 +1169,15 @@ void LLTextEditor::addChar(llwchar wc) if (!mReadOnly && mShowEmojiHelper) { - LLWString wtext(getWText()); S32 shortCodePos; + S32 shortCodePos; + LLWString wtext(getWText()); if (LLEmojiHelper::isCursorInEmojiCode(wtext, mCursorPos, &shortCodePos)) { - 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)); + const LLRect cursorRect(getLocalRectFromDocIndex(shortCodePos)); + const LLWString wpart(wtext.substr(shortCodePos, mCursorPos - shortCodePos)); + const std::string part(wstring_to_utf8str(wpart)); + auto cb = [this](llwchar emoji) { handleEmojiCommit(emoji); }; + LLEmojiHelper::instance().showHelper(this, cursorRect.mLeft, cursorRect.mTop, part, cb); } } -- cgit v1.2.3 From c3adae2a5ff3912ffb741b84a5d098d078da062b Mon Sep 17 00:00:00 2001 From: Alexander Gavriliuk Date: Mon, 2 Oct 2023 15:09:39 +0200 Subject: SL-20391 Show Emoji Completion floater after backspacing a character --- indra/llui/lltexteditor.cpp | 53 ++++++++++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 22 deletions(-) (limited to 'indra/llui/lltexteditor.cpp') diff --git a/indra/llui/lltexteditor.cpp b/indra/llui/lltexteditor.cpp index 4467496146..7aef056e5a 100644 --- a/indra/llui/lltexteditor.cpp +++ b/indra/llui/lltexteditor.cpp @@ -1022,7 +1022,7 @@ S32 LLTextEditor::remove(S32 pos, S32 length, bool group_with_next_op) // store text segments getSegmentsInRange(segments_to_remove, pos, pos + length, false); - if(pos <= end_pos) + if (pos <= end_pos) { removedChar = execute( new TextCmdRemove( pos, group_with_next_op, end_pos - pos, segments_to_remove ) ); } @@ -1046,11 +1046,12 @@ S32 LLTextEditor::overwriteChar(S32 pos, llwchar wc) // a pseudo-tab (up to for spaces in a row) void LLTextEditor::removeCharOrTab() { - if( !getEnabled() ) + if (!getEnabled()) { return; } - if( mCursorPos > 0 ) + + if (mCursorPos > 0) { S32 chars_to_remove = 1; @@ -1062,14 +1063,14 @@ void LLTextEditor::removeCharOrTab() if (offset > 0) { chars_to_remove = offset % SPACES_PER_TAB; - if( chars_to_remove == 0 ) + if (chars_to_remove == 0) { chars_to_remove = SPACES_PER_TAB; } - for( S32 i = 0; i < chars_to_remove; i++ ) + for (S32 i = 0; i < chars_to_remove; i++) { - if (text[ mCursorPos - i - 1] != ' ') + if (text[mCursorPos - i - 1] != ' ') { // Fewer than a full tab's worth of spaces, so // just delete a single character. @@ -1083,8 +1084,10 @@ void LLTextEditor::removeCharOrTab() for (S32 i = 0; i < chars_to_remove; i++) { setCursorPos(mCursorPos - 1); - remove( mCursorPos, 1, FALSE ); + remove(mCursorPos, 1, false); } + + tryToShowEmojiHelper(); } else { @@ -1095,7 +1098,7 @@ void LLTextEditor::removeCharOrTab() // Remove a single character from the text S32 LLTextEditor::removeChar(S32 pos) { - return remove( pos, 1, FALSE ); + return remove(pos, 1, false); } void LLTextEditor::removeChar() @@ -1104,10 +1107,12 @@ void LLTextEditor::removeChar() { return; } + if (mCursorPos > 0) { setCursorPos(mCursorPos - 1); removeChar(mCursorPos); + tryToShowEmojiHelper(); } else { @@ -1166,20 +1171,7 @@ void LLTextEditor::addChar(llwchar wc) } setCursorPos(mCursorPos + addChar( mCursorPos, wc )); - - if (!mReadOnly && mShowEmojiHelper) - { - S32 shortCodePos; - LLWString wtext(getWText()); - if (LLEmojiHelper::isCursorInEmojiCode(wtext, mCursorPos, &shortCodePos)) - { - const LLRect cursorRect(getLocalRectFromDocIndex(shortCodePos)); - const LLWString wpart(wtext.substr(shortCodePos, mCursorPos - shortCodePos)); - const std::string part(wstring_to_utf8str(wpart)); - auto cb = [this](llwchar emoji) { handleEmojiCommit(emoji); }; - LLEmojiHelper::instance().showHelper(this, cursorRect.mLeft, cursorRect.mTop, part, cb); - } - } + tryToShowEmojiHelper(); if (!mReadOnly && mAutoreplaceCallback != NULL) { @@ -1199,6 +1191,23 @@ void LLTextEditor::addChar(llwchar wc) } } +void LLTextEditor::tryToShowEmojiHelper() +{ + if (mReadOnly || !mShowEmojiHelper) + return; + + S32 shortCodePos; + LLWString wtext(getWText()); + if (LLEmojiHelper::isCursorInEmojiCode(wtext, mCursorPos, &shortCodePos)) + { + const LLRect cursorRect(getLocalRectFromDocIndex(shortCodePos)); + const LLWString wpart(wtext.substr(shortCodePos, mCursorPos - shortCodePos)); + const std::string part(wstring_to_utf8str(wpart)); + auto cb = [this](llwchar emoji) { handleEmojiCommit(emoji); }; + LLEmojiHelper::instance().showHelper(this, cursorRect.mLeft, cursorRect.mTop, part, cb); + } +} + void LLTextEditor::addLineBreakChar(BOOL group_together) { if( !getEnabled() ) -- cgit v1.2.3 From 2fad5a770b3583e576992d075c24bc0e25443053 Mon Sep 17 00:00:00 2001 From: Alexander Gavriliuk Date: Thu, 30 Nov 2023 13:59:14 +0100 Subject: SL-19801 Log unicode characters for debug --- indra/llui/lltexteditor.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'indra/llui/lltexteditor.cpp') diff --git a/indra/llui/lltexteditor.cpp b/indra/llui/lltexteditor.cpp index 7aef056e5a..3910be1443 100644 --- a/indra/llui/lltexteditor.cpp +++ b/indra/llui/lltexteditor.cpp @@ -682,6 +682,7 @@ void LLTextEditor::selectByCursorPosition(S32 prev_cursor_pos, S32 next_cursor_p void LLTextEditor::insertEmoji(llwchar emoji) { + LL_INFOS() << "LLTextEditor::insertEmoji(" << wchar_utf8_preview(emoji) << ")" << LL_ENDL; auto styleParams = LLStyle::Params(); styleParams.font = LLFontGL::getFontEmoji(); auto segment = new LLEmojiTextSegment(new LLStyle(styleParams), mCursorPos, mCursorPos + 1, *this); -- cgit v1.2.3 From f6ceafee5bb26cf86d64959cabf68deefaf791a8 Mon Sep 17 00:00:00 2001 From: Alexander Gavriliuk Date: Mon, 22 Jan 2024 06:40:41 +0100 Subject: SL-20416 Avoid of taking focus by EmojiPicker --- indra/llui/lltexteditor.cpp | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'indra/llui/lltexteditor.cpp') diff --git a/indra/llui/lltexteditor.cpp b/indra/llui/lltexteditor.cpp index 3910be1443..092739a538 100644 --- a/indra/llui/lltexteditor.cpp +++ b/indra/llui/lltexteditor.cpp @@ -508,7 +508,8 @@ void LLTextEditor::getSegmentsInRange(LLTextEditor::segment_vec_t& segments_out, } } -void LLTextEditor::setShowEmojiHelper(bool show) { +void LLTextEditor::setShowEmojiHelper(bool show) +{ if (!mShowEmojiHelper) { LLEmojiHelper::instance().hideHelper(this); @@ -1192,6 +1193,16 @@ void LLTextEditor::addChar(llwchar wc) } } +void LLTextEditor::showEmojiHelper() +{ + if (mReadOnly || !mShowEmojiHelper) + return; + + const LLRect cursorRect(getLocalRectFromDocIndex(mCursorPos)); + auto cb = [this](llwchar emoji) { insertEmoji(emoji); }; + LLEmojiHelper::instance().showHelper(this, cursorRect.mLeft, cursorRect.mTop, LLStringUtil::null, cb); +} + void LLTextEditor::tryToShowEmojiHelper() { if (mReadOnly || !mShowEmojiHelper) @@ -1207,6 +1218,10 @@ void LLTextEditor::tryToShowEmojiHelper() auto cb = [this](llwchar emoji) { handleEmojiCommit(emoji); }; LLEmojiHelper::instance().showHelper(this, cursorRect.mLeft, cursorRect.mTop, part, cb); } + else + { + LLEmojiHelper::instance().hideHelper(); + } } void LLTextEditor::addLineBreakChar(BOOL group_together) @@ -1911,7 +1926,12 @@ BOOL LLTextEditor::handleUnicodeCharHere(llwchar uni_char) // Handle most keys only if the text editor is writeable. if( !mReadOnly ) { - if( mAutoIndent && '}' == uni_char ) + if (mShowEmojiHelper && uni_char < 0x80 && LLEmojiHelper::instance().handleKey(this, (KEY)uni_char, MASK_NONE)) + { + return TRUE; + } + + if( mAutoIndent && '}' == uni_char ) { unindentLineBeforeCloseBrace(); } -- cgit v1.2.3