Skip to content

Commit

Permalink
refactor: Reduce code by using value param
Browse files Browse the repository at this point in the history
Signed-off-by: Elizabeth Danzberger <[email protected]>
  • Loading branch information
elzody committed Jun 12, 2024
1 parent c40c322 commit a6db799
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions src/plugins/searchDecorations.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,16 @@ export default function searchDecorations() {
const searchResults = runSearch(doc, '')
return highlightResults(doc, searchResults)
},
apply(tr, _, oldState, newState) {
apply(tr, value, oldState, newState) {
const { query: oldQuery } = searchQueryPluginKey.getState(oldState)
const { query: newQuery } = searchQueryPluginKey.getState(newState)

let query = ''

if (tr.docChanged || (newQuery !== oldQuery)) {
query = newQuery
const searchResults = runSearch(tr.doc, newQuery)
return highlightResults(tr.doc, searchResults)
} else {
query = oldQuery
return value
}

const searchResults = runSearch(tr.doc, query)
return highlightResults(tr.doc, searchResults)
},
},
props: {
Expand Down

0 comments on commit a6db799

Please sign in to comment.