Skip to content

feat: trigger inputrule on enter for code block#1940

Closed
nanokind wants to merge 1 commit intoueberdosis:mainfrom
nanokind:code-block-enter
Closed

feat: trigger inputrule on enter for code block#1940
nanokind wants to merge 1 commit intoueberdosis:mainfrom
nanokind:code-block-enter

Conversation

@nanokind
Copy link
Copy Markdown
Contributor

@nanokind nanokind 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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor Author

@nanokind nanokind 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
Copy Markdown
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
Copy Markdown
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