diff options
author | Marcus Tillmanns <marcus.tillmanns@qt.io> | 2023-03-09 22:33:47 +0100 |
---|---|---|
committer | Marcus Tillmanns <marcus.tillmanns@qt.io> | 2023-03-12 09:22:38 +0000 |
commit | 887f6afd258233c476bea1a34834a67e12a864c0 (patch) | |
tree | d32c736c23eb90fd2597a2bf00d9abd1d1b8af6a /src/plugins/terminal/terminalwidget.cpp | |
parent | 5f8f2f4bcbf114e0e909635f1474629378dcef4e (diff) | |
download | qt-creator-887f6afd258233c476bea1a34834a67e12a864c0.tar.gz |
Terminal: Auto-scroll when selecting outside
Change-Id: I5dea3256524634d9c3e6c0f8132c6bdba4494978
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Cristian Adam <cristian.adam@qt.io>
Diffstat (limited to 'src/plugins/terminal/terminalwidget.cpp')
-rw-r--r-- | src/plugins/terminal/terminalwidget.cpp | 60 |
1 files changed, 36 insertions, 24 deletions
diff --git a/src/plugins/terminal/terminalwidget.cpp b/src/plugins/terminal/terminalwidget.cpp index aba69664fb..0321c0ce5c 100644 --- a/src/plugins/terminal/terminalwidget.cpp +++ b/src/plugins/terminal/terminalwidget.cpp @@ -94,6 +94,15 @@ TerminalWidget::TerminalWidget(QWidget *parent, const OpenTerminalParameters &op connect(&m_flushDelayTimer, &QTimer::timeout, this, [this]() { flushVTerm(true); }); + m_scrollTimer.setSingleShot(false); + m_scrollTimer.setInterval(1s / 2); + connect(&m_scrollTimer, &QTimer::timeout, this, [this] { + if (m_scrollDirection < 0) + verticalScrollBar()->triggerAction(QAbstractSlider::SliderSingleStepSub); + else if (m_scrollDirection > 0) + verticalScrollBar()->triggerAction(QAbstractSlider::SliderSingleStepAdd); + }); + connect(&TerminalSettings::instance(), &AspectContainer::applied, this, [this] { // Setup colors first, as setupFont will redraw the screen. setupColors(); @@ -992,7 +1001,9 @@ void TerminalWidget::inputMethodEvent(QInputMethodEvent *event) void TerminalWidget::mousePressEvent(QMouseEvent *event) { - m_activeMouseSelect.start = event->pos(); + m_scrollDirection = 0; + + m_activeMouseSelect.start = viewportToGlobal(event->pos()); if (event->button() == Qt::LeftButton && event->modifiers() == Qt::ControlModifier) { if (m_linkSelection) { @@ -1034,8 +1045,29 @@ void TerminalWidget::mouseMoveEvent(QMouseEvent *event) { if (m_selection && event->buttons() & Qt::LeftButton) { const auto old = m_selection; + int scrollVelocity = 0; + if (event->pos().y() < 0) { + scrollVelocity = (event->pos().y()); + } else if (event->pos().y() > viewport()->height()) { + scrollVelocity = (event->pos().y() - viewport()->height()); + } + + if ((scrollVelocity != 0) != m_scrollTimer.isActive()) { + if (scrollVelocity != 0) + m_scrollTimer.start(); + else + m_scrollTimer.stop(); + } - int start = m_surface->gridToPos(globalToGrid(viewportToGlobal(m_activeMouseSelect.start))); + m_scrollDirection = scrollVelocity; + + if (m_scrollTimer.isActive() && scrollVelocity != 0) { + const std::chrono::milliseconds scrollInterval = 1000ms / qAbs(scrollVelocity); + if (m_scrollTimer.intervalAsDuration() != scrollInterval) + m_scrollTimer.setInterval(scrollInterval); + } + + int start = m_surface->gridToPos(globalToGrid(m_activeMouseSelect.start)); int newEnd = m_surface->gridToPos(globalToGrid(viewportToGlobal(event->pos()))); if (start > newEnd) { @@ -1103,6 +1135,8 @@ void TerminalWidget::checkLinkAt(const QPoint &pos) void TerminalWidget::mouseReleaseEvent(QMouseEvent *event) { + m_scrollTimer.stop(); + if (m_selection && event->button() == Qt::LeftButton) { if (m_selection->end - m_selection->start == 0) { setSelection(std::nullopt); @@ -1149,28 +1183,6 @@ void TerminalWidget::mouseDoubleClickEvent(QMouseEvent *event) event->accept(); } -void TerminalWidget::scrollContentsBy(int dx, int dy) -{ - Q_UNUSED(dx); - Q_UNUSED(dy); - - if (m_ignoreScroll) - return; - /* - if (m_altscreen) - return; - - size_t orig = m_scrollback->offset(); - size_t offset = m_scrollback->scroll(dy); - if (orig == offset) - return; - - m_cursor.visible = (offset == 0); - */ - - updateViewport(); -} - void TerminalWidget::showEvent(QShowEvent *event) { Q_UNUSED(event); |