Fix double click to select full words (#5243)
Co-authored-by: Rasmus Karlsson <rasmus.karlsson@pajlada.com>
This commit is contained in:
@@ -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_);
|
||||
|
||||
Reference in New Issue
Block a user