cleaning up javascript code
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user