This repository has been archived by the owner on Jun 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1343 from ckeditor/t/1267
Fix: `model.DocumentSelection` should update it's attributes after each change, including external changes. Closes #1267.
- Loading branch information
Showing
3 changed files
with
127 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/** | ||
* @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved. | ||
* For licensing, see LICENSE.md. | ||
*/ | ||
|
||
/* globals document */ | ||
|
||
import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor'; | ||
import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph'; | ||
import Bold from '@ckeditor/ckeditor5-basic-styles/src/bold'; | ||
import Position from '../../src/model/position'; | ||
import Range from '../../src/model/range'; | ||
import { setData as setModelData, getData as getModelData } from '../../src/dev-utils/model'; | ||
|
||
describe( 'Bug ckeditor5-engine#1267', () => { | ||
let element, editor, model; | ||
|
||
beforeEach( () => { | ||
element = document.createElement( 'div' ); | ||
document.body.appendChild( element ); | ||
|
||
return ClassicTestEditor | ||
.create( element, { plugins: [ Paragraph, Bold ] } ) | ||
.then( newEditor => { | ||
editor = newEditor; | ||
model = editor.model; | ||
} ); | ||
} ); | ||
|
||
afterEach( () => { | ||
element.remove(); | ||
|
||
return editor.destroy(); | ||
} ); | ||
|
||
it( 'selection should not retain attributes after external change removal', () => { | ||
setModelData( model, | ||
'<paragraph>foo bar baz</paragraph>' + | ||
'<paragraph>foo <$text bold="true">bar{}</$text> baz</paragraph>' | ||
); | ||
|
||
// Remove second paragraph where selection is placed. | ||
model.enqueueChange( 'transparent', writer => { | ||
writer.remove( Range.createFromPositionAndShift( new Position( model.document.getRoot(), [ 1 ] ), 1 ) ); | ||
} ); | ||
|
||
expect( getModelData( model ) ).to.equal( '<paragraph>foo bar baz[]</paragraph>' ); | ||
} ); | ||
|
||
it( 'selection should retain attributes set manually', () => { | ||
setModelData( model, | ||
'<paragraph>foo bar baz</paragraph>' + | ||
'<paragraph>foo bar baz</paragraph>' + | ||
'<paragraph>[]</paragraph>' | ||
); | ||
|
||
// Execute bold command when selection is inside empty paragraph. | ||
editor.execute( 'bold' ); | ||
expect( getModelData( model ) ).to.equal( | ||
'<paragraph>foo bar baz</paragraph>' + | ||
'<paragraph>foo bar baz</paragraph>' + | ||
'<paragraph selection:bold="true"><$text bold="true">[]</$text></paragraph>' | ||
); | ||
|
||
// Remove second paragraph. | ||
model.enqueueChange( 'transparent', writer => { | ||
writer.remove( Range.createFromPositionAndShift( new Position( model.document.getRoot(), [ 1 ] ), 1 ) ); | ||
} ); | ||
|
||
// Selection attributes set by command should stay as they were. | ||
expect( getModelData( model ) ).to.equal( | ||
'<paragraph>foo bar baz</paragraph>' + | ||
'<paragraph selection:bold="true"><$text bold="true">[]</$text></paragraph>' ); | ||
} ); | ||
} ); |