Browse Source

fix: second part of the fix for correctly moving a tab between group

We were fetching the position of a tab in a group based of its window
index to emit a `TabCreated` request to component of the new group's
tab. But to compute it we were relying on the previous positions of the
tabs, with just the group of the tab changed, not its actual index. The
computation of `getPositionTabInGroup` was in that case incorrect.
Since we already now we want to put it at the end, it's easy to compute.
Jocelyn Boullier 4 years ago
parent
commit
7e7b2d0409
1 changed files with 8 additions and 3 deletions
  1. 8 3
      src/Sidebar/Components/Bar.purs

+ 8 - 3
src/Sidebar/Components/Bar.purs

@@ -232,16 +232,19 @@ handleAction =
                 fromMaybe (A.length state.groupTabsPositions) 
                 fromMaybe (A.length state.groupTabsPositions) 
                 $ lastWinTabIndexInGroup toGroup state.groupTabsPositions
                 $ lastWinTabIndexInGroup toGroup state.groupTabsPositions
 
 
+              -- The new index of tab in the group will be at the end.
+              newIndexInGroup = state.groupTabsPositions #
+                                    A.length <<<
+                                    A.filter (T.snd >>> (==) toGroup)
+
           s <- H.modify \s -> 
           s <- H.modify \s -> 
             s { tabsToGroup = M.update (\_ -> Just toGroup) tid s.tabsToGroup
             s { tabsToGroup = M.update (\_ -> Just toGroup) tid s.tabsToGroup
             , groupTabsPositions = 
             , groupTabsPositions = 
               s.groupTabsPositions
               s.groupTabsPositions
-              <#> 
-              (\(Tuple tid' gid') -> if tid' == tid then Tuple tid' toGroup else Tuple tid' gid') 
+              <#> \(Tuple tid' gid') -> if tid' == tid then Tuple tid' toGroup else Tuple tid' gid' 
             -- Reassign the current group directly here to avoid flickering
             -- Reassign the current group directly here to avoid flickering
             , currentGroup = toGroup
             , currentGroup = toGroup
             }
             }
-          let newIndexInGroup = getPositionTabInGroup newTabIndex toGroup s.groupTabsPositions
 
 
           deletedTab' <- H.query _tabs fromGroup $ H.request $ Tabs.TabDeleted tid
           deletedTab' <- H.query _tabs fromGroup $ H.request $ Tabs.TabDeleted tid
           case deletedTab' of 
           case deletedTab' of 
@@ -255,6 +258,8 @@ handleAction =
           H.raise $ SbChangeTabGroup tid (Just toGroup)
           H.raise $ SbChangeTabGroup tid (Just toGroup)
           void $ handleTabsQuery $ Tabs.TabActivated (Just tid) tid Nothing
           void $ handleTabsQuery $ Tabs.TabActivated (Just tid) tid Nothing
 
 
+        -- | Raise a SbMoveTab event with the tab index corrected from the point of view of the
+        -- | group to that of the Firefox window.
         sidebarMoveTab 
         sidebarMoveTab 
           :: TabId 
           :: TabId 
           -> GroupId 
           -> GroupId