optimize: 优化SearchBar的行为。

release-2.0.0.2
王良 2025-02-26 10:01:28 +08:00
parent 99c634ed7f
commit 175e902251
2 changed files with 58 additions and 9 deletions

View File

@ -315,7 +315,7 @@ function createWindow (startHideWindow, autoQuitIfError = true) {
} else if (input.key === 'Escape' && input.type === 'keyUp' && !input.control && !input.shift && !input.alt && !input.meta) {
// 按 ESC隐藏全文检索框SearchBar
event.preventDefault()
win.webContents.send('search-bar', { key: 'show-hide', hideSearchBar: true })
win.webContents.send('search-bar', { key: 'hide' })
} else if (input.key === 'F3' && input.type === 'keyDown' && !input.control && !input.shift && !input.alt && !input.meta) {
// 按 F3全文检索框SearchBar定位到下一个
event.preventDefault()

View File

@ -13,6 +13,8 @@ export default {
menus: undefined,
config: undefined,
hideSearchBar: true,
searchBarIsFocused: false,
searchBarInputKeyupTimeout: null,
}
},
computed: {
@ -45,23 +47,31 @@ export default {
}
// /
if (message.key !== 'show-hide' && this.hideSearchBar) {
if (!message.key.includes('hide') && this.hideSearchBar) {
message = { key: 'show-hide' }
}
try {
if (message.key === 'show-hide') { // /
this.hideSearchBar = message.hideSearchBar != null ? message.hideSearchBar : !this.hideSearchBar
const hide = message.hideSearchBar != null ? message.hideSearchBar : !this.hideSearchBar
// SearchBar
if (hide && !this.hideSearchBar && !this.searchBarIsFocused) {
this.doSearchBarInputFocus()
return
}
this.hideSearchBar = hide
//
if (!this.hideSearchBar) {
setTimeout(() => {
try {
this.$refs.searchBar.$el.querySelector('input').focus()
} catch {
}
}, 100)
this.doSearchBarInputFocus()
} else {
this.searchBarIsFocused = false
}
} else if (message.key === 'hide') { //
this.hideSearchBar = true
this.searchBarIsFocused = false
} else if (message.key === 'next') { //
this.$refs.searchBar.next()
} else if (message.key === 'previous') { //
@ -70,9 +80,48 @@ export default {
} catch (e) {
console.error('操作SearchBar出现异常', e)
}
const input = this.getSearchBarInput()
if (input) {
input.addEventListener('focus', this.onSearchBarInputFocus)
input.addEventListener('blur', this.onSearchBarInputBlur)
input.addEventListener('keydown', this.onSearchBarInputKeydown)
input.addEventListener('keyup', this.onSearchBarInputKeyup)
}
})
},
methods: {
getSearchBarInput () {
return this.$refs.searchBar.$el.querySelector('input[type=text]')
},
onSearchBarInputFocus () {
this.searchBarIsFocused = true
},
onSearchBarInputBlur () {
this.searchBarIsFocused = false
},
onSearchBarInputKeydown () {
clearTimeout(this.searchBarInputKeyupTimeout)
},
onSearchBarInputKeyup (e) {
if (!this.$refs.searchBar || e.key === 'Enter' || e.key === 'F3') {
return
}
clearTimeout(this.searchBarInputKeyupTimeout)
this.searchBarInputKeyupTimeout = setTimeout(() => {
//
this.$refs.searchBar.next()
this.$refs.searchBar.previous()
}, 150)
},
doSearchBarInputFocus () {
setTimeout(() => {
const input = this.getSearchBarInput()
if (input) {
input.focus()
}
}, 100)
},
titleClick (item) {
console.log('title click:', item)
},