Export togglePanel state effect #15

Closed
hubgit wants to merge 1 commit from export-toggle-panel into main
hubgit commented 2022-08-08 14:32:44 +02:00 (Migrated from github.com)

We have an extension that's responsible for automatically highlighting matches when the search query changes, by watching for the setSearchQuery effect.

When the search panel was open, this should scroll the match into view, but when the search panel wasn't open (i.e. it's opening now), the match should not be scrolled into view.

To achieve this, we need to check the togglePanel effect for a value of true (i.e. the panel is opening), which means the togglePanel effect needs to be exported from the @codemirror/search package.

We don't intend to dispatch the togglePanel effect, as closeSearchPanel and openSearchPanel already exist for that purpose, so if you'd prefer to add a function that encapsulates togglePanel instead of exporting it, that would be fine too.

We have an extension that's responsible for automatically highlighting matches when the search query changes, by watching for the `setSearchQuery` effect. When the search panel was open, this should scroll the match into view, but when the search panel wasn't open (i.e. it's opening now), the match should not be scrolled into view. To achieve this, we need to check the `togglePanel` effect for a value of `true` (i.e. the panel is opening), which means the `togglePanel` effect needs to be exported from the `@codemirror/search` package. We don't intend to dispatch the `togglePanel` effect, as `closeSearchPanel` and `openSearchPanel` already exist for that purpose, so if you'd prefer to add a function that encapsulates `togglePanel` instead of exporting it, that would be fine too.
marijnh commented 2022-08-13 13:03:43 +02:00 (Migrated from github.com)

Would a searchPanelOpen(state) predicate work for you? That seems like it should address this case and be more generally applicable.

Would a `searchPanelOpen(state)` predicate work for you? That seems like it should address this case and be more generally applicable.
hubgit commented 2022-08-16 13:17:27 +02:00 (Migrated from github.com)

I think searchPanelOpen(state) would work, yes, assuming that if togglePanel.of(true) and setSearchQuery are effects on the same transaction then calling searchPanelOpen(tr.state) would return false, as the togglePanel effect hasn't been applied yet.

I think `searchPanelOpen(state)` would work, yes, assuming that if `togglePanel.of(true)` and `setSearchQuery` are effects on the same transaction then calling `searchPanelOpen(tr.state)` would return `false`, as the `togglePanel` effect hasn't been applied yet.
marijnh commented 2022-08-16 15:28:44 +02:00 (Migrated from github.com)

then calling searchPanelOpen(tr.state) would return false

No, the new state will have the panel open, so that'd return true. searchPanelOpen(tr.startState) would return false though.

> then calling searchPanelOpen(tr.state) would return false No, the new state will have the panel open, so that'd return true. `searchPanelOpen(tr.startState)` would return false though.
hubgit commented 2022-08-16 16:54:02 +02:00 (Migrated from github.com)

Ok, searchPanelOpen(tr.startState) sounds good - I assume you'll want to add that function?

Ok, `searchPanelOpen(tr.startState)` sounds good - I assume you'll want to add that function?
marijnh commented 2022-08-16 17:13:15 +02:00 (Migrated from github.com)

Added this in 6.1.0

Added this in 6.1.0

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