Fix focus lost (fix #4732)

This commit is contained in:
the1812 2024-12-21 20:51:14 +08:00
parent fdec2d8dd6
commit d76293ef0a
2 changed files with 10 additions and 5 deletions

View File

@ -30,7 +30,7 @@
:action="a"
@previous-item="previousItem()"
@next-item="nextItem()"
@delete-item="onDeleteItem()"
@delete-item="onDeleteItem(index)"
@action="
index === actions.length - 1 && onClearHistory()
onAction(a)
@ -49,12 +49,12 @@
class="suggest-item disabled"
></VLoading>
<ActionItem
v-for="a of actions"
v-for="(a, index) of actions"
:key="a.key"
:action="a"
@previous-item="previousItem()"
@next-item="nextItem()"
@delete-item="onDeleteItem()"
@delete-item="onDeleteItem(index)"
@action="onAction(a)"
/>
</div>
@ -234,7 +234,8 @@ export default Vue.extend({
this.focusTarget.next()
e.preventDefault()
},
handleIndexUpdate() {
async handleIndexUpdate() {
await this.$nextTick()
if (!this.focusTarget.hasFocus) {
this.focusInput()
return
@ -248,7 +249,8 @@ export default Vue.extend({
this.focusTarget.next()
},
search,
onDeleteItem() {
onDeleteItem(index: number) {
this.focusTarget.setFocus(index)
this.focusTarget.previous()
this.getActions()
},

View File

@ -26,6 +26,9 @@ export class FocusTarget extends EventTarget {
return this.itemIndex > -1
}
setFocus(index: number) {
this.index = index
}
reset(length: number, index = this.index) {
this.itemLength = length
this.index = index