Skip to content

Commit

Permalink
Editor: Prevent switching editor tabs from marking content as dirty
Browse files Browse the repository at this point in the history
  • Loading branch information
nylen committed Jul 18, 2016
1 parent c080cfd commit 6c1fe8c
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 1 deletion.
18 changes: 17 additions & 1 deletion client/lib/posts/post-edit-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,23 @@ PostEditStore = {
},

isDirty: function() {
return _post !== _savedPost || _rawContent !== _initialRawContent;
debug(
'isDirty post?%s rawContent?%s initial=%s content=%s',
_post !== _savedPost,
_rawContent !== _initialRawContent,
_initialRawContent,
_rawContent
);
if ( _post !== _savedPost ) {
return true;
}
if ( _rawContent !== _initialRawContent ) {
return (
! isContentEmpty( _rawContent ) ||
! isContentEmpty( _initialRawContent )
);
}
return false;
},

isNew: function() {
Expand Down
50 changes: 50 additions & 0 deletions client/lib/posts/test/post-edit-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,56 @@ describe( 'post-edit-store', function() {

assert( PostEditStore.isDirty() );
} );

it( 'returns false if content changes from empty to <p><br></p>', function() {
dispatcherCallback( {
action: {
type: 'RECEIVE_POST_TO_EDIT',
post: {}
}
} );

dispatcherCallback( {
action: {
type: 'EDIT_POST_RAW_CONTENT',
content: ''
}
} );

dispatcherCallback( {
action: {
type: 'EDIT_POST_RAW_CONTENT',
content: '<p><br data-mce-bogus="1"></p>'
}
} );

assert( ! PostEditStore.isDirty() );
} );

it( 'returns false if content changes from <p><br></p> to empty', function() {
dispatcherCallback( {
action: {
type: 'RECEIVE_POST_TO_EDIT',
post: {}
}
} );

dispatcherCallback( {
action: {
type: 'EDIT_POST_RAW_CONTENT',
content: '<p><br data-mce-bogus="1"></p>'
}
} );

dispatcherCallback( {
action: {
type: 'EDIT_POST_RAW_CONTENT',
content: ''
}
} );

assert( ! PostEditStore.isDirty() );
} );
} );

describe( '#isSaveBlocked()', function() {
Expand Down

0 comments on commit 6c1fe8c

Please sign in to comment.