From 7ed92ed7ebe165043b1a9aa4dd0763b3b3f17a4a Mon Sep 17 00:00:00 2001 From: Le Tan Date: Mon, 9 Jan 2017 23:01:12 +0800 Subject: [PATCH] fix bug in VEditWindow Bug: when we press the scroll button to the end and click the first/last tab, it won't set current tab correctly. We should not change anything related to current index in handling tabbarClicked(). Signed-off-by: Le Tan --- src/veditwindow.cpp | 15 +++++++++++++-- src/veditwindow.h | 3 ++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/veditwindow.cpp b/src/veditwindow.cpp index b9ec677c..28235a4c 100644 --- a/src/veditwindow.cpp +++ b/src/veditwindow.cpp @@ -32,6 +32,8 @@ VEditWindow::VEditWindow(VNote *vnote, VEditArea *editArea, QWidget *parent) this, &VEditWindow::handleTabCloseRequest); connect(this, &VEditWindow::tabBarClicked, this, &VEditWindow::handleTabbarClicked); + connect(this, &VEditWindow::currentChanged, + this, &VEditWindow::handleCurrentIndexChanged); connect(this, &VEditWindow::customContextMenuRequested, this, &VEditWindow::contextMenuRequested); } @@ -368,9 +370,18 @@ void VEditWindow::focusWindow() getTab(idx)->focusTab(); } -void VEditWindow::handleTabbarClicked(int /* index */) +void VEditWindow::handleTabbarClicked(int p_index) +{ + // Only handle the case when (p_index == currentIndex()) here + // because currentIndex() is not changed yet. If we focus window + // now, we may change the current index forcely. + if (p_index == currentIndex()) { + focusWindow(); + } +} + +void VEditWindow::handleCurrentIndexChanged(int /* p_index */) { - // The child will emit getFocused here focusWindow(); } diff --git a/src/veditwindow.h b/src/veditwindow.h index 8c4a45f5..acbee3b2 100644 --- a/src/veditwindow.h +++ b/src/veditwindow.h @@ -64,7 +64,8 @@ private slots: bool handleTabCloseRequest(int index); void splitWindow(); void removeSplit(); - void handleTabbarClicked(int index); + void handleTabbarClicked(int p_index); + void handleCurrentIndexChanged(int p_index); void contextMenuRequested(QPoint pos); void tabListJump(QAction *action); void handleOutlineChanged(const VToc &p_toc);