Skip to content

Commit 9b3a51f

Browse files
committed
fix: reset completion UI state when input is cleared and unfocused
1 parent e5ced4e commit 9b3a51f

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

custom/completionInput.vue

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
:debounceTime="meta.debounceTime"
1212
/>
1313
<div class="absolute right-2 bottom-1">
14-
<Tooltip v-if="isUntouched">
14+
<Tooltip v-if="isUntouched || (!currentValue.trim() && !isFocused)">
1515
<button
1616
@click.stop="handleFocus"
1717
@mousedown.prevent
@@ -25,7 +25,7 @@
2525
</Tooltip>
2626

2727
<Spinner v-else-if="isLoading" class="w-6 h-6" lightFill="#000000" darkFill="#ffffff" />
28-
<Tooltip v-else>
28+
<Tooltip v-else-if="isFocused">
2929
<button
3030
@click.stop="approveCompletion"
3131
@mousedown.prevent
@@ -64,11 +64,19 @@ const emit = defineEmits([
6464
6565
const isLoading = ref<boolean>(false);
6666
const isUntouched = ref<boolean>(true);
67+
const isFocused = ref<boolean>(false);
6768
const currentValue: Ref<string> = ref('');
6869
const suggestionInputRef = ref<InstanceType<typeof SuggestionInput> | null>(null);
6970
7071
onMounted(() => {
7172
currentValue.value = props.record[props.column.name] || '';
73+
if (suggestionInputRef.value) {
74+
const editor = suggestionInputRef.value.$el.querySelector('.ql-editor');
75+
if (editor) {
76+
editor.addEventListener('focus', handleFocus);
77+
editor.addEventListener('blur', handleBlur);
78+
}
79+
}
7280
});
7381
7482
watch(() => currentValue.value, (value) => {
@@ -103,6 +111,7 @@ const approveCompletion = async () => {
103111
}
104112
105113
function handleFocus() {
114+
isFocused.value = true;
106115
if (suggestionInputRef.value) {
107116
const editor = suggestionInputRef.value.$el.querySelector('.ql-editor');
108117
if (editor) {
@@ -111,6 +120,10 @@ function handleFocus() {
111120
}
112121
}
113122
123+
function handleBlur() {
124+
isFocused.value = false;
125+
}
126+
114127
</script>
115128

116129
<style>

0 commit comments

Comments
 (0)