@@ -19,7 +19,7 @@ import {
19
19
TerminalAsk ,
20
20
TerminalFlash ,
21
21
InputTipsSearchHandlerFunc ,
22
- InputTipsSelectHandlerFunc , TerminalElementInfo
22
+ InputTipsSelectHandlerFunc , TerminalElementInfo , TerminalCursorStyle
23
23
} from " ./types" ;
24
24
import {
25
25
_copyTextToClipboard , _debounce ,
@@ -38,7 +38,7 @@ import {
38
38
_isSafari ,
39
39
_nonEmpty ,
40
40
_openUrl ,
41
- _pointInRect ,
41
+ _pointInRect , _screenType ,
42
42
} from " ~/common/util.ts" ;
43
43
import api , {register , rename , unregister } from " ~/common/api" ;
44
44
import {DEFAULT_COMMANDS } from " ~/common/configuration.ts" ;
@@ -131,15 +131,9 @@ const props = defineProps({
131
131
type: Number ,
132
132
default: 15
133
133
},
134
- /**
135
- * 光标样式,可选值:
136
- * - block
137
- * - underline
138
- * - bar
139
- * - none
140
- */
134
+ // 光标样式
141
135
cursorStyle: {
142
- type: String ,
136
+ type: String as PropType < TerminalCursorStyle > ,
143
137
default : () => " block"
144
138
},
145
139
// 光标闪烁开关
@@ -197,6 +191,14 @@ const containerStyle = computed(() => {
197
191
return ' '
198
192
})
199
193
194
+ const isEnableHelpBox = computed <boolean >(() => {
195
+ return props .enableHelpBox && tips .items [tips .selectedIndex ] && tips .items [tips .selectedIndex ].command
196
+ })
197
+
198
+ const selectedTipCommand = computed <Command | null >(() => {
199
+ return tips .items [tips .selectedIndex ] ? tips .items [tips .selectedIndex ].command : null
200
+ })
201
+
200
202
const _name = ref <string >()
201
203
const command = ref <string >(" " )
202
204
const cursorConf = reactive ({
@@ -696,7 +698,7 @@ const _searchCmd = () => {
696
698
items .push ({
697
699
content: o .keyword ,
698
700
description: o .item .description ,
699
- attach : o .item
701
+ command : o .item
700
702
})
701
703
}
702
704
_updateTipsItems (items , cursorInKey )
@@ -1241,21 +1243,27 @@ const _onInput = (e: InputEvent) => {
1241
1243
1242
1244
_calculateTipsPos ()
1243
1245
1244
- _checkInputCursor ()
1245
- _calculateCursorPos ()
1246
+ nextTick (() => {
1247
+ _checkInputCursor ()
1248
+ _calculateCursorPos ()
1249
+
1250
+ let helpBoxRef = terminalHelpBoxRef .value
1251
+ if (helpBoxRef ) {
1252
+ let cursorRect = terminalCursorRef .value .getBoundingClientRect ()
1253
+ let helpBoxRect = tips .helpBox .defaultBoxRect || helpBoxRef .getBoundingClientRect ()
1254
+ if (cursorRect && helpBoxRect && _pointInRect ({
1255
+ x: cursorRect .x + byteLen .en * 2 ,
1256
+ y: cursorRect .y + FONT_HEIGHT
1257
+ }, helpBoxRect )) {
1258
+ tips .helpBox .open = false
1259
+ tips .helpBox .defaultBoxRect = helpBoxRect
1260
+ } else {
1261
+ tips .helpBox .open = true
1262
+ tips .helpBox .defaultBoxRect = null
1263
+ }
1264
+ }
1265
+ })
1246
1266
1247
- let cursorRect = terminalCursorRef .value .getBoundingClientRect ()
1248
- let helpBoxRect = tips .helpBox .defaultBoxRect || terminalHelpBoxRef .value .getBoundingClientRect ()
1249
- if (cursorRect && helpBoxRect && _pointInRect ({
1250
- x: cursorRect .x + byteLen .en * 2 ,
1251
- y: cursorRect .y + FONT_HEIGHT
1252
- }, helpBoxRect )) {
1253
- tips .helpBox .open = false
1254
- tips .helpBox .defaultBoxRect = helpBoxRect
1255
- } else {
1256
- tips .helpBox .open = true
1257
- tips .helpBox .defaultBoxRect = null
1258
- }
1259
1267
}
1260
1268
1261
1269
const _checkInputCursor = () => {
@@ -1696,7 +1704,7 @@ const _selectTips = () => {
1696
1704
})
1697
1705
return
1698
1706
}
1699
- command .value = selectedItem .attach .key
1707
+ command .value = selectedItem .command .key
1700
1708
_resetCursorPos ()
1701
1709
_jumpToBottom ()
1702
1710
}
@@ -1864,12 +1872,12 @@ defineExpose({
1864
1872
</p >
1865
1873
</div >
1866
1874
</div >
1867
- <div v-if =" enableHelpBox " >
1868
- <slot name =" helpBox" :showHeader =" showHeader" :item =" tips.items[tips.selectedIndex] ? tips.items[tips.selectedIndex].attach : null " >
1869
- <t-help-box ref =" terminalHelpBox "
1875
+ <div v-if =" isEnableHelpBox " >
1876
+ <slot name =" helpBox" :showHeader =" showHeader" :item =" selectedTipCommand " >
1877
+ <t-help-box ref =" terminalHelpBoxRef "
1870
1878
:top =" headerHeight + 10"
1871
- :content =" tips.items[tips.selectedIndex] ? tips.items[tips.selectedIndex].attach : null "
1872
- v-show =" tips.helpBox.open" />
1879
+ :content =" selectedTipCommand "
1880
+ v-show =" tips.helpBox.open && !_screenType().xs " />
1873
1881
</slot >
1874
1882
</div >
1875
1883
0 commit comments