@@ -265,6 +265,7 @@ const tips = reactive({
265
265
top:0 ,
266
266
left:0
267
267
},
268
+ cursorIdx: 0 ,
268
269
items: <InputTipItem []>[],
269
270
helpBox: {
270
271
// 避免默认提示板与输入框遮挡,某些情况下需要隐藏提示板
@@ -822,6 +823,7 @@ const _execute = () => {
822
823
showInputLine .value = false
823
824
let _success: SuccessFunc = (message ) => {
824
825
let _finish = () => {
826
+ _jumpToBottom ()
825
827
showInputLine .value = true
826
828
_endExecCallBack ()
827
829
}
@@ -831,6 +833,7 @@ const _execute = () => {
831
833
if (message instanceof TerminalFlash ) {
832
834
message .onFlush ((msg : string ) => {
833
835
flash .content = msg
836
+ _jumpToBottom ()
834
837
})
835
838
message .onFinish (() => {
836
839
flash .open = false
@@ -846,6 +849,7 @@ const _execute = () => {
846
849
ask .callback = options .callback
847
850
ask .autoReview = options .autoReview
848
851
_focus ()
852
+ _jumpToBottom ()
849
853
})
850
854
851
855
message .onFinish (() => {
@@ -1169,11 +1173,7 @@ const _inputKeyUp = () => {
1169
1173
} else {
1170
1174
idx = tips .items .length - 1
1171
1175
}
1172
- let viewItem = terminalCmdTipsRef .value .querySelector (" .t-cmd-tips-item:nth-child(" + (idx + 1 ) + " )" )
1173
- if (viewItem ) {
1174
- viewItem .scrollIntoView ({block: " start" , behavior: " smooth" })
1175
- }
1176
- tips .selectedIndex = idx
1176
+ _switchTipsSelectedIdx (idx )
1177
1177
} else {
1178
1178
_switchPreCmd ()
1179
1179
}
@@ -1187,16 +1187,25 @@ const _inputKeyDown = () => {
1187
1187
} else {
1188
1188
idx = 0
1189
1189
}
1190
- let viewItem = terminalCmdTipsRef .value .querySelector (" .t-cmd-tips-item:nth-child(" + (idx + 1 ) + " )" )
1191
- if (viewItem ) {
1192
- viewItem .scrollIntoView ({block: " start" , behavior: " smooth" })
1193
- }
1194
- tips .selectedIndex = idx
1190
+ _switchTipsSelectedIdx (idx )
1195
1191
} else {
1196
1192
_switchNextCmd ()
1197
1193
}
1198
1194
}
1199
1195
1196
+ const _switchTipsSelectedIdx = (idx : number ) => {
1197
+ let viewItem = terminalCmdTipsRef .value .querySelector (" .t-cmd-tips-item:nth-child(" + (idx + 1 ) + " )" )
1198
+ if (viewItem ) {
1199
+ viewItem .scrollIntoView ({block: " start" , behavior: " smooth" })
1200
+ }
1201
+ tips .selectedIndex = idx
1202
+
1203
+ let input = terminalCmdInputRef .value
1204
+ if (input ) {
1205
+ input .setSelectionRange (tips .cursorIdx , tips .cursorIdx )
1206
+ }
1207
+ }
1208
+
1200
1209
const _switchPreCmd = () => {
1201
1210
let cmdLog = store .getLog (getName ())
1202
1211
let cmdIdx = store .getIdx (getName ())
@@ -1617,6 +1626,7 @@ const _switchAllFoldState = (fold: boolean) => {
1617
1626
const _calculateTipsPos = (autoOpen : boolean = false ) => {
1618
1627
if (autoOpen ) {
1619
1628
tips .style .opacity = 0
1629
+ tips .cursorIdx = terminalCmdInputRef .value .selectionStart
1620
1630
tips .open = true
1621
1631
}
1622
1632
if (tips .open ) {
0 commit comments