pass Transaction to validFor #23

Closed
AlexErrant wants to merge 2 commits from validForTransaction into main
AlexErrant commented 2024-06-20 04:06:27 +02:00 (Migrated from github.com)

I'm using codemirror as a searchbox. I have two "types" of autocompletions:

  1. Historical, i.e. previous things you've searched for.
  2. Syntactical, i.e. typing kind: will give you different "kinds" of cards that you can search for.

I'm using activateOnCompletion to get completion after accepting another completion. I'm also using validFor to make historical completions work since they may have spaces.

However, as seen in this demo video, the historical completion is "overriding" the syntactical completion because the validFor is still returning true even after the initial completion was accepted. You can play with the searchbox here.

This PR passes the Transaction to validFor. Using that transaction, I can call tr.isUserEvent('input.complete') and break out of validFor. I used pnpm patch to test this new behavior in a branch of my project and it works the way I want.

I'm using codemirror as a searchbox. I have two "types" of autocompletions: 1. Historical, i.e. previous things you've searched for. 2. Syntactical, i.e. typing `kind:` will give you different "kinds" of cards that you can search for. I'm using [`activateOnCompletion`](https://github.com/AlexErrant/Pentive/blob/cba8d39e49953874831aa67457809a24fb120696/app/src/components/queryEditor.tsx#L103-L104) to get completion after accepting another completion. I'm also using [`validFor`](https://github.com/AlexErrant/Pentive/blob/cba8d39e49953874831aa67457809a24fb120696/shared-dom/src/language/queryCompletion.ts#L88) to make historical completions work since they may have spaces. However, as seen in [this demo video](https://youtu.be/QK8tFUoMqAQ), the historical completion is "overriding" the syntactical completion because the `validFor` is still returning `true` even after the initial completion was accepted. You can play with the searchbox [here](https://app.pentive.com/cards). This PR passes the Transaction to `validFor`. Using that transaction, I can call `tr.isUserEvent('input.complete')` and break out of `validFor`. I used pnpm patch to test this new behavior in [a branch of my project](https://github.com/AlexErrant/Pentive/compare/main...patch-autocomplete) and it works the way I want.
marijnh commented 2024-06-20 08:30:33 +02:00 (Migrated from github.com)

Would it maybe make more sense to always reset existing completions when picking a completion?

Would it maybe make more sense to always reset existing completions when picking a completion?
AlexErrant commented 2024-06-20 18:24:21 +02:00 (Migrated from github.com)

Yeah, I can't think of a scenario where someone would want to keep the existing completions after accepting one of them. I tried to avoid potentially breaking behavior by making a small additive change. But if you also think it would make sense for validFor to always return false after accepting a completion, that'd work for me!

Yeah, I can't think of a scenario where someone would want to keep the existing completions after accepting one of them. I tried to avoid potentially breaking behavior by making a small additive change. But if you also think it would make sense for `validFor` to always return false after accepting a completion, that'd work for me!
marijnh commented 2024-06-21 13:06:18 +02:00 (Migrated from github.com)

I've pushed an alternative patch, which cleans up some of the state transition handling, and does not add this argument to validFor.

I've pushed an alternative patch, which cleans up some of the state transition handling, and does not add this argument to `validFor`.

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/autocomplete!23
No description provided.