Skip to content

Commit

Permalink
Scroll quote selection in the draft options box.
Browse files Browse the repository at this point in the history
  • Loading branch information
john-preston committed Oct 3, 2024
1 parent 7d67b3d commit a8b0f29
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ class PreviewWrap final : public Ui::RpWidget {
const std::vector<MessageLinkRange> &links,
const QString &usedLink);

[[nodiscard]] rpl::producer<int> draggingScrollDelta() const {
return _draggingScrollDelta.events();
}

private:
void paintEvent(QPaintEvent *e) override;
void leaveEventHook(QEvent *e) override;
Expand All @@ -118,6 +122,11 @@ class PreviewWrap final : public Ui::RpWidget {
void mouseReleaseEvent(QMouseEvent *e) override;
void mouseDoubleClickEvent(QMouseEvent *e) override;

void visibleTopBottomUpdated(int top, int bottom) override {
_visibleTop = top;
_visibleBottom = bottom;
}

void initElement();
void highlightUsedLink(
const TextWithTags &message,
Expand All @@ -141,6 +150,9 @@ class PreviewWrap final : public Ui::RpWidget {
rpl::lifetime _elementLifetime;

QPoint _position;
rpl::event_stream<int> _draggingScrollDelta;
int _visibleTop = 0;
int _visibleBottom = 0;

base::Timer _trippleClickTimer;
ClickHandlerPtr _link;
Expand Down Expand Up @@ -423,9 +435,8 @@ void PreviewWrap::mouseMoveEvent(QMouseEvent *e) {
: Flag::LookupLink),
.onlyMessageText = (_section == Section::Link || _onlyMessageText),
};
auto resolved = _element->textState(
e->pos() - _position,
request);
const auto position = e->pos();
auto resolved = _element->textState(position - _position, request);
_over = true;
const auto text = (_section == Section::Reply)
&& (resolved.cursor == CursorState::Text);
Expand All @@ -450,6 +461,17 @@ void PreviewWrap::mouseMoveEvent(QMouseEvent *e) {
update();
}
}

_draggingScrollDelta.fire([&] {
if (!_selecting || _visibleTop >= _visibleBottom) {
return 0;
} else if (position.y() < _visibleTop) {
return position.y() - _visibleTop;
} else if (position.y() >= _visibleBottom) {
return position.y() + 1 - _visibleBottom;
}
return 0;
}());
}

void PreviewWrap::mousePressEvent(QMouseEvent *e) {
Expand Down Expand Up @@ -814,6 +836,11 @@ void DraftOptionsBox(
state->wrap = box->addRow(
object_ptr<PreviewWrap>(box, args.history),
{});
state->wrap->draggingScrollDelta(
) | rpl::start_with_next([=](int delta) {
box->scrollByDraggingDelta(delta);
}, state->wrap->lifetime());

const auto &linkRanges = args.links;
state->shown.value() | rpl::start_with_next([=](Section shown) {
bottom->clear();
Expand Down
23 changes: 16 additions & 7 deletions Telegram/SourceFiles/history/view/history_view_message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2400,8 +2400,10 @@ TextState Message::textState(
const auto media = this->media();

auto result = TextState(item);
const auto visibleMediaTextLen = visibleMediaTextLength();
const auto visibleTextLen = visibleTextLength();
const auto minSymbol = (_invertMedia && request.onlyMessageText)
? visibleMediaTextLength()
? visibleMediaTextLen
: 0;
result.symbol = minSymbol;

Expand All @@ -2428,6 +2430,7 @@ TextState Message::textState(
g.setHeight(g.height() - reactionsHeight);
const auto reactionsPosition = QPoint(reactionsLeft + g.left(), g.top() + g.height() + st::mediaInBubbleSkip);
if (_reactions->getState(point - reactionsPosition, &result)) {
result.symbol += visibleMediaTextLen + visibleTextLen;
return result;
}
}
Expand All @@ -2443,6 +2446,7 @@ TextState Message::textState(

auto inner = g;
if (getStateCommentsButton(point, inner, &result)) {
result.symbol += visibleMediaTextLen + visibleTextLen;
return result;
}
auto trect = inner.marginsRemoved(st::msgPadding);
Expand All @@ -2460,6 +2464,7 @@ TextState Message::textState(
trect.setHeight(trect.height() - reactionsHeight);
const auto reactionsPosition = QPoint(trect.left(), trect.top() + trect.height() + reactionsTop);
if (_reactions->getState(point - reactionsPosition, &result)) {
result.symbol += visibleMediaTextLen + visibleTextLen;
return result;
}
}
Expand All @@ -2475,6 +2480,7 @@ TextState Message::textState(
? inner
: inner - heightMargins),
&result)) {
result.symbol += visibleMediaTextLen + visibleTextLen;
return result;
}
if (belowInfo) {
Expand Down Expand Up @@ -2552,7 +2558,11 @@ TextState Message::textState(
result = bottomInfoResult;
}
};
if (result.symbol <= minSymbol && inBubble) {
if (!inBubble) {
if (point.y() >= g.y() + g.height()) {
result.symbol += visibleTextLen + visibleMediaTextLen;
}
} else if (result.symbol <= minSymbol) {
const auto mediaHeight = mediaDisplayed ? media->height() : 0;
const auto mediaLeft = trect.x() - st::msgPadding.left();
const auto mediaTop = (!mediaDisplayed || _invertMedia)
Expand All @@ -2575,22 +2585,21 @@ TextState Message::textState(
result.cursor = CursorState::None;
}
} else if (request.onlyMessageText) {
result.symbol = visibleTextLength();
result.symbol = visibleTextLen;
result.afterSymbol = false;
result.cursor = CursorState::None;
} else {
result.symbol += visibleTextLength();
result.symbol += visibleTextLen;
}
} else if (getStateText(point, trect, &result, request)) {
if (_invertMedia) {
result.symbol += visibleMediaTextLength();
result.symbol += visibleMediaTextLen;
}
result.overMessageText = true;
checkBottomInfoState();
return result;
} else if (point.y() >= trect.y() + trect.height()) {
result.symbol = visibleTextLength()
+ visibleMediaTextLength();
result.symbol = visibleTextLen + visibleMediaTextLen;
}
}
checkBottomInfoState();
Expand Down

0 comments on commit a8b0f29

Please sign in to comment.