Skip to content

Commit 2586a1b

Browse files
committed
fix(globals): implement missing global.find file search prompt
Add implementation for global.find which was declared in types but never implemented, causing CI test failures. The find prompt provides an interactive file search using the existing fileSearch functionality (mdfind on macOS, where on Windows).
1 parent c1d4d2b commit 2586a1b

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

src/target/app.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3303,6 +3303,52 @@ global.toast = async (text: string, options = {}) => {
33033303
})
33043304
}
33053305

3306+
/**
3307+
* File search prompt - search for files using system file search (mdfind on macOS, where on Windows)
3308+
*/
3309+
global.find = async (placeholderOrConfig?, fileSearchOptions = {}) => {
3310+
let config: PromptConfig =
3311+
typeof placeholderOrConfig === "string"
3312+
? { placeholder: placeholderOrConfig }
3313+
: placeholderOrConfig || {}
3314+
3315+
let searchDebounce: ReturnType<typeof setTimeout> | null = null
3316+
3317+
return await global.kitPrompt({
3318+
placeholder: "Search for files...",
3319+
enter: "Select",
3320+
...config,
3321+
onInput: async (input, state) => {
3322+
if (config.onInput) {
3323+
await config.onInput(input, state)
3324+
}
3325+
3326+
if (searchDebounce) {
3327+
clearTimeout(searchDebounce)
3328+
}
3329+
3330+
if (!input || input.length < 2) {
3331+
setChoices([])
3332+
return
3333+
}
3334+
3335+
searchDebounce = setTimeout(async () => {
3336+
try {
3337+
const results = await global.fileSearch(input, fileSearchOptions)
3338+
const choices = results.slice(0, 100).map((filePath: string) => ({
3339+
name: global.path.basename(filePath),
3340+
description: filePath,
3341+
value: filePath,
3342+
}))
3343+
setChoices(choices)
3344+
} catch (error) {
3345+
setChoices([])
3346+
}
3347+
}, 200)
3348+
},
3349+
})
3350+
}
3351+
33063352
let beginMicStream = () => {
33073353
global.mic.stream = undefined
33083354
global.mic.stream = new Readable({

src/target/terminal.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,11 @@ global.revealFile = async () => {
382382
notSupported('revealFile')
383383
return ''
384384
}
385+
386+
global.find = async () => {
387+
notSupported('find')
388+
return ''
389+
}
385390
; (global as any).clipboard = new Proxy(
386391
{},
387392
{

0 commit comments

Comments
 (0)