-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Editor: Prevent switching editor tabs from marking content as dirty #6880
Conversation
5ab21c8
to
46adb12
Compare
46adb12
to
6c1fe8c
Compare
} | ||
if ( _rawContent !== _initialRawContent ) { | ||
return ( | ||
! isContentEmpty( _rawContent ) || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My thinking was to prevent raw content from being set as empty before allowing it to get to this point. Especially since isDirty
is run alot.
diff --git a/client/lib/posts/post-edit-store.js b/client/lib/posts/post-edit-store.js
index a8c695e..4777058 100644
--- a/client/lib/posts/post-edit-store.js
+++ b/client/lib/posts/post-edit-store.js
@@ -237,6 +237,8 @@ function normalize( post ) {
function setRawContent( content ) {
var isDirty, hasContent;
+ content = content.replace( REGEXP_EMPTY_CONTENT, '' );
+
if ( null === _initialRawContent ) {
debug( 'Set initial raw content to: %s', content );
_initialRawContent = content;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried this out, but it appears that TinyMCE is fighting with this content replacement. When switching between Visual and HTML tabs, I see the content ending up as <br />
, which is not currently considered "empty", so the post is still marked dirty. Also, the replacement unexpectedly clears the post content when you enter a blank line as the only content.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a feeling there may be some related issues around this line:
https://github.com/Automattic/wp-calypso/blob/76a4b7a/client/post-editor/post-editor.jsx#L753
Specifically, I was observing that when switching from HTML to Visual editors, it was setting the raw content without <p>
tags. I'm not sure this is the same root cause as what you were observing, but I have a feeling that the solution here won't cover all cases (e.g. when switching from HTML mode to Visual mode where multiple paragraphs exist, does it show as dirty?).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct, this PR does not address switching between HTML and Visual with content entered. I tried a couple of things without luck.
Closing as older and possibly abandoned. Feel free to re-open if still valid and in-progress. |
Fixes #6869 where switching between the Visual and HTML tabs would cause the post/page being edited to be marked as dirty.
This is because our
wpautop
filter and TinyMCE apply changes to empty content that makes it look like this:<p><br data-mce-bogus="1"></p>
We have an
isContentEmpty
function that accounts for this specific string, and we should use it to make sure that truly empty content is treated the same as the special empty content string above.This works well when the editor content is actually empty. Typing any text into the editor then switching tabs may still cause the post to be marked as dirty, but the fix for this situation is more involved because we will need to judiciously apply
wpautop
(right now we are not consistent about how this is done).The debug statement added here will come in handy for future related changes.
To test
/cc @aduth - I think you had a different idea about how to fix this, but I feel more comfortable with this simple approach, though it only works well with empty post content.
Test live: https://calypso.live/?branch=fix/editor/dirty-on-switch-tabs