-
Notifications
You must be signed in to change notification settings - Fork 91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Content search highlighting #5817
Conversation
This comment was marked as off-topic.
This comment was marked as off-topic.
0b79206
to
9bef1db
Compare
For easier testing just paste this in the js console:
|
Some odd behaviour seems that the search is reset when a sync request comes in, that would still be good to fix, otherwise this looks really good 👍 |
9bef1db
to
db68c8b
Compare
Interestingly, it doesn't happen for me in Collectives, but when I test it by making a plain markdown document in Files and doing a search, it does this. Will look into it further. UPDATE: I think I fixed it :D |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How would i clear the highlight now?
@max-nextcloud Sending an empty string as a search query should clear the highlighting. This PR is mostly to get the foundation of the search highlighting into Text, and other apps can then use it in their own way and provide the user with a way to clear the highlighting, and it will then just send an empty search query to Text to clear the highlighting I am also open to other suggestions on how to clear the highlighting if an empty search query doesn't make sense for it |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One tweak still. Approving anyway so you can move on.
src/plugins/searchDecorations.js
Outdated
if (tr.docChanged || (newQuery !== oldQuery)) { | ||
query = newQuery | ||
} else { | ||
query = oldQuery |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can just return the previous value here. The doc did not change and the query also stayed the same.oldState
That way you also don't need the query
variable and can just use newQuery
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh... the way this is defined in prosemirror is slightly confusing as oldState
contains the entire state. I think you will need to use all four args of the function so you can reuse the previous value of this plugins state:
apply(tr, value, oldState, newState) {
...
if (tr.docChanged || (newQuery !== oldQuery)) {
...
} else {
return value // same as before
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, I think you mean something like this?
apply(tr, value, oldState, newState) {
const { query: oldQuery } = searchQueryPluginKey.getState(oldState)
const { query: newQuery } = searchQueryPluginKey.getState(newState)
if (tr.docChanged || (newQuery !== oldQuery)) {
const searchResults = runSearch(tr.doc, newQuery)
return highlightResults(tr.doc, searchResults)
} else {
return value
}
},
It was indeed kind of confusing, I thought it the value
parameter there was something I could use, but the docs did not really elaborate on it, so originally I operated on the oldState
to be safe. But this would make more sense.
Signed-off-by: Elizabeth Danzberger <lizzy7128@tutanota.de>
Signed-off-by: Elizabeth Danzberger <lizzy7128@tutanota.de>
Signed-off-by: Elizabeth Danzberger <lizzy7128@tutanota.de>
Signed-off-by: Elizabeth Danzberger <lizzy7128@tutanota.de>
Signed-off-by: Elizabeth Danzberger <lizzy7128@tutanota.de>
Signed-off-by: Elizabeth Danzberger <lizzy7128@tutanota.de>
a6db799
to
59cec5c
Compare
💬 Summary
Part of #5816
This PR implements search highlighting in Text. It is mainly a TipTap extension which subscribes to an event emitted with a search query, and will add highlighting styles to the editor document if matches to the search query are found.
How to test this PR
From the browser console, emit an event with the event bus:Replace 'Test' with the string you want to search for.
Screenshot
📝 TODO
☑️ Checklist