diff options
| author | Jonathan "Geenz" Goodman <geenz@lindenlab.com> | 2026-08-17 20:30:20 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-08-17 20:30:20 -0400 |
| commit | 18648fc51e2a0c750182d8aa3814ed5b6bf8445e (patch) | |
| tree | 0517959512fc0d6876780641da88b74dd72aec5b /indra/llui/lltextbase.cpp | |
| parent | 6d4c4c029ce43aa413266135829cd2bc00001890 (diff) | |
| parent | 932e8ac318eb2e29ea519249348315b50c7d1d58 (diff) | |
Merge pull request #5638 from secondlife/release/26.3
Release/26.3
Diffstat (limited to 'indra/llui/lltextbase.cpp')
| -rw-r--r-- | indra/llui/lltextbase.cpp | 81 |
1 files changed, 60 insertions, 21 deletions
diff --git a/indra/llui/lltextbase.cpp b/indra/llui/lltextbase.cpp index 5882c1edbb..0521853b02 100644 --- a/indra/llui/lltextbase.cpp +++ b/indra/llui/lltextbase.cpp @@ -225,6 +225,7 @@ LLTextBase::LLTextBase(const LLTextBase::Params &p) mTrustedContent(p.trusted_content), mAlwaysShowIcons(p.always_show_icons), mTrackEnd( p.track_end ), + mTrackValueChange(true), mScrollIndex(-1), mSelectionStart( 0 ), mSelectionEnd( 0 ), @@ -967,7 +968,10 @@ void LLTextBase::drawText() S32 LLTextBase::insertStringNoUndo(S32 pos, const LLWString &wstr, LLTextBase::segment_vec_t* segments ) { - beforeValueChange(); + if (mTrackValueChange) + { + beforeValueChange(); + } S32 old_len = getLength(); // length() returns character length S32 insert_len = static_cast<S32>(wstr.length()); @@ -1090,12 +1094,14 @@ S32 LLTextBase::insertStringNoUndo(S32 pos, const LLWString &wstr, LLTextBase::s getViewModel()->getEditableDisplay().insert(pos, wstr); - if ( truncate() ) + if (mTrackValueChange) { - insert_len = getLength() - old_len; + if (truncate()) + { + insert_len = getLength() - old_len; + } + onValueChange(pos, pos + insert_len); } - - onValueChange(pos, pos + insert_len); needsReflow(pos); return insert_len; @@ -1111,7 +1117,10 @@ S32 LLTextBase::removeStringNoUndo(S32 pos, S32 length) // Clamp length to not go past the end of the text length = std::min(length, text_length - pos); - beforeValueChange(); + if (mTrackValueChange) + { + beforeValueChange(); + } segment_set_t::iterator seg_iter = getSegIterContaining(pos); while(seg_iter != mSegments.end()) { @@ -1162,7 +1171,10 @@ S32 LLTextBase::removeStringNoUndo(S32 pos, S32 length) // recreate default segment in case we erased everything createDefaultSegment(); - onValueChange(pos, pos); + if (mTrackValueChange) + { + onValueChange(pos, pos); + } needsReflow(pos); return -length; // This will be wrong if someone calls removeStringNoUndo with an excessive length @@ -1170,7 +1182,10 @@ S32 LLTextBase::removeStringNoUndo(S32 pos, S32 length) S32 LLTextBase::overwriteCharNoUndo(S32 pos, llwchar wc) { - beforeValueChange(); + if (mTrackValueChange) + { + beforeValueChange(); + } if (pos > (S32)getLength()) { @@ -1178,7 +1193,10 @@ S32 LLTextBase::overwriteCharNoUndo(S32 pos, llwchar wc) } getViewModel()->getEditableDisplay()[pos] = wc; - onValueChange(pos, pos + 1); + if (mTrackValueChange) + { + onValueChange(pos, pos + 1); + } needsReflow(pos); return 1; @@ -1625,7 +1643,7 @@ void LLTextBase::deselect() bool LLTextBase::getSpellCheck() const { - return (LLSpellChecker::getUseSpellCheck()) && (!mReadOnly) && (mSpellCheck); + return (!mReadOnly) && (LLSpellChecker::getUseSpellCheck()) && (mSpellCheck); } const std::string& LLTextBase::getSuggestion(U32 index) const @@ -2333,6 +2351,10 @@ void LLTextBase::createUrlContextMenu(S32 x, S32 y, const std::string &in_url) void LLTextBase::setText(const LLStringExplicit &utf8str, const LLStyle::Params& input_params) { + beforeValueChange(); + // Can insert a lot of different segments, don't want to spam events. + mTrackValueChange = false; + // clear out the existing text and segments getViewModel()->setDisplay(LLWStringUtil::null); @@ -2353,6 +2375,8 @@ void LLTextBase::setText(const LLStringExplicit &utf8str, const LLStyle::Params& startOfDoc(); } + truncate(); // was postponed to avoid micro truncations and expensive checks + mTrackValueChange = true; onValueChange(0, getLength()); } @@ -2383,6 +2407,10 @@ void LLTextBase::appendTextImpl(const std::string& new_text, const LLStyle::Para LLStyle::Params style_params(getStyleParams()); style_params.overwriteFrom(input_params); + // todo: this does not check for maximum size, might + // want to stop once maximum size was reached to avoid + // expensive findUrl, replaceUrl calls. + S32 part = (S32)LLTextParser::WHOLE; if ((mParseHTML || force_slurl) && !style_params.is_link) // Don't search for URLs inside a link segment (STORM-358). { @@ -2556,6 +2584,10 @@ void LLTextBase::copyContents(const LLTextBase* source) beforeValueChange(); deselect(); + // Can insert a lot of different segments, don't want to spam events. + // Do one full length onValueChange() at the end of this function. + mTrackValueChange = false; + mSegments.clear(); for (const LLTextSegmentPtr& segp : source->mSegments) { @@ -2570,6 +2602,8 @@ void LLTextBase::copyContents(const LLTextBase* source) getViewModel()->setDisplay(source->getViewModel()->getDisplay()); + truncate(); // was postponed to avoid micro truncations and expensive checks + mTrackValueChange = true; onValueChange(0, getLength()); needsReflow(); } @@ -2824,7 +2858,7 @@ S32 LLTextBase::getDocIndexFromLocalCoord( S32 local_x, S32 local_y, bool round, line_seg_iter != mSegments.end(); ++line_seg_iter, line_seg_offset = 0) { - const LLTextSegmentPtr segmentp = *line_seg_iter; + LLTextSegmentPtr segmentp = *line_seg_iter; S32 segment_line_start = segmentp->getStart() + line_seg_offset; S32 segment_line_length = llmin(segmentp->getEnd(), line_iter->mDocIndexEnd) - segment_line_start; @@ -2915,7 +2949,7 @@ LLRect LLTextBase::getDocRectFromDocIndex(S32 pos) const while(line_seg_iter != mSegments.end()) { - const LLTextSegmentPtr segmentp = *line_seg_iter; + LLTextSegmentPtr segmentp = *line_seg_iter; if (line_seg_iter == cursor_seg_iter) { @@ -3466,8 +3500,8 @@ LLStyleSP LLTextSegment::cloneStyle(LLTextBase& target, const LLStyle* source) } -bool LLTextSegment::getDimensionsF32(S32 first_char, S32 num_chars, F32& width, S32& height) const { width = 0; height = 0; return false; } -bool LLTextSegment::getDimensions(S32 first_char, S32 num_chars, S32& width, S32& height) const +bool LLTextSegment::getDimensionsF32(S32 first_char, S32 num_chars, F32& width, S32& height) { width = 0; height = 0; return false; } +bool LLTextSegment::getDimensions(S32 first_char, S32 num_chars, S32& width, S32& height) { F32 fwidth = 0; bool result = getDimensionsF32(first_char, num_chars, fwidth, height); @@ -3564,6 +3598,7 @@ F32 LLNormalTextSegment::draw(S32 start, S32 end, S32 selection_start, S32 selec mFontBufferPreSelection.reset(); mFontBufferSelection.reset(); mFontBufferPostSelection.reset(); + mFontWidthBuffer.reset(); } return draw_rect.mLeft; } @@ -3589,6 +3624,7 @@ F32 LLNormalTextSegment::drawClippedSegment(S32 seg_start, S32 seg_end, S32 sele mFontBufferPreSelection.reset(); mFontBufferSelection.reset(); mFontBufferPostSelection.reset(); + mFontWidthBuffer.reset(); } const LLFontGL* font = mStyle->getFont(); @@ -3820,17 +3856,19 @@ LLTextSegmentPtr LLNormalTextSegment::clone(LLTextBase& target) const return new LLNormalTextSegment(sp, mStart, mEnd, target); } -bool LLNormalTextSegment::getDimensionsF32(S32 first_char, S32 num_chars, F32& width, S32& height) const +bool LLNormalTextSegment::getDimensionsF32(S32 first_char, S32 num_chars, F32& width, S32& height) { height = 0; width = 0; if (num_chars > 0 && (mStart + first_char >= 0)) { height = mFontHeight; - const LLWString &text = getWText(); - // if last character is a newline, then return true, forcing line break - width = mStyle->getFont()->getWidthF32(text.c_str(), mStart + first_char, num_chars, true); + + const LLWString& text = getWText(); + const LLFontGL* font = mStyle->getFont(); + width += mFontWidthBuffer.getWidth(font, text.c_str(), mStart + first_char, num_chars, true); } + // if last character is a newline, then return true, forcing line break return false; } @@ -3912,6 +3950,7 @@ void LLNormalTextSegment::updateLayout(const class LLTextBase& editor) mFontBufferPreSelection.reset(); mFontBufferSelection.reset(); mFontBufferPostSelection.reset(); + mFontWidthBuffer.reset(); } void LLNormalTextSegment::dump() const @@ -4063,7 +4102,7 @@ LLTextSegmentPtr LLInlineViewSegment::clone(LLTextBase& target) const return nullptr; } -bool LLInlineViewSegment::getDimensionsF32(S32 first_char, S32 num_chars, F32& width, S32& height) const +bool LLInlineViewSegment::getDimensionsF32(S32 first_char, S32 num_chars, F32& width, S32& height) { if (first_char == 0 && num_chars == 0) { @@ -4155,7 +4194,7 @@ LLTextSegmentPtr LLLineBreakTextSegment::clone(LLTextBase& target) const copy->mFontHeight = mFontHeight; return copy; } -bool LLLineBreakTextSegment::getDimensionsF32(S32 first_char, S32 num_chars, F32& width, S32& height) const +bool LLLineBreakTextSegment::getDimensionsF32(S32 first_char, S32 num_chars, F32& width, S32& height) { width = 0; height = mFontHeight; @@ -4192,7 +4231,7 @@ LLTextSegmentPtr LLImageTextSegment::clone(LLTextBase& target) const static const S32 IMAGE_HPAD = 3; // virtual -bool LLImageTextSegment::getDimensionsF32(S32 first_char, S32 num_chars, F32& width, S32& height) const +bool LLImageTextSegment::getDimensionsF32(S32 first_char, S32 num_chars, F32& width, S32& height) { width = 0; height = mStyle->getFont()->getLineHeight(); |
