Skip to content

[prosemirror-autocomplete] add cancelOnSpace option#185

Open
benrbray wants to merge 3 commits intocurvenote:mainfrom
benrbray:benrbray/cancelOnFirstSpace
Open

[prosemirror-autocomplete] add cancelOnSpace option#185
benrbray wants to merge 3 commits intocurvenote:mainfrom
benrbray:benrbray/cancelOnFirstSpace

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.

1 participant