4
4
dark:focus:ring-blue-500 dark:focus:border-blue-500 relative max-w-full" >
5
5
<SuggestionInput
6
6
ref =" suggestionInputRef"
7
- class =" w-full !border-none text-gray-900 text-sm dark:placeholder-gray-400 dark:text-white whitespace-normal mr-14 "
7
+ class =" w-full !border-none text-gray-900 text-sm dark:placeholder-gray-400 dark:text-white whitespace-normal mr-28 "
8
8
v-model =" currentValue"
9
9
:type =" column.type"
10
10
:completionRequest =" complete"
11
11
:debounceTime =" meta.debounceTime"
12
+ @completion-approved =" handleCompletionApproved"
12
13
/>
13
14
<div class =" absolute right-2 bottom-1" >
14
15
<Tooltip v-if =" isUntouched || (!currentValue.trim() && !isFocused)" >
29
30
<button
30
31
@click.stop =" approveCompletion"
31
32
@mousedown.prevent
32
- class =" text-white bg-gradient-to-r from-purple-500 via-purple-600 to-purple-700 hover:bg-gradient-to-br focus:ring-4 focus:outline-none focus:ring-purple-300 dark:focus:ring-purple-800
33
- font-medium rounded-lg text-xs w-14 h-6 flex items-center justify-center" >
34
- <IconArrowRightThin class =" w-5 h-5" />
35
- <span class =" scale-75 border border-white rounded-sm px-0.5 bg-white/25" >TAB</span >
33
+ :class =" [
34
+ 'text-white bg-gradient-to-r from-purple-500 via-purple-600 to-purple-700 hover:bg-gradient-to-br focus:ring-4 focus:outline-none focus:ring-purple-300 dark:focus:ring-purple-800',
35
+ 'font-medium rounded-lg text-xs flex items-center justify-center py-1 px-1 ',
36
+ buttonText === approveCompletionValue ? 'w-16' : 'w-18'
37
+ ]" >
38
+ <div
39
+ class =" flex items-center justify-center"
40
+ v-if =" buttonText === approveCompletionValue"
41
+ >
42
+ <IconArrowRightThin class =" mt-0.5 w-5 h-5 text-white" />
43
+ <span class =" ml-1 px-1 h-4 flex items-center justify-center rounded border bg-white text-black text-[10px] font-mono shadow-inner shadow-sm border-gray-300 dark:bg-gray-700 dark:text-white dark:border-gray-500" >
44
+ <p class =" mt-0.5" >Tab</p >
45
+ </span >
46
+ </div >
47
+ <div
48
+ class =" flex items-center justify-center"
49
+ v-else-if =" buttonText === approveNextWordValue"
50
+ >
51
+ <IconArrowRightThin class =" mt-0.5 w-5 h-5 text-white" />
52
+ <span class =" ml-1 px-1 h-4 flex items-center justify-center rounded border bg-white text-black text-[10px] font-mono shadow-inner shadow-sm border-gray-300 dark:bg-gray-700 dark:text-white dark:border-gray-500" >
53
+ <p class =" mt-0.5" >Ctrl</p >
54
+ </span >
55
+ <span class =" ml-1 text-white" >+</span >
56
+ <span class =" ml-1 px-1 h-4 flex items-center justify-center rounded border bg-white text-black text-[10px] font-mono shadow-inner shadow-sm border-gray-300 dark:bg-gray-700 dark:text-white dark:border-gray-500" >
57
+ <IconArrowRightThin class =" w-3.5 h-3.5" />
58
+ </span >
59
+ </div >
36
60
</button >
37
61
<template #tooltip >
38
- {{ $t('Approve completion' ) }}
62
+ {{ $t(tooltipText ) }}
39
63
</template >
40
64
</Tooltip >
41
65
44
68
</template >
45
69
46
70
<script setup lang="ts">
47
- import { ref , onMounted , watch , Ref } from ' vue' ;
71
+ import { ref , onMounted , watch , Ref , computed } from ' vue' ;
48
72
import { callAdminForthApi } from ' @/utils' ;
49
73
import { AdminForthColumnCommon } from ' @/types/Common' ;
50
74
import { Spinner , Tooltip } from ' @/afcl' ;
@@ -61,15 +85,33 @@ const props = defineProps<{
61
85
const emit = defineEmits ([
62
86
' update:value' ,
63
87
]);
64
-
88
+ const approveCompletionValue: string = ' TAB' ;
89
+ const approveNextWordValue: string = ' CTRL + ->'
65
90
const isLoading = ref <boolean >(false );
66
91
const isUntouched = ref <boolean >(true );
67
92
const isFocused = ref <boolean >(false );
68
93
const currentValue: Ref <string > = ref (' ' );
69
94
const suggestionInputRef = ref <InstanceType <typeof SuggestionInput > | null >(null );
95
+ const buttonText = ref <string >(approveCompletionValue );
96
+
97
+ const tooltipText = computed (() =>
98
+ buttonText .value === approveCompletionValue ? ' Approve completion' : ' Approve next word'
99
+ );
100
+
101
+ function handleCompletionApproved(type : ' all' | ' word' ) {
102
+ if (buttonText .value === approveCompletionValue && type === ' all' ) {
103
+ buttonText .value = approveNextWordValue ;
104
+ } else if (buttonText .value === approveNextWordValue && type === ' word' ) {
105
+ buttonText .value = approveCompletionValue ;
106
+ }
107
+ }
70
108
71
109
onMounted (() => {
72
- currentValue .value = props .record [props .column .name ] || ' ' ;
110
+ const value = props .record [props .column .name ] || ' ' ;
111
+ currentValue .value = value ;
112
+ if (value .trim ()) {
113
+ isUntouched .value = false ;
114
+ }
73
115
if (suggestionInputRef .value ) {
74
116
const editor = suggestionInputRef .value .$el .querySelector (' .ql-editor' );
75
117
if (editor ) {
@@ -84,7 +126,11 @@ watch(() => currentValue.value, (value) => {
84
126
});
85
127
86
128
watch (() => props .record , (value ) => {
87
- currentValue .value = value [props .column .name ] || ' ' ;
129
+ const val = value [props .column .name ] || ' ' ;
130
+ currentValue .value = val ;
131
+ if (val .trim ()) {
132
+ isUntouched .value = false ;
133
+ }
88
134
});
89
135
90
136
async function complete(textBeforeCursor : string ) {
@@ -105,8 +151,13 @@ async function complete(textBeforeCursor: string) {
105
151
106
152
const approveCompletion = async () => {
107
153
if (suggestionInputRef .value ) {
108
- await suggestionInputRef .value .approveCompletion (' all' );
154
+ if ( buttonText .value === approveCompletionValue ) {
155
+ await suggestionInputRef .value .approveCompletion (' all' );
156
+ } else {
157
+ await suggestionInputRef .value .approveCompletion (' word' );
158
+ }
109
159
}
160
+ buttonText .value === approveCompletionValue ? buttonText .value = approveNextWordValue : buttonText .value = approveCompletionValue ;
110
161
}
111
162
112
163
function handleFocus() {
0 commit comments