Seeing weird behaviors with `width` and `height` for multi step args calls
I have a custom search script that I put together that utilizes the snippet below:
// Name: Bike Search
// Shortcut: cmd ctrl space
import "@johnlindquist/kit"
const Fuse = await npm("fuse.js")
async function main() {
const bikePath = path.resolve(home("Documents/notes/bike"))
const contents = await readFile(`${bikePath}/db.json`, "utf-8")
const parsedFiles = JSON.parse(contents)
const flatRows = parsedFiles.flat()
const fuse = new Fuse(flatRows, {
includeScore: true,
useExtendedSearch: true,
keys: ["text"],
})
const searchQuery = await arg({
placeholder: "Enter your search query",
width: 500,
height: 80,
ignoreBlur: true,
enter: "Search",
onEscape: async (input) => {
await global.hide()
process.exit(0)
},
shortcuts: []
})
const searchResults = fuse.search(searchQuery)
console.log(searchResults.length)
const selection = await arg({
placeholder: "Search for...",
width: 1000,
height: 600,
onEscape: async (input) => {
await global.hide()
process.exit(0)
},
shortcuts: []
}, searchResults.map(result => ({
name: result.item.text,
description: `level: ${result.item.level}`,
value: result,
preview: async () => {
return `
<div class="m-4 p-4">
<h1>${result.item.text}</h1>
<ul>
${result.item.parents.map(pt => `<li>${pt}</li>`).join("\n")}
</ul>
</div>
`
}
})))
await $`open bike://${selection.item.documentId}#${selection.item.id}`
}
main().catch(console.error)
I get weird things happening though where the sizes upon secondary runs either have the width and height from the second prompt for the first prompt and vice versa. Has anybody experienced weird behavior like this?
I should note that I'm on latest and triggering this search via a shortcut.
After trial and error it's the presence of shortcuts: []. I've only included that empty array because another bug I found: onEscape and some of the other onX methods, don't register without the presence of the shortcuts key.
Interesting...
~/.kit/db/prompt.json will attempt to store the prompt position per script. The logic that's handling that cache must be interfering with your custom sizes.
I don't really have a solution for you right now since that prompt cache will auto update whenever the scripts ends, so you'd be fighting against the app if you tried to update the prompt.json manually.
In the future I'll have to disable the automatic prompt caching and force the user to "pin prompt" or something if they want to remember the position/size.
All good, thanks for the response John. I can take a look into the logic of it too, but for now I'll remove the custom sizes.