Opened 6 years ago
Closed 6 years ago
#45947 closed defect (bug) (fixed)
More tag breaks when switching from Text to Visual when cursor left in HTML
Reported by: | jeremeylduvall | Owned by: | azaozz |
---|---|---|---|
Milestone: | 5.1 | Priority: | normal |
Severity: | normal | Version: | 5.0.3 |
Component: | TinyMCE | Keywords: | has-patch needs-testing |
Focuses: | Cc: |
Description
Currently, in the classic WordPress editor, I'm hitting some issues with the "More" tag when flipping from Text to Visual.
For example:
- Open a new post.
- Flip to the Text editor and add some content.
- Use the toolbar button to insert a Read More tag.
- Place your cursor inside that tag. Click on the Visual editor.
The <!--more-->
tag is translated to:
" class="wp-more-tag mce-wp-more" alt="" title="Read more..." data-mce-resize="false" data-mce-placeholder="1" />
As a result, the tag no longer works. In my testing, this only happens when the cursor is left inside the tag when changing from Text to Visual.
Attachments (2)
Change History (9)
#3
@
6 years ago
- Component changed from Editor to TinyMCE
Possibly related https://core.trac.wordpress.org/ticket/42908
#4
@
6 years ago
The above ticket pointed me in the right direction. The solution here it to move the cursor outside of the HTML comment when switching views. This is already done for HTML tags and shortcodes.
I've also found that this will help with those editing ex-gutenberg posts, as this bug could mess up a post very badly otherwise.
Testing is fairly straightforward. Create HTML comments, and place your cursor inside of them while switching between visual and text mode. Patch incoming, and props to @davidsword for the regex help :)
@
6 years ago
First pass at 45947. Update regex to also match HTML comments to allow the cursor to always be moved outside of them when switching views.
I can replicate consistently. This also occurs with the
<!--nextpage-->
tag.It has to do with the content.replace() call here: https://github.com/WordPress/WordPress/blob/6ffafa5bc7124dd58a292720fea49465297f452c/wp-includes/js/tinymce/plugins/wordpress/plugin.js#L108
It also matters where your cursor is exactly. For example, if your cursor is between the
p
and thea
innextpage
before you switch back to the visual editor, you end up with this in the content:<!--nextp<span data-mce-type="bookmark" style="display: inline-block; width: 0px; overflow: hidden; line-height: 0;" class="mce_SELRES_start"></span>age-->
And when it is in between the
m
ando
inmore
:<!--m<span data-mce-type="bookmark" style="display: inline-block; width: 0px; overflow: hidden; line-height: 0;" class="mce_SELRES_start"></span>ore-->
A google search for
"data-mce-type="bookmark"
shows many other similar issues.