Skip to content

Commit

Permalink
feat: Add search next/previous methods
Browse files Browse the repository at this point in the history
Signed-off-by: Elizabeth Danzberger <[email protected]>
  • Loading branch information
elzody committed Aug 11, 2024
1 parent 464e98a commit d071d8b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 10 deletions.
10 changes: 6 additions & 4 deletions src/components/SearchDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -116,16 +116,18 @@ export default {
'setSearchQuery',
'toggleMatchAll',
'showSearchDialog',
'searchNext',
'searchPrevious',
]),

previous() {
// this.previousSearch()
// this.scrollIntoView()
this.searchPrevious()
this.scrollIntoView()
},

next() {
// this.nextSearch()
// this.scrollIntoView()
this.searchNext()
this.scrollIntoView()
},

clearSearch() {
Expand Down
26 changes: 20 additions & 6 deletions src/mixins/editorMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { useSearchStore } from '../stores/search.js'
import linkHandlerMixin from '../mixins/linkHandlerMixin.js'
import PageInfoBar from '../components/Page/PageInfoBar.vue'
import { editorApiReaderFileId } from '../constants.js'
import { emit } from '@nextcloud/event-bus'
import { subscribe } from '@nextcloud/event-bus'

export default {
mixins: [
Expand All @@ -37,7 +37,7 @@ export default {
'shareTokenParam',
'showing',
]),
...mapState(useSearchStore, ['searchQuery']),
...mapState(useSearchStore, ['searchQuery', 'matchAll']),
...mapState(useCollectivesStore, ['currentCollectiveCanEdit']),
...mapState(usePagesStore, ['currentPage', 'pageFilePath']),

Expand All @@ -62,6 +62,18 @@ export default {
},
},

created() {
subscribe('collectives:next-search', () => {
this.editor?.searchNext()
this.reader?.searchNext()
})

subscribe('collectives:previous-search', () => {
this.editor?.searchPrevious()
this.reader?.searchPrevious()
})
},

watch: {
'showOutline'(value) {
this.editor?.setShowOutline(value)
Expand All @@ -71,6 +83,12 @@ export default {
this.editor?.setSearchQuery(value)
this.reader?.setSearchQuery(value)
},
'matchAll'(newValue, oldValue) {
if (newValue !== oldValue) {
this.editor?.setSearchQuery(this.searchQuery, newValue)
this.reader?.setSearchQuery(this.searchQuery, newValue)
}
},
},

beforeDestroy() {
Expand Down Expand Up @@ -112,10 +130,6 @@ export default {
const element = document.querySelector(`[href="${document.location.hash}"]`)
element?.click()
}

if (this.searchQuery && this.searchQuery !== '') {
emit('text:editor:search', { query: this.searchQuery })
}
},
onSearch: (results) => {
this.setSearchResults(results)
Expand Down
9 changes: 9 additions & 0 deletions src/stores/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

import { defineStore } from 'pinia'
import { emit } from '@nextcloud/event-bus'

export const useSearchStore = defineStore('search', {
state: () => ({
Expand All @@ -26,5 +27,13 @@ export const useSearchStore = defineStore('search', {
setSearchResults(results) {
this.results = results
},
searchNext() {
emit('collectives:next-search')
this.matchAll = false
},
searchPrevious() {
emit('collectives:previous-search')
this.matchAll = false
},
},
})

0 comments on commit d071d8b

Please sign in to comment.