|
@@ -8,9 +8,7 @@ import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtest
|
|
|
import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
|
|
import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
|
|
|
import Typing from '@ckeditor/ckeditor5-typing/src/typing';
|
|
import Typing from '@ckeditor/ckeditor5-typing/src/typing';
|
|
|
import Command from '@ckeditor/ckeditor5-core/src/command';
|
|
import Command from '@ckeditor/ckeditor5-core/src/command';
|
|
|
-import { getData as getModelData, setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
|
|
|
|
|
-import { getData as getViewData } from '@ckeditor/ckeditor5-engine/src/dev-utils/view';
|
|
|
|
|
-import { assertEqualMarkup } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
|
|
|
|
|
|
|
+import { setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
|
|
|
|
|
|
|
|
import RestrictedEditingEditing from './../src/restrictededitingediting';
|
|
import RestrictedEditingEditing from './../src/restrictededitingediting';
|
|
|
import UndoEditing from '@ckeditor/ckeditor5-undo/src/undoediting';
|
|
import UndoEditing from '@ckeditor/ckeditor5-undo/src/undoediting';
|
|
@@ -20,189 +18,6 @@ describe( 'RestrictedEditingEditing - commands', () => {
|
|
|
|
|
|
|
|
testUtils.createSinonSandbox();
|
|
testUtils.createSinonSandbox();
|
|
|
|
|
|
|
|
- describe( 'editing behavior', () => {
|
|
|
|
|
- let model;
|
|
|
|
|
-
|
|
|
|
|
- beforeEach( async () => {
|
|
|
|
|
- editor = await VirtualTestEditor.create( { plugins: [ Paragraph, Typing, RestrictedEditingEditing ] } );
|
|
|
|
|
- model = editor.model;
|
|
|
|
|
- } );
|
|
|
|
|
-
|
|
|
|
|
- afterEach( async () => {
|
|
|
|
|
- await editor.destroy();
|
|
|
|
|
- } );
|
|
|
|
|
-
|
|
|
|
|
- it( 'should keep markers in the view when editable region is edited', () => {
|
|
|
|
|
- setModelData( model,
|
|
|
|
|
- '<paragraph>foo bar baz</paragraph>' +
|
|
|
|
|
- '<paragraph>xxx y[]yy zzz</paragraph>'
|
|
|
|
|
- );
|
|
|
|
|
-
|
|
|
|
|
- const firstParagraph = model.document.getRoot().getChild( 0 );
|
|
|
|
|
- const secondParagraph = model.document.getRoot().getChild( 1 );
|
|
|
|
|
-
|
|
|
|
|
- model.change( writer => {
|
|
|
|
|
- writer.addMarker( 'restricted-editing-exception:1', {
|
|
|
|
|
- range: writer.createRange( writer.createPositionAt( firstParagraph, 4 ), writer.createPositionAt( firstParagraph, 7 ) ),
|
|
|
|
|
- usingOperation: true,
|
|
|
|
|
- affectsData: true
|
|
|
|
|
- } );
|
|
|
|
|
- writer.addMarker( 'restricted-editing-exception:2', {
|
|
|
|
|
- range: writer.createRange(
|
|
|
|
|
- writer.createPositionAt( secondParagraph, 4 ),
|
|
|
|
|
- writer.createPositionAt( secondParagraph, 7 )
|
|
|
|
|
- ),
|
|
|
|
|
- usingOperation: true,
|
|
|
|
|
- affectsData: true
|
|
|
|
|
- } );
|
|
|
|
|
- } );
|
|
|
|
|
-
|
|
|
|
|
- model.change( writer => {
|
|
|
|
|
- model.insertContent( writer.createText( 'R', model.document.selection.getAttributes() ) );
|
|
|
|
|
- } );
|
|
|
|
|
-
|
|
|
|
|
- const expectedView = '<p>foo <span class="ck-restricted-editing-exception">bar</span> baz</p>' +
|
|
|
|
|
- '<p>xxx <span class="ck-restricted-editing-exception">yRyy</span> zzz</p>';
|
|
|
|
|
-
|
|
|
|
|
- expect( editor.getData() ).to.equal( expectedView );
|
|
|
|
|
- expect( getViewData( editor.editing.view, { withoutSelection: true } ) ).to.equal( expectedView );
|
|
|
|
|
- } );
|
|
|
|
|
-
|
|
|
|
|
- it( 'should block user typing outside exception markers', () => {
|
|
|
|
|
- setModelData( model, '<paragraph>foo []bar baz</paragraph>' );
|
|
|
|
|
-
|
|
|
|
|
- editor.execute( 'input', { text: 'X' } );
|
|
|
|
|
-
|
|
|
|
|
- assertEqualMarkup( getModelData( model ), '<paragraph>foo []bar baz</paragraph>' );
|
|
|
|
|
- } );
|
|
|
|
|
-
|
|
|
|
|
- it( 'should not block user typing inside exception marker', () => {
|
|
|
|
|
- setModelData( model, '<paragraph>[]foo bar baz</paragraph>' );
|
|
|
|
|
- const firstParagraph = model.document.getRoot().getChild( 0 );
|
|
|
|
|
-
|
|
|
|
|
- model.change( writer => {
|
|
|
|
|
- writer.addMarker( 'restricted-editing-exception:1', {
|
|
|
|
|
- range: writer.createRange( writer.createPositionAt( firstParagraph, 4 ), writer.createPositionAt( firstParagraph, 7 ) ),
|
|
|
|
|
- usingOperation: true,
|
|
|
|
|
- affectsData: true
|
|
|
|
|
- } );
|
|
|
|
|
- } );
|
|
|
|
|
-
|
|
|
|
|
- model.change( writer => {
|
|
|
|
|
- writer.setSelection( firstParagraph, 5 );
|
|
|
|
|
- } );
|
|
|
|
|
- editor.execute( 'input', { text: 'X' } );
|
|
|
|
|
-
|
|
|
|
|
- assertEqualMarkup( getModelData( model ), '<paragraph>foo bX[]ar baz</paragraph>' );
|
|
|
|
|
- } );
|
|
|
|
|
-
|
|
|
|
|
- it( 'should extend maker when typing on the marker boundary (end)', () => {
|
|
|
|
|
- setModelData( model, '<paragraph>foo bar[] baz</paragraph>' );
|
|
|
|
|
- const firstParagraph = model.document.getRoot().getChild( 0 );
|
|
|
|
|
-
|
|
|
|
|
- model.change( writer => {
|
|
|
|
|
- writer.addMarker( 'restricted-editing-exception:1', {
|
|
|
|
|
- range: writer.createRange( writer.createPositionAt( firstParagraph, 4 ), writer.createPositionAt( firstParagraph, 7 ) ),
|
|
|
|
|
- usingOperation: true,
|
|
|
|
|
- affectsData: true
|
|
|
|
|
- } );
|
|
|
|
|
- } );
|
|
|
|
|
-
|
|
|
|
|
- editor.execute( 'input', { text: 'X' } );
|
|
|
|
|
-
|
|
|
|
|
- assertEqualMarkup( getModelData( model ), '<paragraph>foo barX[] baz</paragraph>' );
|
|
|
|
|
- const markerRange = editor.model.markers.get( 'restricted-editing-exception:1' ).getRange();
|
|
|
|
|
- const expectedRange = model.createRange(
|
|
|
|
|
- model.createPositionAt( firstParagraph, 4 ),
|
|
|
|
|
- model.createPositionAt( firstParagraph, 8 )
|
|
|
|
|
- );
|
|
|
|
|
-
|
|
|
|
|
- expect( markerRange.isEqual( expectedRange ) ).to.be.true;
|
|
|
|
|
- } );
|
|
|
|
|
-
|
|
|
|
|
- it( 'should extend marker when typing on the marker boundary (start)', () => {
|
|
|
|
|
- setModelData( model, '<paragraph>foo []bar baz</paragraph>' );
|
|
|
|
|
- const firstParagraph = model.document.getRoot().getChild( 0 );
|
|
|
|
|
-
|
|
|
|
|
- model.change( writer => {
|
|
|
|
|
- writer.addMarker( 'restricted-editing-exception:1', {
|
|
|
|
|
- range: writer.createRange( writer.createPositionAt( firstParagraph, 4 ), writer.createPositionAt( firstParagraph, 7 ) ),
|
|
|
|
|
- usingOperation: true,
|
|
|
|
|
- affectsData: true
|
|
|
|
|
- } );
|
|
|
|
|
- } );
|
|
|
|
|
-
|
|
|
|
|
- editor.execute( 'input', { text: 'X' } );
|
|
|
|
|
-
|
|
|
|
|
- assertEqualMarkup( getModelData( model ), '<paragraph>foo X[]bar baz</paragraph>' );
|
|
|
|
|
- const markerRange = editor.model.markers.get( 'restricted-editing-exception:1' ).getRange();
|
|
|
|
|
-
|
|
|
|
|
- const expectedRange = model.createRange(
|
|
|
|
|
- model.createPositionAt( firstParagraph, 4 ),
|
|
|
|
|
- model.createPositionAt( firstParagraph, 8 )
|
|
|
|
|
- );
|
|
|
|
|
-
|
|
|
|
|
- expect( markerRange.isEqual( expectedRange ) ).to.be.true;
|
|
|
|
|
- } );
|
|
|
|
|
-
|
|
|
|
|
- it( 'should extend marker when typing on the marker boundary (collapsed marker)', () => {
|
|
|
|
|
- setModelData( model, '<paragraph>[]foo bar baz</paragraph>' );
|
|
|
|
|
- const firstParagraph = model.document.getRoot().getChild( 0 );
|
|
|
|
|
-
|
|
|
|
|
- model.change( writer => {
|
|
|
|
|
- writer.addMarker( 'restricted-editing-exception:1', {
|
|
|
|
|
- range: writer.createRange( writer.createPositionAt( firstParagraph, 4 ) ),
|
|
|
|
|
- usingOperation: true,
|
|
|
|
|
- affectsData: true
|
|
|
|
|
- } );
|
|
|
|
|
- } );
|
|
|
|
|
-
|
|
|
|
|
- model.change( writer => {
|
|
|
|
|
- writer.setSelection( writer.createPositionAt( firstParagraph, 4 ) );
|
|
|
|
|
- } );
|
|
|
|
|
-
|
|
|
|
|
- editor.execute( 'input', { text: 'X' } );
|
|
|
|
|
-
|
|
|
|
|
- assertEqualMarkup( getModelData( model ), '<paragraph>foo X[]bar baz</paragraph>' );
|
|
|
|
|
- const markerRange = editor.model.markers.get( 'restricted-editing-exception:1' ).getRange();
|
|
|
|
|
-
|
|
|
|
|
- const expectedRange = model.createRange(
|
|
|
|
|
- model.createPositionAt( firstParagraph, 4 ),
|
|
|
|
|
- model.createPositionAt( firstParagraph, 5 )
|
|
|
|
|
- );
|
|
|
|
|
-
|
|
|
|
|
- expect( markerRange.isEqual( expectedRange ) ).to.be.true;
|
|
|
|
|
- } );
|
|
|
|
|
-
|
|
|
|
|
- it( 'should not move collapsed marker to $graveyard', () => {
|
|
|
|
|
- setModelData( model, '<paragraph>foo b[]ar baz</paragraph>' );
|
|
|
|
|
- const firstParagraph = model.document.getRoot().getChild( 0 );
|
|
|
|
|
-
|
|
|
|
|
- model.change( writer => {
|
|
|
|
|
- writer.addMarker( 'restricted-editing-exception:1', {
|
|
|
|
|
- range: writer.createRange(
|
|
|
|
|
- writer.createPositionAt( firstParagraph, 4 ),
|
|
|
|
|
- writer.createPositionAt( firstParagraph, 5 )
|
|
|
|
|
- ),
|
|
|
|
|
- usingOperation: true,
|
|
|
|
|
- affectsData: true
|
|
|
|
|
- } );
|
|
|
|
|
- } );
|
|
|
|
|
-
|
|
|
|
|
- editor.execute( 'delete' );
|
|
|
|
|
-
|
|
|
|
|
- assertEqualMarkup( getModelData( model ), '<paragraph>foo []ar baz</paragraph>' );
|
|
|
|
|
- const markerRange = editor.model.markers.get( 'restricted-editing-exception:1' ).getRange();
|
|
|
|
|
-
|
|
|
|
|
- const expectedRange = model.createRange(
|
|
|
|
|
- model.createPositionAt( firstParagraph, 4 ),
|
|
|
|
|
- model.createPositionAt( firstParagraph, 4 )
|
|
|
|
|
- );
|
|
|
|
|
-
|
|
|
|
|
- expect( markerRange.isEqual( expectedRange ) ).to.be.true;
|
|
|
|
|
- } );
|
|
|
|
|
- } );
|
|
|
|
|
-
|
|
|
|
|
describe( 'commands behavior', () => {
|
|
describe( 'commands behavior', () => {
|
|
|
let model, firstParagraph;
|
|
let model, firstParagraph;
|
|
|
|
|
|