Skip to content

Commit

Permalink
Merge pull request #9871 from ckeditor/ck/9650
Browse files Browse the repository at this point in the history
Fix (restricted-editing): Editor will not crash when a restricted area marker is removed. Closes #9650.
  • Loading branch information
niegowski committed Jun 15, 2021
2 parents b5aeb62 + ea16acf commit f358e6d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export function resurrectCollapsedMarkerPostFixer( editor ) {
let changeApplied = false;

for ( const { name, data } of editor.model.document.differ.getChangedMarkers() ) {
if ( name.startsWith( 'restrictedEditingException' ) && data.newRange.root.rootName == '$graveyard' ) {
if ( name.startsWith( 'restrictedEditingException' ) && data.newRange && data.newRange.root.rootName == '$graveyard' ) {
writer.updateMarker( name, {
range: writer.createRange( writer.createPositionAt( data.oldRange.start ) )
} );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,31 @@ describe( 'RestrictedEditingModeEditing', () => {
expect( markerRange.isEqual( expectedRange ) ).to.be.true;
} );

// https://github.com/ckeditor/ckeditor5/issues/9650
it( 'should not try to fix the marker if it was removed from markers collection', () => {
setModelData( model, '<paragraph>[]foo bar baz</paragraph>' );
const firstParagraph = model.document.getRoot().getChild( 0 );

model.change( writer => {
writer.addMarker( 'restrictedEditingException:1', {
range: writer.createRange(
writer.createPositionAt( firstParagraph, 4 ),
writer.createPositionAt( firstParagraph, 5 )
),
usingOperation: true,
affectsData: true
} );
} );

expect( () => {
model.change( writer => {
writer.removeMarker( 'restrictedEditingException:1' );
} );
} ).not.to.throw();

assertEqualMarkup( getModelData( model ), '<paragraph>[]foo bar baz</paragraph>' );
} );

it( 'should not move collapsed marker to $graveyard if it was removed by dragging', () => {
setModelData( model, '<paragraph>foo bar b[]az</paragraph>' );

Expand Down

0 comments on commit f358e6d

Please sign in to comment.