Skip to content

Commit

Permalink
Fix arrow up or down functionality (#224)
Browse files Browse the repository at this point in the history
  • Loading branch information
timmo001 committed May 6, 2024
1 parent 8bd8e3c commit c24f43f
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/pages/Home.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,14 @@
await homeAssistantClient.connect();
}
function handleKeypress(event: KeyboardEvent): void {
function handleKeydown(event: KeyboardEvent): void {
switch (event.key) {
case "ArrowUp":
if (responses.length === 0) return;
if (!inputElement.selectionStart || inputElement.selectionStart > 0)
if (
inputElement.selectionStart === null ||
inputElement.selectionStart > 0
)
return;
const userResponsesUp = responses.filter(
Expand All @@ -116,7 +119,7 @@
case "ArrowDown":
if (responses.length === 0) return;
if (
!inputElement.selectionStart ||
inputElement.selectionStart === null ||
inputElement.selectionStart < text.length
)
return;
Expand Down Expand Up @@ -522,9 +525,10 @@
bind:value={text}
class="input"
id="text"
type="text"
placeholder="Enter a request.."
on:keypress={handleKeypress}
tabindex="0"
type="text"
on:keydown={handleKeydown}
/>

<button
Expand Down

0 comments on commit c24f43f

Please sign in to comment.