Fix a text editor bug with selection being lost when url segments updated

By doing it the right way, and calculating where the selection should be
after the change is applied.
Also no longer consider text editor modified if nothing was changed.
Also update cursor position so it doesn't move to the wrong place on update
This commit is contained in:
Lirusaito
2019-03-26 05:09:21 -04:00
parent f2b39196a0
commit 7be177e9ab

View File

@@ -4477,9 +4477,22 @@ void LLTextEditor::replaceUrl(const std::string &url,
{
S32 start = seg->getStart();
S32 end = seg->getEnd();
text = text.substr(0, start) + wlabel + text.substr(end, text.size() - end + 1);
seg->setEnd(start + wlabel.size());
modified = true;
const auto& old_label = text.substr(start, end - start);
if (wlabel != old_label)
{
const auto difference = std::abs((S32)wlabel.length() - (S32)old_label.length());
if (mSelectionEnd >= end) // Selection stays at/after end
{
mSelectionEnd += difference;
if (mSelectionStart >= end)
mSelectionStart += difference;
}
if (mCursorPos >= end) // Cursor stays at/after end
mCursorPos += difference;
text.replace(start, end - start, wlabel);
seg->setEnd(start + wlabel.size());
modified = true;
}
}
/* Singu TODO: Icons with Urls?
@@ -4508,7 +4521,6 @@ void LLTextEditor::replaceUrl(const std::string &url,
{
mWText = text;
mTextIsUpToDate = FALSE;
deselect();
setCursorPos(mCursorPos);
needsReflow();
}