Add numMatches method to SearchQuery #10

Closed
sergeichestakov wants to merge 1 commit from num-results into main
sergeichestakov commented 2022-03-03 08:50:45 +01:00 (Migrated from github.com)

Fixes the issue described here: https://github.com/codemirror/codemirror.next/issues/727

Although calculating the total number of matches for a given search query can be expensive and is calculated lazily, I believe it can be useful to expose this functionality for certain product use cases (for example, displaying the number of matches to the user in a custom search panel).

Let me know if this sounds reasonable and like something you would accept, otherwise I can close!

Fixes the issue described here: https://github.com/codemirror/codemirror.next/issues/727 Although calculating the total number of matches for a given search query can be expensive and is calculated lazily, I believe it can be useful to expose this functionality for certain product use cases (for example, displaying the number of matches to the user in a custom search panel). Let me know if this sounds reasonable and like something you would accept, otherwise I can close!
marijnh commented 2022-03-03 10:20:07 +01:00 (Migrated from github.com)

Is this not easy enough to do entirely in client code with the new getCursor method?

Is this not easy enough to do entirely in client code with the new `getCursor` method?
sergeichestakov commented 2022-03-03 10:32:59 +01:00 (Migrated from github.com)

oh yes, I totally missed that. looks like it's not even published yet. will give it a try when it is. thanks!

oh yes, I totally missed that. looks like it's not even published yet. will give it a try when it is. thanks!
marijnh commented 2022-03-03 10:36:26 +01:00 (Migrated from github.com)

Oh, indeed, it wasn't published. I've tagged 0.19.9

Oh, indeed, it wasn't published. I've tagged 0.19.9
sergeichestakov commented 2022-03-04 02:13:40 +01:00 (Migrated from github.com)

FYI I think the return type of getCursor is incorrect: github.com/codemirror/search@6fcc3247e1/src/search.ts (L112)

The return type is Iterator<{from: number, to: number}> but it actually returns RegExpCursor | SearchCursor, both of which implement Iterator but are strict supersets. This means TS complains when trying to access the value field for example.

FYI I think the return type of `getCursor` is incorrect: https://github.com/codemirror/search/blob/6fcc3247e180b949b90884ee725098b7250ac81b/src/search.ts#L112 The return type is `Iterator<{from: number, to: number}>` but it actually returns `RegExpCursor | SearchCursor`, both of which *implement* `Iterator` but are strict supersets. This means TS complains when trying to access the `value` field for example.
marijnh commented 2022-03-04 09:18:02 +01:00 (Migrated from github.com)

How does that make it incorrect? Just use it like an iterator, which is the shared interface between those two types.

How does that make it incorrect? Just use it like an iterator, which is the shared interface between those two types.

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!10
No description provided.