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

Detect key events in code tag in domObserver #114

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

seanchambo
Copy link
Contributor

@seanchambo seanchambo commented Nov 23, 2021

We currently have a code block node that under the hood uses a code tag instead of a p tag for better syntax highlighting. We were noticing on mobile that if you hit enter within the code block it would delete all the text after the place where the "Enter" was done.

I believe this will fix the issue but also not sure if it is the best approach. I don't think on our end we are able to change to a p tag now and must stick with code.

Have attached some videos to help show the issue. This is done on the iOS simulator BTW

after.mov
before.mov

@marijnh
Copy link
Member

marijnh commented Nov 24, 2021

Are you styling the code elements as display: block, or wrapping them in a block node? (Seeing the toDOM function for your block nodes would be useful.)

@seanchambo
Copy link
Contributor Author

Yup we are wrapping the code in quite a nested structure.

[
    'div',
    { class: 'code-block' },
    ['div', { class: codeBlockClassNames.gutter, contenteditable: 'false' }],
    [
      'div',
      { class: codeBlockClassNames.content },
      [
        'code',
        {
          'data-language': node.attrs.language || '',
          spellcheck: 'false',
          contenteditable: 'true',
        },
        0,
      ],
    ],
  ]

@marijnh
Copy link
Member

marijnh commented Nov 24, 2021

And the browser only splits the <code> element, not the <div>, when you press enter? That doesn't seem like the native behavior would produce a line break.

@seanchambo
Copy link
Contributor Author

Yes it splits into 2 code tags.

@seanchambo
Copy link
Contributor Author

Any ideas about this? I can send through the mutations from the domobserver if that helps?

@seanchambo
Copy link
Contributor Author

image

This is the dom mutations that are generated when you hit "enter" in the code block node on ios

@seanchambo
Copy link
Contributor Author

@marijnh just wanted to bump this

@marijnh
Copy link
Member

marijnh commented Dec 9, 2021

A minimal self-contained setup that demonstrates the problem would help debug this. The markdown schema also has an inner <code> tag, but doesn't seem to cause this issue. So try to figure out what it is that you're doing differently.

@robinslange
Copy link

Hey @marijnh I'm necroing this thread only because I work with Sean and have been working on newer problems arising that are fixed by this also.

We have an issue where users on Android mobile cannot enter a new line while in a codeblock, and also if there is content after the cursor and the return key is pressed, that content is lost.

I've created a reproduction for you to try out here: https://stackblitz.com/edit/js-jb8fcr?file=index.html

I tested the PR suggested change locally, and without any other changes was able to resolve both the aforementioned issues :)

Hopefully the reproduction helps, let me know if you need anything else. Open to suggestion on resolution, there may be something we've missed in our investigation.

We're currently looking at a bump for our prosemirror-view version in May, and having tested v1.30.1 as that is what we're looking to bump to and at present none of the new changes fix our issues.

@robinslange
Copy link

Hey @marijnh just a gentle bump ❤️

@marijnh
Copy link
Member

marijnh commented Apr 13, 2023

At a glance, your code blocks are rendered in an uneditable wrapper element, which is definitely not something this library supports.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants