cleaning up javascript code

This commit is contained in:
2025-07-29 09:01:37 +02:00
parent 89abbf5c62
commit 90a936b07f
13 changed files with 138 additions and 114 deletions

View File

@@ -1,29 +1,29 @@
<script>
import { t } from '../translations.svelte.js'
import { t } from '../translations.svelte.js'
import { tick } from "svelte";
let {
getCandidates = text => {},
onSelect = text => []
onSelect = text => []
} = $props();
let text = $state('')
let options = $state({});
const ignore = ['Escape','Tab','ArrowUp','ArrowLeft','ArrowRight']
let options = $state({});
let text = $state('')
async function ondblclick(evt){
var select = evt.target;
let key = select.value;
text = options[key];
let result = {};
result[key]=text;
options={};
const select = evt.target;
const key = select.value;
text = options[key];
let result = {};
result[key] = text;
options = {};
onSelect(result);
}
async function onkeyup(evt){
var select = evt.target;
var key = evt.key;
var ignore = ['Escape','Tab','ArrowUp','ArrowLeft','ArrowRight']
const select = evt.target;
const key = evt.key;
if (ignore.includes(key)) return;
if (key == 'ArrowDown'){
if (select.selectedIndex == 0) select.selectedIndex=1;
@@ -34,12 +34,11 @@
return;
}
if (key == 'Backspace'){
text = text.substring(0,text.length-1)
text = text.substring(0,text.length-1)
} else if (key.length<2){
text += evt.key
}
options = await getCandidates(text);
console.log({options:options})
await tick();
for (let o of select.getElementsByTagName('option')) o.selected = false;
}