Fix double click to select full words (#5243)

Co-authored-by: Rasmus Karlsson <rasmus.karlsson@pajlada.com>
This commit is contained in:
KleberPF
2024-03-17 10:43:55 -03:00
committed by GitHub
parent 46c5609736
commit c10e364e06
11 changed files with 224 additions and 22 deletions
+20 -1
View File
@@ -443,12 +443,31 @@ void MessageLayout::deleteCache()
// returns nullptr if none was found
// fourtf: this should return a MessageLayoutItem
const MessageLayoutElement *MessageLayout::getElementAt(QPoint point)
const MessageLayoutElement *MessageLayout::getElementAt(QPoint point) const
{
// go through all words and return the first one that contains the point.
return this->container_.getElementAt(point);
}
std::pair<int, int> MessageLayout::getWordBounds(
const MessageLayoutElement *hoveredElement, QPoint relativePos) const
{
// An element with wordId != -1 can be multiline, so we need to check all
// elements in the container
if (hoveredElement->getWordId() != -1)
{
return this->container_.getWordBounds(hoveredElement);
}
const auto wordStart = this->getSelectionIndex(relativePos) -
hoveredElement->getMouseOverIndex(relativePos);
const auto selectionLength = hoveredElement->getSelectionIndexCount();
const auto length = hoveredElement->hasTrailingSpace() ? selectionLength - 1
: selectionLength;
return {wordStart, wordStart + length};
}
size_t MessageLayout::getLastCharacterIndex() const
{
return this->container_.getLastCharacterIndex();