diff --git a/src/Name.svelte b/src/Name.svelte index 953562a..a4c93f7 100644 --- a/src/Name.svelte +++ b/src/Name.svelte @@ -12,8 +12,7 @@ let url = getContext('LUOXU_URL') let input let ul - let has_focus = false - let has_mouse = false + let should_hide = false let abort = new AbortController() @@ -23,6 +22,11 @@ ul.style.width = `${rect.width - 2}px` }) + function update_list_width() { + const rect = input.getBoundingClientRect() + ul.style.width = `${rect.width - 2}px` + } + function may_complete() { if(to) { clearTimeout(to) @@ -62,8 +66,10 @@ if(el.tagName != 'LI') { return } - selected_idx = el.dataset.idx + selected_idx = el.dataset.idx|0 select_confirmed() + input.focus() + should_hide = true } function select_confirmed() { @@ -73,9 +79,12 @@ } function update_value() { + if(!selected) { + return + } if(input.value) { input.value = selected_name - }else if(selected != null){ + }else{ selected = null selected_name = '' } @@ -112,16 +121,23 @@ // TODO: NOT operator -