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

Fix pasting code in CSS editor #776

Merged
merged 1 commit into from
May 6, 2022
Merged

Conversation

NiedziolkaMichal
Copy link
Member

This PR fixes two issues with pasting code into CSS examples(like matrix):

  • When caret is placed inside highlighted syntax, error is thrown(Uncaught TypeError: Cannot read properties of null (reading 'textContent'))
  • When user selects text that he wishes to replace, that selection is ignored and new content is always added at the end.

Now editor will use native copy-paste mechanism of the contenteditable elements, we just use Prism.highlightElement(codeElement); afterwards.

There is still one issue regarding this feature. Prism always places caret at the very beginning of highlighted content, which is unexpected to the user. Maybe this can be resolved by using newer version of the library.

@caugner Could you review it please?

@caugner
Copy link
Contributor

caugner commented May 5, 2022

@NiedziolkaMichal Would you be able to provide two screen videos, one from before (with the issues you describe), and another one after (with the issues fixed by your PR)?

@NiedziolkaMichal
Copy link
Member Author

NiedziolkaMichal commented May 5, 2022

Before:

bandicam.2022-05-05.21-02-15-646.mp4

After:

bandicam.2022-05-05.21-07-11-692.mp4

Yellow X is shown before there are too many values and PR #763 is installed on my localhost.

I think MP4 needs to be downloaded for you to be able to see it. For me clicking PLAY button doesn't show any content. I can upload it somewhere else too.

Copy link
Contributor

@caugner caugner left a comment

Choose a reason for hiding this comment

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

What happens if you paste formatted text that you copied from another website or a Word document? Does Prism handle that correctly?

@caugner caugner self-requested a review May 5, 2022 20:41
@NiedziolkaMichal
Copy link
Member Author

It works well. There is a very short glimpse of styled content being placed, immediately replaced by formatted code replaced by Prism.

@NiedziolkaMichal
Copy link
Member Author

Thanks for review. That bug was really annoying, while working on new examples.

@caugner caugner merged commit 5beccb7 into mdn:main May 6, 2022
@wbamberg
Copy link
Collaborator

So much better!

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