fix: improve search trigger detection on mobile keyboards

Switch from keydown to beforeinput event for detecting search trigger characters, which works reliably across desktop and mobile virtual keyboards. Allow Shift+Enter to create newlines on mobile devices.
This commit is contained in:
Andrew Beal 2025-11-12 22:05:12 +00:00
parent 911165b15d
commit 10472bf30a

View file

@ -106,23 +106,23 @@
}
if (e.key === "Enter") {
if (e.shiftKey) {
if (e.shiftKey || Platform.isMobile) {
return;
}
e.preventDefault();
handleSubmit();
}
}
if (isSearchTrigger(e.key)) {
e.preventDefault();
// Detect search triggers on character insertion
function handleBeforeInput(e: InputEvent) {
// This works reliably on both desktop and mobile (including virtual keyboards)
if (e.inputType === "insertText" && e.data && isSearchTrigger(e.data)) {
const position = inputService.getCursorPosition(textareaElement);
const trigger = fromInput(e.key);
const trigger = fromInput(e.data);
searchStateStore.initializeSearch(trigger, position);
inputService.insertTextAtCursor(e.key, textareaElement);
}
// Let the character insert, handleInput() will synchronize the search query
}
async function continueSearch(e: KeyboardEvent) {
@ -287,6 +287,7 @@
bind:this={textareaElement}
contenteditable="plaintext-only"
on:keydown={handleKeydown}
on:beforeinput={handleBeforeInput}
on:input={handleInput}
on:paste={handlePaste}
on:copy={handleCopy}