mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-07 23:53:58 +02:00
Fix text selection in recent actions.
This commit is contained in:
parent
6cb01998cc
commit
1ee9122660
2 changed files with 32 additions and 12 deletions
|
@ -1606,7 +1606,8 @@ TextState Message::textState(
|
||||||
result = entry->textState(
|
result = entry->textState(
|
||||||
point - QPoint(entryLeft, entryTop),
|
point - QPoint(entryLeft, entryTop),
|
||||||
request);
|
request);
|
||||||
result.symbol += text().length() + (mediaDisplayed ? media->fullSelectionLength() : 0);
|
result.symbol += visibleTextLength()
|
||||||
|
+ visibleMediaTextLength();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1624,7 +1625,7 @@ TextState Message::textState(
|
||||||
result = bottomInfoResult;
|
result = bottomInfoResult;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if (inBubble) {
|
if (!result.symbol && inBubble) {
|
||||||
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();
|
||||||
|
@ -1632,18 +1633,18 @@ 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 += text().length();
|
result.symbol += visibleTextLength();
|
||||||
} else if (getStateText(point, trect, &result, request)) {
|
} else if (getStateText(point, trect, &result, request)) {
|
||||||
checkBottomInfoState();
|
checkBottomInfoState();
|
||||||
return result;
|
return result;
|
||||||
} else if (point.y() >= trect.y() + trect.height()) {
|
} else if (point.y() >= trect.y() + trect.height()) {
|
||||||
result.symbol = text().length();
|
result.symbol = visibleTextLength();
|
||||||
}
|
}
|
||||||
} else if (getStateText(point, trect, &result, request)) {
|
} else if (getStateText(point, trect, &result, request)) {
|
||||||
checkBottomInfoState();
|
checkBottomInfoState();
|
||||||
return result;
|
return result;
|
||||||
} else if (point.y() >= trect.y() + trect.height()) {
|
} else if (point.y() >= trect.y() + trect.height()) {
|
||||||
result.symbol = text().length();
|
result.symbol = visibleTextLength();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
checkBottomInfoState();
|
checkBottomInfoState();
|
||||||
|
@ -1665,7 +1666,7 @@ TextState Message::textState(
|
||||||
}
|
}
|
||||||
} else if (media && media->isDisplayed()) {
|
} else if (media && media->isDisplayed()) {
|
||||||
result = media->textState(point - g.topLeft(), request);
|
result = media->textState(point - g.topLeft(), request);
|
||||||
result.symbol += text().length();
|
result.symbol += visibleTextLength();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (keyboard && item->isHistoryEntry()) {
|
if (keyboard && item->isHistoryEntry()) {
|
||||||
|
@ -2002,7 +2003,9 @@ void Message::updatePressed(QPoint point) {
|
||||||
TextForMimeData Message::selectedText(TextSelection selection) const {
|
TextForMimeData Message::selectedText(TextSelection selection) const {
|
||||||
const auto media = this->media();
|
const auto media = this->media();
|
||||||
auto logEntryOriginalResult = TextForMimeData();
|
auto logEntryOriginalResult = TextForMimeData();
|
||||||
auto textResult = text().toTextForMimeData(selection);
|
auto textResult = hasVisibleText()
|
||||||
|
? text().toTextForMimeData(selection)
|
||||||
|
: TextForMimeData();
|
||||||
auto skipped = skipTextSelection(selection);
|
auto skipped = skipTextSelection(selection);
|
||||||
auto mediaDisplayed = (media && media->isDisplayed());
|
auto mediaDisplayed = (media && media->isDisplayed());
|
||||||
auto mediaResult = (mediaDisplayed || isHiddenByGroup())
|
auto mediaResult = (mediaDisplayed || isHiddenByGroup())
|
||||||
|
@ -2033,8 +2036,10 @@ TextSelection Message::adjustSelection(
|
||||||
TextSelectType type) const {
|
TextSelectType type) const {
|
||||||
const auto media = this->media();
|
const auto media = this->media();
|
||||||
|
|
||||||
auto result = text().adjustSelection(selection, type);
|
auto result = hasVisibleText()
|
||||||
auto beforeMediaLength = text().length();
|
? text().adjustSelection(selection, type)
|
||||||
|
: selection;
|
||||||
|
auto beforeMediaLength = visibleTextLength();
|
||||||
if (selection.to <= beforeMediaLength) {
|
if (selection.to <= beforeMediaLength) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -2048,8 +2053,7 @@ TextSelection Message::adjustSelection(
|
||||||
result.to = mediaSelection.to;
|
result.to = mediaSelection.to;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
auto beforeEntryLength = beforeMediaLength
|
auto beforeEntryLength = beforeMediaLength + visibleMediaTextLength();
|
||||||
+ (mediaDisplayed ? media->fullSelectionLength() : 0);
|
|
||||||
if (selection.to <= beforeEntryLength) {
|
if (selection.to <= beforeEntryLength) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -2887,13 +2891,16 @@ void Message::fromNameUpdated(int width) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
TextSelection Message::skipTextSelection(TextSelection selection) const {
|
TextSelection Message::skipTextSelection(TextSelection selection) const {
|
||||||
if (selection.from == 0xFFFF) {
|
if (selection.from == 0xFFFF || !hasVisibleText()) {
|
||||||
return selection;
|
return selection;
|
||||||
}
|
}
|
||||||
return HistoryView::UnshiftItemSelection(selection, text());
|
return HistoryView::UnshiftItemSelection(selection, text());
|
||||||
}
|
}
|
||||||
|
|
||||||
TextSelection Message::unskipTextSelection(TextSelection selection) const {
|
TextSelection Message::unskipTextSelection(TextSelection selection) const {
|
||||||
|
if (!hasVisibleText()) {
|
||||||
|
return selection;
|
||||||
|
}
|
||||||
return HistoryView::ShiftItemSelection(selection, text());
|
return HistoryView::ShiftItemSelection(selection, text());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3160,6 +3167,17 @@ bool Message::hasVisibleText() const {
|
||||||
return !media || !media->hideMessageText();
|
return !media || !media->hideMessageText();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Message::visibleTextLength() const {
|
||||||
|
return hasVisibleText() ? text().length() : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Message::visibleMediaTextLength() const {
|
||||||
|
const auto media = this->media();
|
||||||
|
return (media && media->isDisplayed())
|
||||||
|
? media->fullSelectionLength()
|
||||||
|
: 0;
|
||||||
|
}
|
||||||
|
|
||||||
QSize Message::performCountCurrentSize(int newWidth) {
|
QSize Message::performCountCurrentSize(int newWidth) {
|
||||||
const auto newHeight = resizeContentGetHeight(newWidth);
|
const auto newHeight = resizeContentGetHeight(newWidth);
|
||||||
|
|
||||||
|
|
|
@ -226,6 +226,8 @@ private:
|
||||||
QSize performCountOptimalSize() override;
|
QSize performCountOptimalSize() override;
|
||||||
QSize performCountCurrentSize(int newWidth) override;
|
QSize performCountCurrentSize(int newWidth) override;
|
||||||
bool hasVisibleText() const override;
|
bool hasVisibleText() const override;
|
||||||
|
[[nodiscard]] int visibleTextLength() const;
|
||||||
|
[[nodiscard]] int visibleMediaTextLength() const;
|
||||||
[[nodiscard]] bool needInfoDisplay() const;
|
[[nodiscard]] bool needInfoDisplay() const;
|
||||||
|
|
||||||
[[nodiscard]] bool isPinnedContext() const;
|
[[nodiscard]] bool isPinnedContext() const;
|
||||||
|
|
Loading…
Add table
Reference in a new issue