Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions reader/browser/SheetBrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2121,11 +2121,14 @@ void SheetBrowser::hideFindWidget()
qCDebug(appLog) << "hideFindWidget";
if (!m_findWidget.isNull()) {
m_findWidget->hide();
m_findWidget->deleteLater();
m_findWidget = nullptr;
}
}

bool SheetBrowser::isFindWidgetVisible() const
{
return !m_findWidget.isNull() && m_findWidget->isVisible();
}

void SheetBrowser::handleSearchStart()
{
qCDebug(appLog) << "SheetBrowser::handleSearchStart() - Handling search start";
Expand Down
8 changes: 7 additions & 1 deletion reader/browser/SheetBrowser.h
Original file line number Diff line number Diff line change
Expand Up @@ -281,10 +281,16 @@ class SheetBrowser : public Dtk::Widget::DGraphicsView

/**
* @brief hideFindWidget
* 隐藏并销毁搜索框,切换标签页时调用,防止搜索串档
* 隐藏搜索框,切换标签页时调用,防止搜索串档
*/
void hideFindWidget();

/**
* @brief isFindWidgetVisible
* 返回搜索框是否可见
*/
bool isFindWidgetVisible() const;

/**
* @brief jumpToNextSearchResult
* 跳到下一个搜索条目中
Expand Down
4 changes: 2 additions & 2 deletions reader/uiframe/CentralDocPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,9 @@ void CentralDocPage::onTabChanged(DocSheet *sheet)
// 离开当前 sheet 前,保存其阅读状态
QPointer<DocSheet> prevSheet = qobject_cast<DocSheet *>(m_stackedLayout->currentWidget());
if (prevSheet && prevSheet != sheet && prevSheet->opened()) {
// 关闭前一个 sheet 的搜索框,防止切换标签后搜索串档
prevSheet->closeFindWidget();
// 先保存阅读状态(含搜索框可见性),再关闭搜索框,防止切换标签后搜索串档
prevSheet->saveCurrentViewState();
prevSheet->closeFindWidget();
}

m_stackedLayout->setCurrentWidget(sheet);
Expand Down
6 changes: 6 additions & 0 deletions reader/uiframe/DocSheet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1911,6 +1911,7 @@ void DocSheet::saveCurrentViewState()
// 保存滚动位置
if (m_browser) {
m_operation.scrollPosition = m_browser->getScrollPosition();
m_operation.findWidgetVisible = m_browser->isFindWidgetVisible();
}
// 保存侧边栏宽度和展开状态
if (m_sidebar && m_sidebar->isVisible()) {
Expand All @@ -1927,6 +1928,11 @@ void DocSheet::restoreSavedViewState()
if (!opened())
return;

// 恢复搜索框可见性
if (m_browser && m_operation.findWidgetVisible) {
m_browser->handlePrepareSearch();
}

// 恢复侧边栏宽度(仅当用户主动调整过时才恢复)
if (m_sidebar && m_sidebar->isVisible() && m_operation.sidebarWidthChanged && m_operation.sidebarWidth > 0) {
QTimer::singleShot(kRestoreCatalogDelayMs, this, [this]() {
Expand Down
2 changes: 2 additions & 0 deletions reader/uiframe/DocSheet.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ struct SheetOperation {
float scrollPosition = 0.0f;
// 目录树展开节点标题路径列表(如 ["1.概述", "1.概述/1.1 背景"])
QStringList expandedSections;
// 搜索框可见性(标签页切换时保存/恢复)
bool findWidgetVisible = false;
};

DWIDGET_BEGIN_NAMESPACE
Expand Down
Loading