Skip to content

Commit faa49c8

Browse files
committed
fixed no escape from search menu
1 parent 550bce2 commit faa49c8

6 files changed

Lines changed: 177 additions & 9 deletions

File tree

.github/workflows/docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
destination: ./_site
3535

3636
- name: Upload artifact
37-
uses: actions/upload-pages-artifact@v4
37+
uses: actions/upload-pages-artifact@v5
3838

3939
deploy:
4040
environment:

.github/workflows/npm-publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
token: ${{ secrets.NPM_TOKEN }}
3535

3636
- name: Release to GitHub
37-
uses: softprops/action-gh-release@v2
37+
uses: softprops/action-gh-release@v3
3838
if: github.ref_type == 'tag'
3939
with:
4040
files: |

.kilo/package-lock.json

Lines changed: 115 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

source/components/layouts/MainLayout.tsx

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
// Main layout shell
2-
import {useCallback, useMemo} from 'react';
2+
import {useCallback, useMemo, useEffect} from 'react';
33
import React from 'react';
44
import {useNavigation} from '../../hooks/useNavigation.ts';
55
import PlaylistList from '../playlist/PlaylistList.tsx';
66
import Help from '../common/Help.tsx';
77
import {useTheme} from '../../hooks/useTheme.ts';
8-
import {useKeyBinding} from '../../hooks/useKeyboard.ts';
8+
import {
9+
useKeyBinding,
10+
registerGoHomeCallback,
11+
setCurrentViewForCtrlC,
12+
} from '../../hooks/useKeyboard.ts';
913
import SearchLayout from './SearchLayout.tsx';
1014
import PlayerLayout from './PlayerLayout.tsx';
1115
import MiniPlayerLayout from './MiniPlayerLayout.tsx';
@@ -184,6 +188,20 @@ function MainLayout() {
184188
useKeyBinding(KEYBINDINGS.DETACH, handleDetach);
185189
useKeyBinding(KEYBINDINGS.RESUME_BACKGROUND, handleResumeBackground);
186190

191+
// Register goHome callback for Ctrl+C handling in search view
192+
useEffect(() => {
193+
registerGoHomeCallback(goToHome);
194+
195+
return () => {
196+
registerGoHomeCallback(() => {});
197+
};
198+
}, [goToHome]);
199+
200+
// Update current view for Ctrl+C handling when navigation changes
201+
useEffect(() => {
202+
setCurrentViewForCtrlC(navState.currentView);
203+
}, [navState.currentView]);
204+
187205
// Memoize the view component to prevent unnecessary remounts
188206
// Only recreate when currentView actually changes
189207
const currentView = useMemo(() => {

source/components/layouts/SearchLayout.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,13 @@ function SearchLayout() {
172172
}
173173
}, [editingFilter, isTyping, dispatch]);
174174

175+
// Handle escape in search - go to home
176+
const goToHome = useCallback(() => {
177+
dispatch({category: 'NAVIGATE', view: VIEW.HOME});
178+
}, [dispatch]);
179+
175180
useKeyBinding(KEYBINDINGS.BACK, goBack);
181+
useKeyBinding(['escape'], goToHome, {bypassBlock: true});
176182

177183
const handleMixCreated = useCallback((message: string) => {
178184
setActionMessage(message);

source/hooks/useKeyboard.ts

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,26 @@ type RegistryEntry = {
1414
// Global registry for key handlers
1515
const registry: Set<RegistryEntry> = new Set();
1616

17+
// Callback to navigate to home (registered by MainLayout)
18+
let goHomeCallback: (() => void) | null = null;
19+
20+
/**
21+
* Register a callback to navigate to home (used for Ctrl+C in certain views)
22+
*/
23+
export function registerGoHomeCallback(callback: () => void): void {
24+
goHomeCallback = callback;
25+
}
26+
27+
/**
28+
* Function to set the current view for Ctrl+C handling
29+
* This should be called by the app to track which view we're in
30+
*/
31+
let currentView: string = 'home';
32+
33+
export function setCurrentViewForCtrlC(view: string): void {
34+
currentView = view;
35+
}
36+
1737
/**
1838
* Hook to bind keyboard shortcuts.
1939
* This uses a centralized manager to avoid multiple useInput calls and memory leaks.
@@ -88,6 +108,20 @@ export function KeyboardManager() {
88108
if (blockCount > 0) {
89109
// When keyboard input is blocked (e.g., within a focused text input),
90110
// check if any entry has bypassBlock flag and matches this key.
111+
// First check for Ctrl+C special case - go to home in search view
112+
if (key.ctrl && input === 'c') {
113+
if (currentView === 'search') {
114+
if (goHomeCallback) {
115+
goHomeCallback();
116+
}
117+
118+
return;
119+
}
120+
121+
// In other views, quit the app
122+
process.exit(0);
123+
}
124+
91125
for (const entry of registry) {
92126
if (entry.bypassBlock) {
93127
for (const binding of entry.keys) {
@@ -173,11 +207,6 @@ export function KeyboardManager() {
173207
});
174208
}
175209

176-
// Global quit handling
177-
if (key.ctrl && input === 'c') {
178-
process.exit(0);
179-
}
180-
181210
// Dispatch to registered handlers
182211
for (const entry of registry) {
183212
const {keys, handler} = entry;

0 commit comments

Comments
 (0)