idea-manager 0.7.0 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -111,6 +111,8 @@ interface TabContextValue {
|
|
|
111
111
|
setActiveTab: (tabId: string) => void;
|
|
112
112
|
updateTabName: (tabId: string, name: string) => void;
|
|
113
113
|
consumeInitial: (tabId: string) => void;
|
|
114
|
+
nextTab: () => void;
|
|
115
|
+
prevTab: () => void;
|
|
114
116
|
}
|
|
115
117
|
|
|
116
118
|
const TabCtx = createContext<TabContextValue | null>(null);
|
|
@@ -193,8 +195,36 @@ export function TabProvider({ children }: { children: ReactNode }) {
|
|
|
193
195
|
dispatch({ type: 'CONSUME_INITIAL', tabId });
|
|
194
196
|
}, []);
|
|
195
197
|
|
|
198
|
+
const nextTab = useCallback(() => {
|
|
199
|
+
const idx = state.tabs.findIndex(t => t.id === state.activeTabId);
|
|
200
|
+
const next = state.tabs[(idx + 1) % state.tabs.length];
|
|
201
|
+
if (next) dispatch({ type: 'SET_ACTIVE', tabId: next.id });
|
|
202
|
+
}, [state.tabs, state.activeTabId]);
|
|
203
|
+
|
|
204
|
+
const prevTab = useCallback(() => {
|
|
205
|
+
const idx = state.tabs.findIndex(t => t.id === state.activeTabId);
|
|
206
|
+
const prev = state.tabs[(idx - 1 + state.tabs.length) % state.tabs.length];
|
|
207
|
+
if (prev) dispatch({ type: 'SET_ACTIVE', tabId: prev.id });
|
|
208
|
+
}, [state.tabs, state.activeTabId]);
|
|
209
|
+
|
|
210
|
+
// Ctrl+Tab / Ctrl+Shift+Tab keyboard shortcut
|
|
211
|
+
useEffect(() => {
|
|
212
|
+
const handler = (e: KeyboardEvent) => {
|
|
213
|
+
if (e.ctrlKey && e.key === 'Tab') {
|
|
214
|
+
e.preventDefault();
|
|
215
|
+
if (e.shiftKey) {
|
|
216
|
+
prevTab();
|
|
217
|
+
} else {
|
|
218
|
+
nextTab();
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
window.addEventListener('keydown', handler);
|
|
223
|
+
return () => window.removeEventListener('keydown', handler);
|
|
224
|
+
}, [nextTab, prevTab]);
|
|
225
|
+
|
|
196
226
|
return (
|
|
197
|
-
<TabCtx.Provider value={{ state, openProject, closeTab, setActiveTab, updateTabName, consumeInitial }}>
|
|
227
|
+
<TabCtx.Provider value={{ state, openProject, closeTab, setActiveTab, updateTabName, consumeInitial, nextTab, prevTab }}>
|
|
198
228
|
{children}
|
|
199
229
|
</TabCtx.Provider>
|
|
200
230
|
);
|