Skip to content

Add test and regexpTest functions to SearchQuery config#18

Closed
heyman wants to merge 3 commits intocodemirror:mainfrom
heyman:add-test-function-to-searchquery
Closed

Add test and regexpTest functions to SearchQuery config#18
heyman wants to merge 3 commits intocodemirror:mainfrom
heyman:add-test-function-to-searchquery

Conversation

@heyman
Copy link
Copy Markdown
Contributor

@heyman heyman commented Jul 10, 2025

Adds test and regexpTest to SearchQuery's config, which can be used to specify a custom test function for SearchCursor and RegExpCursor.

See: https://discuss.codemirror.net/t/custom-test-function-for-searchquery-config/9323

@marijnh
Copy link
Copy Markdown
Member

marijnh commented Jul 10, 2025

These look very specific to your use case, and not very elegant in their interface. Would a single function (not split between regexp and regular matches), that passes the matched string, an editor state, and from/to positions, work for you? I guess you're trying to optimize by passing in the data structures that are locally available, but that feels like it leaks too much of the internal implementation, and needlessly complicates the signatures.

@heyman
Copy link
Copy Markdown
Contributor Author

heyman commented Jul 10, 2025

Yeah, this is just some minimal changes that would allow me to do the filtering I wanted to do, using the same signature as the test function used internally.

Would a single function (not split between regexp and regular matches), that passes the matched string, an editor state, and from/to positions, work for you?

Yes, that should work. I do a regex test on the whole line (of the match) and use to and from for my filtering.

@heyman
Copy link
Copy Markdown
Contributor Author

heyman commented Jan 13, 2026

I've now updated the PR to use a single test function that is passed the matched string, state, and from/to positions like you suggested.

marijnh added a commit that referenced this pull request Jan 13, 2026
@marijnh
Copy link
Copy Markdown
Member

marijnh commented Jan 13, 2026

Thanks, that looks much better. I've merged this as d554699

@marijnh marijnh closed this Jan 13, 2026
heyman added a commit to heyman/heynote that referenced this pull request Jan 13, 2026
Remove modified version of @codemirror/search that we had vendored, since codemirror/search#18 was merged.

Refactored code to use the same search test function for regular search, regexp search, and selection matching search.
@heyman
Copy link
Copy Markdown
Contributor Author

heyman commented Jan 13, 2026

Thanks! Feels good to be back on the official @codemirror/search package, instead of a copied monstrosity :).

heyman added a commit to heyman/heynote that referenced this pull request Jan 13, 2026
Remove modified version of @codemirror/search that we had vendored, since codemirror/search#18 was merged.

Refactored code to use the same search test function for regular search, regexp search, and selection matching search.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants