Skip to content

Commit

Permalink
Merge pull request #17367 from ckeditor/ck/9646
Browse files Browse the repository at this point in the history
Fix (restricted-editing): Remove existing restricted editing markers when setting new data to prevent marker resurrection. Closes #9646, #16721
  • Loading branch information
Mati365 authored Nov 13, 2024
2 parents b13ebf6 + d46a2c2 commit c66459d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,17 @@ export default class RestrictedEditingModeEditing extends Plugin {
writer.addClass( 'ck-restricted-editing_mode_restricted', root );
}
} );

// Remove existing restricted editing markers when setting new data to prevent marker resurrection.
// Without this, markers from removed content would be incorrectly restored due to the resurrection mechanism.
// See more: https://github.com/ckeditor/ckeditor5/issues/9646#issuecomment-843064995
editor.data.on( 'set', () => {
editor.model.change( writer => {
for ( const marker of editor.model.markers.getMarkersGroup( 'restrictedEditingException' ) ) {
writer.removeMarker( marker.name );
}
} );
}, { priority: 'high' } );
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,26 @@ describe( 'RestrictedEditingModeEditing', () => {

expect( model.markers.has( 'restrictedEditingException:1' ) ).to.be.false;
} );

it( 'should remove previous `restrictedEditingException` markers before setting new ones', () => {
editor.setData(
'<figure class="table">' +
'<table><tbody><tr><td><span class="restricted-editing-exception">bar</span></td></tr></tbody></table>' +
'</figure>'
);

expect( model.markers.has( 'restrictedEditingException:1' ) ).to.be.true;
expect( model.markers.has( 'restrictedEditingException:2' ) ).to.be.false;

editor.setData(
'<figure class="table">' +
'<table><tbody><tr><td><span class="restricted-editing-exception">bar</span></td></tr></tbody></table>' +
'</figure>'
);

expect( model.markers.has( 'restrictedEditingException:1' ) ).to.be.false;
expect( model.markers.has( 'restrictedEditingException:2' ) ).to.be.true;
} );
} );

describe( 'downcast', () => {
Expand Down

0 comments on commit c66459d

Please sign in to comment.