瀏覽代碼

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 <[email protected]>
Le Tan 9 年之前
父節點
當前提交
7ed92ed7eb
共有 2 個文件被更改,包括 15 次插入3 次删除
  1. 13 2
      src/veditwindow.cpp
  2. 2 1
      src/veditwindow.h

+ 13 - 2
src/veditwindow.cpp

@@ -32,6 +32,8 @@ VEditWindow::VEditWindow(VNote *vnote, VEditArea *editArea, QWidget *parent)
             this, &VEditWindow::handleTabCloseRequest);
             this, &VEditWindow::handleTabCloseRequest);
     connect(this, &VEditWindow::tabBarClicked,
     connect(this, &VEditWindow::tabBarClicked,
             this, &VEditWindow::handleTabbarClicked);
             this, &VEditWindow::handleTabbarClicked);
+    connect(this, &VEditWindow::currentChanged,
+            this, &VEditWindow::handleCurrentIndexChanged);
     connect(this, &VEditWindow::customContextMenuRequested,
     connect(this, &VEditWindow::customContextMenuRequested,
             this, &VEditWindow::contextMenuRequested);
             this, &VEditWindow::contextMenuRequested);
 }
 }
@@ -368,9 +370,18 @@ void VEditWindow::focusWindow()
     getTab(idx)->focusTab();
     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();
     focusWindow();
 }
 }
 
 

+ 2 - 1
src/veditwindow.h

@@ -64,7 +64,8 @@ private slots:
     bool handleTabCloseRequest(int index);
     bool handleTabCloseRequest(int index);
     void splitWindow();
     void splitWindow();
     void removeSplit();
     void removeSplit();
-    void handleTabbarClicked(int index);
+    void handleTabbarClicked(int p_index);
+    void handleCurrentIndexChanged(int p_index);
     void contextMenuRequested(QPoint pos);
     void contextMenuRequested(QPoint pos);
     void tabListJump(QAction *action);
     void tabListJump(QAction *action);
     void handleOutlineChanged(const VToc &p_toc);
     void handleOutlineChanged(const VToc &p_toc);