Skip to content

Commit 8d56700

Browse files
committed
Fix smart scroll logic - use one-liner setTrackOutput(isAtEndOfOutput())
Implement smart scrolling behavior that only auto-scrolls when user is already at the bottom of the terminal. This allows users to scroll up and view history without being forced back to the bottom when new output arrives. Changes: - Replace broken logic that didn't call setTrackOutput(false) when scrolled up - Use setTrackOutput(isAtEndOfOutput()) to properly auto-scroll when at bottom - Removed 6 excessive qCDebug logs - Updated comment style in qtermwidget.h to match project format (dzw1995 2026-04-03) Fixes: Users can now scroll up to view history while output is ongoing
1 parent 28829b6 commit 8d56700

2 files changed

Lines changed: 5 additions & 19 deletions

File tree

3rdparty/terminalwidget/lib/qtermwidget.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,10 +280,10 @@ class TERMINALWIDGET_EXPORT QTermWidget : public QWidget
280280

281281
void enableSetCursorPosition(bool enable);
282282

283-
// 获取是否允许输出时滚动
283+
//Add by dzw1995 2026-04-03 获取是否允许输出时滚动
284284
bool getIsAllowScroll() const;
285285

286-
// 设置是否允许输出时滚动
286+
//Add by dzw1995 2026-04-03 设置是否允许输出时滚动
287287
void setIsAllowScroll(bool isAllowScroll);
288288

289289
//Add by ut001000 renfeixiang 2020-12-02 当搜索框出现时,设置m_bHasSelect为false,

src/views/termwidget.cpp

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -280,26 +280,12 @@ inline void TermWidget::onQTermWidgetReceivedData(QString value)
280280
qCDebug(views) << "Enter TermWidget::onQTermWidgetReceivedData";
281281
Q_UNUSED(value)
282282

283-
// 如果用户禁用了输出时滚动,重置标志后直接返回
284-
if (!Settings::instance()->OutputtingScroll()) {
285-
qCDebug(views) << "Branch: OutputtingScroll is false, setting isAllowScroll to true";
286-
setIsAllowScroll(true);
287-
return;
288-
}
289-
290283
// 智能滚动:只在用户在底部时才自动滚动
291284
// 这样用户向上滚动查看历史时不会被强制拉回
292-
qCDebug(views) << "Branch: Smart scroll - checking isAtEndOfOutput";
293-
if (isAtEndOfOutput()) {
294-
qCDebug(views) << "Branch: At end of output, setting trackOutput to true";
295-
setTrackOutput(true);
296-
} else {
297-
qCDebug(views) << "Branch: Not at end of output, keeping current position";
285+
if (getIsAllowScroll()) {
286+
setTrackOutput(isAtEndOfOutput());
287+
setIsAllowScroll(true);
298288
}
299-
// 如果用户不在底部(正在查看历史),不强制滚动,保持当前位置
300-
301-
// 重置 m_isAllowScroll 标志,确保下次能正常处理
302-
setIsAllowScroll(true);
303289
}
304290

305291
inline void TermWidget::onTermWidgetReceivedData(QString value)

0 commit comments

Comments
 (0)