Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
open-webui
Commits
5beaa5d8
Commit
5beaa5d8
authored
Jul 23, 2024
by
Aryan Kothari
Browse files
feat: select model with arrow keys (+enter)
parent
63eda0fe
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
3 deletions
+20
-3
src/lib/components/chat/ModelSelector/Selector.svelte
src/lib/components/chat/ModelSelector/Selector.svelte
+20
-3
No files found.
src/lib/components/chat/ModelSelector/Selector.svelte
View file @
5beaa5d8
...
@@ -17,6 +17,7 @@
...
@@ -17,6 +17,7 @@
import { getModels } from '$lib/apis';
import { getModels } from '$lib/apis';
import Tooltip from '$lib/components/common/Tooltip.svelte';
import Tooltip from '$lib/components/common/Tooltip.svelte';
import WebParams from '$lib/components/documents/Settings/WebParams.svelte';
const i18n = getContext('i18n');
const i18n = getContext('i18n');
const dispatch = createEventDispatcher();
const dispatch = createEventDispatcher();
...
@@ -43,6 +44,9 @@
...
@@ -43,6 +44,9 @@
let searchValue = '';
let searchValue = '';
let ollamaVersion = null;
let ollamaVersion = null;
let pseudoSelectedIndex = 0;
let autoScrollTimeout;
$: filteredItems = items.filter(
$: filteredItems = items.filter(
(item) =>
(item) =>
(searchValue
(searchValue
...
@@ -239,10 +243,21 @@
...
@@ -239,10 +243,21 @@
placeholder={searchPlaceholder}
placeholder={searchPlaceholder}
autocomplete="off"
autocomplete="off"
on:keydown={(e) => {
on:keydown={(e) => {
if (e.code === 'Enter'
&& filteredItems.length > 0
) {
if (e.code === 'Enter') {
value = filteredItems[
0
].value;
value = filteredItems[
pseudoSelectedIndex
].value;
show = false;
show = false;
return; // dont need to scroll on selection
} else if (e.code === 'ArrowDown') {
pseudoSelectedIndex = Math.min(pseudoSelectedIndex + 1, filteredItems.length - 1);
} else if (e.code === 'ArrowUp') {
pseudoSelectedIndex = Math.max(pseudoSelectedIndex - 1, 0);
} else {
// if the user types something, reset to the top selection.
pseudoSelectedIndex = 0;
}
}
const item = document.querySelector(`[data-pseudo-selected="true"]`);
item?.scrollIntoView({ block: 'center', inline: 'nearest', behavior: 'instant' });
}}
}}
/>
/>
</div>
</div>
...
@@ -255,11 +270,13 @@
...
@@ -255,11 +270,13 @@
<button
<button
aria-label="model-item"
aria-label="model-item"
class="flex w-full text-left font-medium line-clamp-1 select-none items-center rounded-button py-2 pl-3 pr-1.5 text-sm text-gray-700 dark:text-gray-100 outline-none transition-all duration-75 hover:bg-gray-100 dark:hover:bg-gray-800 rounded-lg cursor-pointer data-[highlighted]:bg-muted {index ===
class="flex w-full text-left font-medium line-clamp-1 select-none items-center rounded-button py-2 pl-3 pr-1.5 text-sm text-gray-700 dark:text-gray-100 outline-none transition-all duration-75 hover:bg-gray-100 dark:hover:bg-gray-800 rounded-lg cursor-pointer data-[highlighted]:bg-muted {index ===
0
pseudoSelectedIndex
? 'bg-gray-100 dark:bg-gray-800 group-hover:bg-transparent'
? 'bg-gray-100 dark:bg-gray-800 group-hover:bg-transparent'
: ''}"
: ''}"
data-pseudo-selected={index === pseudoSelectedIndex}
on:click={() => {
on:click={() => {
value = item.value;
value = item.value;
pseudoSelectedIndex = index;
show = false;
show = false;
}}
}}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment