Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,13 @@ export function Autocomplete(props: {
}
if (name === "return") {
select()
e.preventDefault()
// After selection, autocomplete is hidden. If the key that triggered
// this is also the submit keybinding, we need to let the event
// propagate so the prompt can handle submission.
// Only prevent default if autocomplete is still visible (selection failed).
if (store.visible) {
e.preventDefault()
}
return
}
if (name === "tab") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,25 @@ export function useTextareaKeybindings() {
return createMemo(() => {
const keybinds = keybind.all

return [
{ name: "return", action: "submit" },
{ name: "return", meta: true, action: "newline" },
...TEXTAREA_ACTIONS.flatMap((action) => mapTextareaKeybindings(keybinds, action)),
] satisfies KeyBinding[]
// Get user-defined bindings first
const userBindings = TEXTAREA_ACTIONS.flatMap((action) =>
mapTextareaKeybindings(keybinds, action),
)

// Check if user has configured each action
const hasSubmitBinding = userBindings.some((b) => b.action === "submit")
const hasNewlineBinding = userBindings.some((b) => b.action === "newline")

// Build defaults array, only adding defaults for unconfigured actions
const defaults: KeyBinding[] = []
if (!hasSubmitBinding) {
defaults.push({ name: "return", action: "submit" })
}
if (!hasNewlineBinding) {
defaults.push({ name: "return", meta: true, action: "newline" })
}

// User bindings come first so they take precedence over defaults
return [...userBindings, ...defaults] satisfies KeyBinding[]
})
}