Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[prosemirror-autocomplete] add cancelOnSpace option #185

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

benrbray
Copy link

@benrbray benrbray commented May 3, 2023

Thanks very much for the prosemirror-autocomplete package, it's great!

cancelOnFirstSpace

What's the intended behavior of cancelOnFirstSpace? The docs say:

cancelOnFirstSpace?: boolean, cancels the auto complete on first space, default is true

This could be interpreted in two different ways:

  1. the autocomplete will be cancelled the first time the user types a space (that is, no spaces are allowed whatsoever)
  2. the autocomplete will be cancelled if the first character typed after the autocomplete trigger is a space, but after that, spaces are allowed

My desired behavior is the first one -- no spaces allowed, but the code behaves according to the second interpretation:

const checkCancelOnSpace = type?.cancelOnFirstSpace ?? true;
if (
checkCancelOnSpace &&
filter.length === 0 &&
(event.key === ' ' || event.key === 'Spacebar')
) {
closeAutocomplete(view);
// Take over the space creation so no other input rules are fired
view.dispatch(view.state.tr.insertText(' ').scrollIntoView());
return true;
}

Proposal

I propose the following, which I've implemented in this PR.

  • add a new option cancelOnSpace, which cancels autocompletion whenever space is pressed
  • if cancelOnSpace = true, the value of cancelOnFirstSpace is ignored
  • if cancelOnSpace = false, the behavior of cancelOnFirstSpace is the same as before

I also added some comments and updated the readme to document this change.

(Optional) Rename cancelOnFirstSpace?

Optionally, I suggest renaming cancelOnFirstSpace to cancelOnInitialSpace, but I understand if you prefer to keep it the same to avoid a breaking change.

Conclusion

Happy to make any changes to the PR based on your feedback. Thanks!

@benrbray benrbray changed the title [prosemirror-autocomplete] clarify intended meaning of cancelOnFirstSpace [prosemirror-autocomplete] add cancelOnSpace option May 3, 2023
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.

None yet

1 participant