mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-03-30 23:38:25 +00:00
Improve text selection in bubbles.
This commit is contained in:
parent
600737c44f
commit
681b9b5ba3
@ -739,11 +739,19 @@ TextState Message::textState(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto needDateCheck = mediaOnBottom
|
auto checkForPointInTime = [&] {
|
||||||
? !(entry
|
if (mediaOnBottom && (entry || media->customInfoLayout())) {
|
||||||
? entry->customInfoLayout()
|
return;
|
||||||
: media->customInfoLayout())
|
}
|
||||||
: true;
|
const auto inDate = pointInTime(
|
||||||
|
g.left() + g.width(),
|
||||||
|
g.top() + g.height(),
|
||||||
|
point,
|
||||||
|
InfoDisplayType::Default);
|
||||||
|
if (inDate) {
|
||||||
|
result.cursor = CursorState::Date;
|
||||||
|
}
|
||||||
|
};
|
||||||
if (mediaDisplayed) {
|
if (mediaDisplayed) {
|
||||||
auto mediaHeight = media->height();
|
auto mediaHeight = media->height();
|
||||||
auto mediaLeft = trect.x() - st::msgPadding.left();
|
auto mediaLeft = trect.x() - st::msgPadding.left();
|
||||||
@ -752,17 +760,19 @@ TextState Message::textState(
|
|||||||
if (point.y() >= mediaTop && point.y() < mediaTop + mediaHeight) {
|
if (point.y() >= mediaTop && point.y() < mediaTop + mediaHeight) {
|
||||||
result = media->textState(point - QPoint(mediaLeft, mediaTop), request);
|
result = media->textState(point - QPoint(mediaLeft, mediaTop), request);
|
||||||
result.symbol += item->_text.length();
|
result.symbol += item->_text.length();
|
||||||
} else if (trect.contains(point)) {
|
} else if (getStateText(point, trect, &result, request)) {
|
||||||
getStateText(point, trect, &result, request);
|
checkForPointInTime();
|
||||||
}
|
return result;
|
||||||
} else if (trect.contains(point)) {
|
} else if (point.y() >= trect.y() + trect.height()) {
|
||||||
getStateText(point, trect, &result, request);
|
result.symbol = item->_text.length();
|
||||||
}
|
|
||||||
if (needDateCheck) {
|
|
||||||
if (pointInTime(g.left() + g.width(), g.top() + g.height(), point, InfoDisplayType::Default)) {
|
|
||||||
result.cursor = CursorState::Date;
|
|
||||||
}
|
}
|
||||||
|
} else if (getStateText(point, trect, &result, request)) {
|
||||||
|
checkForPointInTime();
|
||||||
|
return result;
|
||||||
|
} else if (point.y() >= trect.y() + trect.height()) {
|
||||||
|
result.symbol = item->_text.length();
|
||||||
}
|
}
|
||||||
|
checkForPointInTime();
|
||||||
if (displayRightAction()) {
|
if (displayRightAction()) {
|
||||||
const auto fastShareSkip = snap(
|
const auto fastShareSkip = snap(
|
||||||
(g.height() - st::historyFastShareSize) / 2,
|
(g.height() - st::historyFastShareSize) / 2,
|
||||||
@ -921,7 +931,7 @@ bool Message::getStateText(
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const auto item = message();
|
const auto item = message();
|
||||||
if (trect.contains(point)) {
|
if (base::in_range(point.y(), trect.y(), trect.y() + trect.height())) {
|
||||||
*outResult = TextState(item, item->_text.getState(
|
*outResult = TextState(item, item->_text.getState(
|
||||||
point - trect.topLeft(),
|
point - trect.topLeft(),
|
||||||
trect.width(),
|
trect.width(),
|
||||||
|
@ -1184,12 +1184,16 @@ private:
|
|||||||
auto currentBlock = _t->_blocks[blockIndex].get();
|
auto currentBlock = _t->_blocks[blockIndex].get();
|
||||||
auto nextBlock = (++blockIndex < _blocksSize) ? _t->_blocks[blockIndex].get() : nullptr;
|
auto nextBlock = (++blockIndex < _blocksSize) ? _t->_blocks[blockIndex].get() : nullptr;
|
||||||
|
|
||||||
int32 delta = (currentBlock->from() < _lineStart ? qMin(_lineStart - currentBlock->from(), 2) : 0);
|
const auto extendLeft = (currentBlock->from() < _lineStart)
|
||||||
_localFrom = _lineStart - delta;
|
? qMin(_lineStart - currentBlock->from(), 2)
|
||||||
int32 lineEnd = (_endBlock && _endBlock->from() < trimmedLineEnd && !elidedLine) ? qMin(uint16(trimmedLineEnd + 2), _t->countBlockEnd(_endBlockIter, _end)) : trimmedLineEnd;
|
: 0;
|
||||||
|
_localFrom = _lineStart - extendLeft;
|
||||||
|
const auto extendedLineEnd = (_endBlock && _endBlock->from() < trimmedLineEnd && !elidedLine)
|
||||||
|
? qMin(uint16(trimmedLineEnd + 2), _t->countBlockEnd(_endBlockIter, _end))
|
||||||
|
: trimmedLineEnd;
|
||||||
|
|
||||||
auto lineText = _t->_text.mid(_localFrom, lineEnd - _localFrom);
|
auto lineText = _t->_text.mid(_localFrom, extendedLineEnd - _localFrom);
|
||||||
auto lineStart = delta;
|
auto lineStart = extendLeft;
|
||||||
auto lineLength = trimmedLineEnd - _lineStart;
|
auto lineLength = trimmedLineEnd - _lineStart;
|
||||||
|
|
||||||
if (elidedLine) {
|
if (elidedLine) {
|
||||||
@ -1241,21 +1245,30 @@ private:
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (_fullWidthSelection) {
|
if (_fullWidthSelection) {
|
||||||
bool selectFromStart = (_selection.to > _lineStart) && (_lineStart > 0) && (_selection.from <= _lineStart);
|
const auto selectFromStart = (_selection.to > _lineStart)
|
||||||
bool selectTillEnd = (_selection.to >= _lineEnd) && (_lineEnd < _t->_text.size()) && (_selection.from < _lineEnd) && (!_endBlock || _endBlock->type() != TextBlockTSkip);
|
&& (_lineStart > 0)
|
||||||
|
&& (_selection.from <= _lineStart);
|
||||||
|
const auto selectTillEnd = (_selection.to > trimmedLineEnd)
|
||||||
|
&& (trimmedLineEnd < _t->_text.size())
|
||||||
|
&& (_selection.from <= trimmedLineEnd)
|
||||||
|
&& (!_endBlock || _endBlock->type() != TextBlockTSkip);
|
||||||
|
|
||||||
if ((selectFromStart && _parDirection == Qt::LeftToRight) || (selectTillEnd && _parDirection == Qt::RightToLeft)) {
|
if ((selectFromStart && _parDirection == Qt::LeftToRight)
|
||||||
|
|| (selectTillEnd && _parDirection == Qt::RightToLeft)) {
|
||||||
if (x > _x) {
|
if (x > _x) {
|
||||||
fillSelectRange(_x, x);
|
fillSelectRange(_x, x);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((selectTillEnd && _parDirection == Qt::LeftToRight) || (selectFromStart && _parDirection == Qt::RightToLeft)) {
|
if ((selectTillEnd && _parDirection == Qt::LeftToRight)
|
||||||
|
|| (selectFromStart && _parDirection == Qt::RightToLeft)) {
|
||||||
if (x < _x + _wLeft) {
|
if (x < _x + _wLeft) {
|
||||||
fillSelectRange(x + _w - _wLeft, _x + _w);
|
fillSelectRange(x + _w - _wLeft, _x + _w);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (trimmedLineEnd == _lineStart && !elidedLine) return true;
|
if (trimmedLineEnd == _lineStart && !elidedLine) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if (!elidedLine) initParagraphBidi(); // if was not inited
|
if (!elidedLine) initParagraphBidi(); // if was not inited
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user