fix: cap topZ to avoid covering menubar/dock, clear isMaximized on drag/resize, fix terminal stale state

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
M1ngdaXie
2026-03-26 14:42:39 -07:00
parent 47df521e86
commit 4381948b58
2 changed files with 41 additions and 18 deletions

View File

@@ -88,20 +88,21 @@ export default function Terminal() {
function handleSubmit() { function handleSubmit() {
const cmd = input.trim().toLowerCase(); const cmd = input.trim().toLowerCase();
const newLines: Line[] = [...lines, { type: 'input', text: PROMPT + input, key: nextKey() }]; const inputLine: Line = { type: 'input', text: PROMPT + input, key: nextKey() };
if (cmd === '') { if (cmd === 'clear') {
setLines([...newLines, { type: 'output', text: '', key: nextKey() }]);
} else if (cmd === 'clear') {
setLines([]); setLines([]);
} else if (cmd === '') {
setLines(prev => [...prev, inputLine, { type: 'output', text: '', key: nextKey() }]);
} else if (COMMANDS[cmd]) { } else if (COMMANDS[cmd]) {
COMMANDS[cmd].forEach(l => newLines.push({ type: 'output', text: l, key: nextKey() })); const outputLines: Line[] = COMMANDS[cmd].map(l => ({ type: 'output' as const, text: l, key: nextKey() }));
newLines.push({ type: 'output', text: '', key: nextKey() }); outputLines.push({ type: 'output', text: '', key: nextKey() });
setLines(newLines); setLines(prev => [...prev, inputLine, ...outputLines]);
} else { } else {
newLines.push({ type: 'output', text: `zsh: command not found: ${cmd}`, key: nextKey() }); setLines(prev => [...prev, inputLine,
newLines.push({ type: 'output', text: '', key: nextKey() }); { type: 'output', text: `zsh: command not found: ${cmd}`, key: nextKey() },
setLines(newLines); { type: 'output', text: '', key: nextKey() }
]);
} }
if (cmd) setHistory(h => [cmd, ...h].slice(0, 50)); if (cmd) setHistory(h => [cmd, ...h].slice(0, 50));

View File

@@ -30,17 +30,31 @@ const initialState: OSState = {
function reducer(state: OSState, action: OSAction): OSState { function reducer(state: OSState, action: OSAction): OSState {
switch (action.type) { switch (action.type) {
case 'OPEN': { case 'OPEN': {
const newZ = state.topZ + 1; const base = state.topZ + 1;
// Normalize z-indices if we're approaching Dock's z-index (500)
if (base >= 480) {
const openWindows = Object.values(state.windows).filter(w => w.isOpen && w.id !== action.id);
openWindows.sort((a, b) => a.zIndex - b.zIndex);
const normalized: Record<string, WindowState> = { ...state.windows };
openWindows.forEach((w, i) => { normalized[w.id] = { ...w, zIndex: 10 + i }; });
normalized[action.id] = {
...state.windows[action.id],
isOpen: true,
isMinimized: false,
zIndex: 10 + openWindows.length,
};
return { ...state, topZ: 10 + openWindows.length, windows: normalized };
}
return { return {
...state, ...state,
topZ: newZ, topZ: base,
windows: { windows: {
...state.windows, ...state.windows,
[action.id]: { [action.id]: {
...state.windows[action.id], ...state.windows[action.id],
isOpen: true, isOpen: true,
isMinimized: false, isMinimized: false,
zIndex: newZ, zIndex: base,
}, },
}, },
}; };
@@ -94,13 +108,21 @@ function reducer(state: OSState, action: OSAction): OSState {
}; };
} }
case 'FOCUS': { case 'FOCUS': {
const newZ = state.topZ + 1; const base = state.topZ + 1;
if (base >= 480) {
const openWindows = Object.values(state.windows).filter(w => w.isOpen && w.id !== action.id);
openWindows.sort((a, b) => a.zIndex - b.zIndex);
const normalized: Record<string, WindowState> = { ...state.windows };
openWindows.forEach((w, i) => { normalized[w.id] = { ...w, zIndex: 10 + i }; });
normalized[action.id] = { ...state.windows[action.id], zIndex: 10 + openWindows.length, isMinimized: false };
return { ...state, topZ: 10 + openWindows.length, windows: normalized };
}
return { return {
...state, ...state,
topZ: newZ, topZ: base,
windows: { windows: {
...state.windows, ...state.windows,
[action.id]: { ...state.windows[action.id], zIndex: newZ, isMinimized: false }, [action.id]: { ...state.windows[action.id], zIndex: base, isMinimized: false },
}, },
}; };
} }
@@ -109,7 +131,7 @@ function reducer(state: OSState, action: OSAction): OSState {
...state, ...state,
windows: { windows: {
...state.windows, ...state.windows,
[action.id]: { ...state.windows[action.id], position: { x: action.x, y: action.y } }, [action.id]: { ...state.windows[action.id], position: { x: action.x, y: action.y }, isMaximized: false },
}, },
}; };
case 'RESIZE': case 'RESIZE':
@@ -117,7 +139,7 @@ function reducer(state: OSState, action: OSAction): OSState {
...state, ...state,
windows: { windows: {
...state.windows, ...state.windows,
[action.id]: { ...state.windows[action.id], size: { width: action.width, height: action.height } }, [action.id]: { ...state.windows[action.id], size: { width: action.width, height: action.height }, isMaximized: false },
}, },
}; };
case 'SET_WALLPAPER': case 'SET_WALLPAPER':