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

feat: trigger inputrule on enter for code block #1940

Closed
wants to merge 1 commit into from

Conversation

fengzilong
Copy link
Contributor

@fengzilong fengzilong commented Sep 25, 2021

```{space|enter}

Support using {space} or {enter} to trigger inputrule

related issue: #1107

export default function (options: any = {}) {
const rules: InputRule[] = options.rules || []
const plugin: Plugin = new ProseMirrorPlugin({
props: {
Copy link
Contributor

@BrianHung BrianHung Sep 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is missing the compositionend event in the original inputrule, and well as the isInputRules field which allows undoInputRule to work; as well as the original plugin state. Why not just copy the original plugin and add the handleKeyDown field?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ProseMirror/prosemirror-inputrules#6

Because marijnh said {enter} is not a kind of inputrule, so I made a standalone plugin

Copy link
Contributor Author

@fengzilong fengzilong Sep 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The origin inputrule plugin is not removed, IMO there is no necessary to add compositionend here maybe.
I'm not familiar with ProseMirror, I'm not sure whether the origin plugin state is needed here 😥

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure whether the origin plugin state is needed here

The plugin state is kept there so that the undoInputRule function (which is binded to backspace) can work using the setMeta and getMeta fields.

https://prosemirror.net/docs/ref/#state.Transaction.setMeta
https://prosemirror.net/docs/ref/#state.Transaction.getMeta

Because marijnh said {enter} is not a kind of inputrule, so I made a standalone plugin

I think you could argue enter is a type of inputrule, but where the trigger isn't an explicit key being entered, but an implicit key being pressed; plus, you're still using the InputRule abstraction, just handling / running it differently.

@philippkuehn
Copy link
Contributor

I currently working on a re-write of Inputrules and Pasterules. I’ve already implemented this feature in that branch based on this solution (thanks @BrianHung 😀). So I don’t want to merge this. Thank you anyway!

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.

3 participants