Skip to content

Commit 7a0796d

Browse files
authored
fix: don't reset settings TUI menu cursor on back (#198)
## Description Related: #181 ## Type of Change <!-- Mark the relevant option with an 'x' --> - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] Documentation update - [ ] Code refactoring - [ ] Performance improvement - [ ] Test updates ## Related Issues <!-- Link to related issues using #issue-number --> Closes # ## Changes Made <!-- Describe the changes in detail --> ## Testing <!-- Describe how you tested your changes --> - [ ] I have tested locally - [ ] I have added/updated tests - [ ] All existing tests pass ## Checklist - [ ] My code follows the code style of this project - [ ] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have updated the documentation accordingly - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged and published ## Screenshots (if applicable) <!-- Add screenshots to help explain your changes --> ## Additional Notes <!-- Any additional information that reviewers should know -->
1 parent 8170888 commit 7a0796d

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

src/components/SettingsMenu.tsx

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { Breadcrumb } from "./Breadcrumb.js";
55
import { NavigationTips } from "./NavigationTips.js";
66
import { colors } from "../utils/theme.js";
77
import { useExitOnCtrlC } from "../hooks/useExitOnCtrlC.js";
8+
import { useMenuStore } from "../store/menuStore.js";
89

910
interface SettingsMenuItem {
1011
key: string;
@@ -52,8 +53,26 @@ interface SettingsMenuProps {
5253

5354
export const SettingsMenu = ({ onSelect, onBack }: SettingsMenuProps) => {
5455
const { exit } = useApp();
55-
const [selectedIndex, setSelectedIndex] = React.useState(0);
5656
const { stdout } = useStdout();
57+
const { settingsSelectedKey, setSettingsSelectedKey } = useMenuStore();
58+
59+
// Calculate initial index from persisted key
60+
const initialIndex = React.useMemo(() => {
61+
const index = settingsMenuItems.findIndex(
62+
(item) => item.key === settingsSelectedKey,
63+
);
64+
return index >= 0 ? index : 0;
65+
}, [settingsSelectedKey]);
66+
67+
const [selectedIndex, setSelectedIndex] = React.useState(initialIndex);
68+
69+
// Persist selection when it changes
70+
React.useEffect(() => {
71+
const currentKey = settingsMenuItems[selectedIndex]?.key;
72+
if (currentKey && currentKey !== settingsSelectedKey) {
73+
setSettingsSelectedKey(currentKey);
74+
}
75+
}, [selectedIndex, settingsSelectedKey, setSettingsSelectedKey]);
5776

5877
// Get terminal dimensions for responsive layout
5978
const getTerminalDimensions = React.useCallback(() => {

src/store/menuStore.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@ import { create } from "zustand";
33
interface MenuState {
44
selectedKey: string;
55
setSelectedKey: (key: string) => void;
6+
settingsSelectedKey: string;
7+
setSettingsSelectedKey: (key: string) => void;
68
}
79

810
export const useMenuStore = create<MenuState>((set) => ({
911
selectedKey: "devboxes",
1012
setSelectedKey: (key) => set({ selectedKey: key }),
13+
settingsSelectedKey: "network-policies",
14+
setSettingsSelectedKey: (key) => set({ settingsSelectedKey: key }),
1115
}));

0 commit comments

Comments
 (0)