Add test and regexpTest functions to SearchQuery config #18

Closed
heyman wants to merge 3 commits from add-test-function-to-searchquery into main
heyman commented 2025-07-10 12:32:48 +02:00 (Migrated from github.com)

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

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 commented 2025-07-10 14:31:28 +02:00 (Migrated from github.com)

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.

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 commented 2025-07-10 15:13:04 +02:00 (Migrated from github.com)

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.

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 commented 2026-01-13 01:11:20 +01:00 (Migrated from github.com)

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.

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 commented 2026-01-13 11:00:07 +01:00 (Migrated from github.com)

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

Thanks, that looks much better. I've merged this as d55469959a81fe
heyman commented 2026-01-13 12:13:01 +01:00 (Migrated from github.com)

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

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

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
codemirror/search!18
No description provided.