Skip to content

Commit 82cf829

Browse files
committed
Feat: re-arrange tabs with Shift+Ctrl+PageUp/Down
1 parent 6a37c9d commit 82cf829

File tree

3 files changed

+51
-2
lines changed

3 files changed

+51
-2
lines changed

packages/bruno-app/src/providers/Hotkeys/index.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
saveFolderRoot
1414
} from 'providers/ReduxStore/slices/collections/actions';
1515
import { findCollectionByUid, findItemInCollection } from 'utils/collections';
16-
import { closeTabs, switchTab } from 'providers/ReduxStore/slices/tabs';
16+
import { closeTabs, reorderTabs, switchTab } from 'providers/ReduxStore/slices/tabs';
1717
import { getKeyBindingsForActionAllOS } from './keyMappings';
1818

1919
export const HotkeysContext = React.createContext();
@@ -211,6 +211,30 @@ export const HotkeysProvider = (props) => {
211211
};
212212
}, [activeTabUid, tabs, collections, dispatch]);
213213

214+
// Move tab left
215+
useEffect(() => {
216+
Mousetrap.bind([...getKeyBindingsForActionAllOS('moveTabLeft')], (e) => {
217+
dispatch(reorderTabs({ direction: -1 }));
218+
return false; // this stops the event bubbling
219+
});
220+
221+
return () => {
222+
Mousetrap.unbind([...getKeyBindingsForActionAllOS('moveTabLeft')]);
223+
};
224+
}, [dispatch]);
225+
226+
// Move tab right
227+
useEffect(() => {
228+
Mousetrap.bind([...getKeyBindingsForActionAllOS('moveTabRight')], (e) => {
229+
dispatch(reorderTabs({ direction: 1 }));
230+
return false; // this stops the event bubbling
231+
});
232+
233+
return () => {
234+
Mousetrap.unbind([...getKeyBindingsForActionAllOS('moveTabRight')]);
235+
};
236+
}, [dispatch]);
237+
214238
return (
215239
<HotkeysContext.Provider {...props} value="hotkey">
216240
{showEnvSettingsModal && (

packages/bruno-app/src/providers/Hotkeys/keyMappings.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@ const KeyMapping = {
2020
windows: 'ctrl+pagedown',
2121
name: 'Switch to Next Tab'
2222
},
23+
moveTabLeft: {
24+
mac: 'ctrl+shift+pageup',
25+
windows: 'ctrl+shift+pageup',
26+
name: 'Move Tab Left'
27+
},
28+
moveTabRight: {
29+
mac: 'ctrl+shift+pagedown',
30+
windows: 'ctrl+shift+pagedown',
31+
name: 'Move Tab Right'
32+
},
2333
closeAllTabs: { mac: 'command+shift+w', windows: 'ctrl+shift+w', name: 'Close All Tabs' }
2434
};
2535

packages/bruno-app/src/providers/ReduxStore/slices/tabs.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,20 @@ export const tabsSlice = createSlice({
162162
} else{
163163
console.error("Tab not found!")
164164
}
165+
},
166+
reorderTabs: (state, action) => {
167+
const activeTab = find(state.tabs, (t) => t.uid === state.activeTabUid);
168+
if (!activeTab) return;
169+
170+
const currentIndex = state.tabs.findIndex((t) => t.uid === state.activeTabUid);
171+
const direction = action.payload.direction;
172+
const newIndex = currentIndex + direction;
173+
174+
if (newIndex >= 0 && newIndex < state.tabs.length) {
175+
const temp = state.tabs[currentIndex];
176+
state.tabs[currentIndex] = state.tabs[newIndex];
177+
state.tabs[newIndex] = temp;
178+
}
165179
}
166180
}
167181
});
@@ -175,7 +189,8 @@ export const {
175189
updateResponsePaneTab,
176190
closeTabs,
177191
closeAllCollectionTabs,
178-
makeTabPermanent
192+
makeTabPermanent,
193+
reorderTabs
179194
} = tabsSlice.actions;
180195

181196
export default tabsSlice.reducer;

0 commit comments

Comments
 (0)