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
+3 -19
View File
@@ -290,23 +290,6 @@ qreal highlightEasingFunction(qreal progress)
return 1.0 + pow((20.0 / 9.0) * (0.5 * progress - 0.5), 3.0);
}
/// @return the start and end of the word bounds
std::pair<int, int> getWordBounds(MessageLayout *layout,
const MessageLayoutElement *element,
const QPoint &relativePos)
{
assert(layout != nullptr);
assert(element != nullptr);
const auto wordStart = layout->getSelectionIndex(relativePos) -
element->getMouseOverIndex(relativePos);
const auto selectionLength = element->getSelectionIndexCount();
const auto length =
element->hasTrailingSpace() ? selectionLength - 1 : selectionLength;
return {wordStart, wordStart + length};
}
} // namespace
namespace chatterino {
@@ -1827,7 +1810,7 @@ void ChannelView::mouseMoveEvent(QMouseEvent *event)
if (this->isDoubleClick_ && hoverLayoutElement)
{
auto [wordStart, wordEnd] =
getWordBounds(layout.get(), hoverLayoutElement, relativePos);
layout->getWordBounds(hoverLayoutElement, relativePos);
auto hoveredWord = Selection{SelectionItem(messageIndex, wordStart),
SelectionItem(messageIndex, wordEnd)};
// combined selection spanning from initially selected word to hoveredWord
@@ -2657,7 +2640,8 @@ void ChannelView::mouseDoubleClickEvent(QMouseEvent *event)
}
auto [wordStart, wordEnd] =
getWordBounds(layout.get(), hoverLayoutElement, relativePos);
layout->getWordBounds(hoverLayoutElement, relativePos);
this->doubleClickSelection_ = {SelectionItem(messageIndex, wordStart),
SelectionItem(messageIndex, wordEnd)};
this->setSelection(this->doubleClickSelection_);