Skip to content

Commit

Permalink
fix: marktext#2294 Focus find-in-folder search box; unfocus with ESC
Browse files Browse the repository at this point in the history
  • Loading branch information
BBazard committed Aug 21, 2022
1 parent aed36db commit 07a1afd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/renderer/components/search/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ export default {
bus.$on('findPrev', this.listenFindPrev)
document.addEventListener('click', this.docClick)
document.addEventListener('keyup', this.docKeyup)
bus.$on('search-blur', this.blurSearch)
},
beforeDestroy () {
Expand All @@ -185,6 +186,7 @@ export default {
bus.$off('findPrev', this.listenFindPrev)
document.removeEventListener('click', this.docClick)
document.removeEventListener('keyup', this.docKeyup)
bus.$off('search-blur', this.blurSearch)
},
methods: {
Expand Down Expand Up @@ -228,6 +230,10 @@ export default {
this.emptySearch(true)
},
blurSearch () {
this.emptySearch(true)
},
emptySearch (selectHighlight = false) {
this.showSearch = false
const searchValue = this.searchValue = ''
Expand Down
18 changes: 14 additions & 4 deletions src/renderer/components/sideBar/search.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
type="text" v-model="keyword"
placeholder="Search in folder..."
@keyup="search"
ref="search"
>
<div class="controls">
<span
Expand Down Expand Up @@ -125,14 +126,18 @@ export default {
},
watch: {
showSideBar: function (value, oldValue) {
if (value && !oldValue && this.rightColumn === 'search') {
this.keyword = this.searchMatches.value
if (this.rightColumn === 'search') {
if (value && !oldValue) {
this.handleFindInFolder(false)
} else {
bus.$emit('search-blur')
}
}
}
},
created () {
this.$nextTick(() => {
this.keyword = this.searchMatches.value
this.handleFindInFolder()
bus.$on('findInFolder', this.handleFindInFolder)
if (this.keyword.length > 0 && this.searcherRunning === false) {
this.searcherRunning = true
Expand Down Expand Up @@ -316,8 +321,13 @@ export default {
openFolder () {
this.$store.dispatch('ASK_FOR_OPEN_PROJECT')
},
handleFindInFolder () {
handleFindInFolder (focus = true) {
this.keyword = this.searchMatches.value
if (focus) {
this.$nextTick(() => {
this.$refs.search.focus()
})
}
}
},
destroyed () {
Expand Down

0 comments on commit 07a1afd

Please sign in to comment.