| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378 |
- /**
- * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
- */
- import Model from '../../../src/model/model';
- import { injectSelectionPostFixer } from '../../../src/model/utils/selection-post-fixer';
- import { getData as getModelData, setData as setModelData } from '../../../src/dev-utils/model';
- import { assertEqualMarkup } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
- describe( 'Selection post-fixer', () => {
- describe( 'injectSelectionPostFixer()', () => {
- it( 'is a function', () => {
- expect( injectSelectionPostFixer ).to.be.a( 'function' );
- } );
- } );
- describe( 'injected behavior', () => {
- let model, modelRoot;
- beforeEach( () => {
- model = new Model();
- modelRoot = model.document.createRoot();
- model.schema.register( 'paragraph', { inheritAllFrom: '$block' } );
- model.schema.register( 'table', {
- allowWhere: '$block',
- allowAttributes: [ 'headingRows', 'headingColumns' ],
- isLimit: true,
- isObject: true
- } );
- model.schema.register( 'tableRow', {
- allowIn: 'table',
- isLimit: true
- } );
- model.schema.register( 'tableCell', {
- allowIn: 'tableRow',
- allowAttributes: [ 'colspan', 'rowspan' ],
- isLimit: true,
- isSelectable: true
- } );
- model.schema.extend( '$block', { allowIn: 'tableCell' } );
- model.schema.register( 'image', {
- isObject: true,
- isBlock: true,
- allowWhere: '$block'
- } );
- model.schema.extend( '$block', { allowIn: 'tableCell' } );
- model.schema.register( 'caption', {
- allowIn: 'image',
- allowContentOf: '$block',
- isLimit: true
- } );
- model.schema.register( 'inlineWidget', {
- isObject: true,
- allowIn: [ '$block', '$clipboardHolder' ]
- } );
- model.schema.register( 'figure', {
- allowIn: '$root',
- allowAttributes: [ 'name', 'title' ]
- } );
- } );
- it( 'should not crash if there is no correct position for model selection', () => {
- setModelData( model, '' );
- // Note that auto-paragraphing post-fixer injected a paragraph into the empty root.
- expect( getModelData( model ) ).to.equal( '<paragraph>[]</paragraph>' );
- } );
- it( 'should react to structure changes', () => {
- setModelData( model, '<paragraph>[]foo</paragraph><image></image>' );
- model.change( writer => {
- writer.remove( modelRoot.getChild( 0 ) );
- } );
- expect( getModelData( model ) ).to.equal( '[<image></image>]' );
- } );
- it( 'should react to selection changes', () => {
- setModelData( model, '<paragraph>[]foo</paragraph><image></image>' );
- // <paragraph>foo</paragraph>[]<image></image>
- model.change( writer => {
- writer.setSelection(
- writer.createRange( writer.createPositionAt( modelRoot, 1 ), writer.createPositionAt( modelRoot, 1 ) )
- );
- } );
- expect( getModelData( model ) ).to.equal( '<paragraph>foo[]</paragraph><image></image>' );
- } );
- describe( 'selection - table scenarios', () => {
- beforeEach( () => {
- setModelData( model,
- '<paragraph>[]foo</paragraph>' +
- '<table>' +
- '<tableRow>' +
- '<tableCell><paragraph>aaa</paragraph></tableCell>' +
- '<tableCell><paragraph>bbb</paragraph></tableCell>' +
- '</tableRow>' +
- '</table>' +
- '<paragraph>bar</paragraph>'
- );
- } );
- it( 'should fix #1 (range start outside table, end on table cell)', () => {
- // <paragraph>f[oo</paragraph><table><tableRow><tableCell></tableCell>]<tableCell>...
- model.change( writer => {
- writer.setSelection( writer.createRange(
- writer.createPositionAt( modelRoot.getChild( 0 ), 1 ),
- writer.createPositionAt( modelRoot.getChild( 1 ).getChild( 0 ), 1 )
- ) );
- } );
- expect( getModelData( model ) ).to.equal(
- '<paragraph>f[oo</paragraph>' +
- '<table>' +
- '<tableRow>' +
- '<tableCell><paragraph>aaa</paragraph></tableCell>' +
- '<tableCell><paragraph>bbb</paragraph></tableCell>' +
- '</tableRow>' +
- '</table>]' +
- '<paragraph>bar</paragraph>'
- );
- } );
- it( 'should fix #2 (range start on table cell, end outside table)', () => {
- // ...<table><tableRow><tableCell></tableCell>[<tableCell></tableCell></tableRow></table><paragraph>b]ar</paragraph>
- model.change( writer => {
- writer.setSelection( writer.createRange(
- writer.createPositionAt( modelRoot.getChild( 1 ).getChild( 0 ), 1 ),
- writer.createPositionAt( modelRoot.getChild( 2 ), 1 )
- ) );
- } );
- expect( getModelData( model ) ).to.equal(
- '<paragraph>foo</paragraph>' +
- '[<table>' +
- '<tableRow>' +
- '<tableCell><paragraph>aaa</paragraph></tableCell>' +
- '<tableCell><paragraph>bbb</paragraph></tableCell>' +
- '</tableRow>' +
- '</table>' +
- '<paragraph>b]ar</paragraph>'
- );
- } );
- it( 'should fix #3', () => {
- // <paragraph>f[oo</paragraph><table>]<tableRow>...
- model.change( writer => {
- writer.setSelection( writer.createRange(
- writer.createPositionAt( modelRoot.getChild( 0 ), 1 ),
- writer.createPositionAt( modelRoot.getChild( 1 ), 0 )
- ) );
- } );
- expect( getModelData( model ) ).to.equal(
- '<paragraph>f[oo</paragraph>' +
- '<table>' +
- '<tableRow>' +
- '<tableCell><paragraph>aaa</paragraph></tableCell>' +
- '<tableCell><paragraph>bbb</paragraph></tableCell>' +
- '</tableRow>' +
- '</table>]' +
- '<paragraph>bar</paragraph>'
- );
- } );
- it( 'should fix #4', () => {
- // <paragraph>foo</paragraph><table><tableRow><tableCell>a[aa</tableCell><tableCell>b]bb</tableCell>
- model.change( writer => {
- writer.setSelection( writer.createRange(
- writer.createPositionAt( modelRoot.getNodeByPath( [ 1, 0, 0, 0 ] ), 1 ),
- writer.createPositionAt( modelRoot.getNodeByPath( [ 1, 0, 1, 0 ] ), 2 )
- ) );
- } );
- expect( getModelData( model ) ).to.equal(
- '<paragraph>foo</paragraph>' +
- '[<table>' +
- '<tableRow>' +
- '<tableCell><paragraph>aaa</paragraph></tableCell>' +
- '<tableCell><paragraph>bbb</paragraph></tableCell>' +
- '</tableRow>' +
- '</table>]' +
- '<paragraph>bar</paragraph>'
- );
- } );
- it( 'should fix #5 (collapsed selection between tables)', () => {
- setModelData( model,
- '<paragraph>foo</paragraph>' +
- '<table>' +
- '<tableRow>' +
- '<tableCell><paragraph>aaa</paragraph></tableCell>' +
- '<tableCell><paragraph>bbb</paragraph></tableCell>' +
- '</tableRow>' +
- '</table>' +
- '[]' +
- '<table>' +
- '<tableRow>' +
- '<tableCell><paragraph>xxx</paragraph></tableCell>' +
- '<tableCell><paragraph>yyy</paragraph></tableCell>' +
- '</tableRow>' +
- '</table>' +
- '<paragraph>baz</paragraph>'
- );
- assertEqualMarkup( getModelData( model ),
- '<paragraph>foo</paragraph>' +
- '[<table>' +
- '<tableRow>' +
- '<tableCell><paragraph>aaa</paragraph></tableCell>' +
- '<tableCell><paragraph>bbb</paragraph></tableCell>' +
- '</tableRow>' +
- '</table>]' +
- '<table>' +
- '<tableRow>' +
- '<tableCell><paragraph>xxx</paragraph></tableCell>' +
- '<tableCell><paragraph>yyy</paragraph></tableCell>' +
- '</tableRow>' +
- '</table>' +
- '<paragraph>baz</paragraph>'
- );
- } );
- // There's a chance that this and the following test will not be up to date with
- // how the table feature is really implemented once we'll introduce row/cells/columns selection
- // in which case all these elements will need to be marked as objects.
- it( 'should fix #6 (element selection of not an object)', () => {
- setModelData( model,
- '<paragraph>foo</paragraph>' +
- '<table>' +
- '[<tableRow>' +
- '<tableCell><paragraph>aaa</paragraph></tableCell>' +
- '<tableCell><paragraph>bbb</paragraph></tableCell>' +
- '</tableRow>]' +
- '</table>' +
- '<paragraph>baz</paragraph>'
- );
- expect( getModelData( model ) ).to.equal(
- '<paragraph>foo</paragraph>' +
- '[<table>' +
- '<tableRow>' +
- '<tableCell><paragraph>aaa</paragraph></tableCell>' +
- '<tableCell><paragraph>bbb</paragraph></tableCell>' +
- '</tableRow>' +
- '</table>]' +
- '<paragraph>baz</paragraph>'
- );
- } );
- it( 'should fix #7 (element selection of non-objects)', () => {
- setModelData( model,
- '<paragraph>foo</paragraph>' +
- '<table>' +
- '[<tableRow>' +
- '<tableCell><paragraph>1</paragraph></tableCell>' +
- '<tableCell><paragraph>2</paragraph></tableCell>' +
- '</tableRow>' +
- '<tableRow>' +
- '<tableCell><paragraph>3</paragraph></tableCell>' +
- '<tableCell><paragraph>4</paragraph></tableCell>]' +
- '</tableRow>' +
- '<tableRow>' +
- '<tableCell><paragraph>5</paragraph></tableCell>' +
- '<tableCell><paragraph>6</paragraph></tableCell>' +
- '</tableRow>' +
- '</table>' +
- '<paragraph>baz</paragraph>'
- );
- expect( getModelData( model ) ).to.equal(
- '<paragraph>foo</paragraph>' +
- '[<table>' +
- '<tableRow>' +
- '<tableCell><paragraph>1</paragraph></tableCell>' +
- '<tableCell><paragraph>2</paragraph></tableCell>' +
- '</tableRow>' +
- '<tableRow>' +
- '<tableCell><paragraph>3</paragraph></tableCell>' +
- '<tableCell><paragraph>4</paragraph></tableCell>' +
- '</tableRow>' +
- '<tableRow>' +
- '<tableCell><paragraph>5</paragraph></tableCell>' +
- '<tableCell><paragraph>6</paragraph></tableCell>' +
- '</tableRow>' +
- '</table>]' +
- '<paragraph>baz</paragraph>'
- );
- } );
- it( 'should fix #8 (cross-limit selection which starts in a non-limit elements)', () => {
- model.schema.extend( 'paragraph', { allowIn: 'tableCell' } );
- setModelData( model,
- '<paragraph>foo</paragraph>' +
- '<table>' +
- '<tableRow>' +
- '<tableCell><paragraph>f[oo</paragraph></tableCell>' +
- '<tableCell><paragraph>b]ar</paragraph></tableCell>' +
- '</tableRow>' +
- '</table>' +
- '<paragraph>baz</paragraph>'
- );
- expect( getModelData( model ) ).to.equal(
- '<paragraph>foo</paragraph>' +
- '[<table>' +
- '<tableRow>' +
- '<tableCell><paragraph>foo</paragraph></tableCell>' +
- '<tableCell><paragraph>bar</paragraph></tableCell>' +
- '</tableRow>' +
- '</table>]' +
- '<paragraph>baz</paragraph>'
- );
- } );
- it( 'should not fix #1 (selection over paragraphs outside table)', () => {
- setModelData( model,
- '<paragraph>foo</paragraph>' +
- '<table>' +
- '<tableRow>' +
- '<tableCell><paragraph>aaa</paragraph></tableCell>' +
- '<tableCell><paragraph>bbb</paragraph></tableCell>' +
- '</tableRow>' +
- '</table>' +
- '<paragraph>b[ar</paragraph>' +
- '<paragraph>ba]z</paragraph>'
- );
- expect( getModelData( model ) ).to.equal(
- '<paragraph>foo</paragraph>' +
- '<table>' +
- '<tableRow>' +
- '<tableCell><paragraph>aaa</paragraph></tableCell>' +
- '<tableCell><paragraph>bbb</paragraph></tableCell>' +
- '</tableRow>' +
- '</table>' +
- '<paragraph>b[ar</paragraph>' +
- '<paragraph>ba]z</paragraph>'
- );
- } );
- it( 'should not fix #2 (selection over image in table)', () => {
- setModelData( model,
- '<paragraph>foo</paragraph>' +
- '<table>' +
- '<tableRow>' +
- '<tableCell><paragraph>foo</paragraph><image></image></tableCell>' +
- '<tableCell><paragraph>[]bbb</paragraph></tableCell>' +
- '</tableRow>' +
- '</table>'
- );
- model.change( writer => {
- const image = model.document.getRoot().getNodeByPath( [ 1, 0, 0, 1 ] );
- writer.setSelection( writer.createRangeOn( image ) );
- } );
- expect( getModelData( model ) ).to.equal(
- '<paragraph>foo</paragraph>' +
- '<table>' +
- '<tableRow>' +
- '<tableCell><paragraph>foo</paragraph>[<image></image>]</tableCell>' +
- '<tableCell><paragraph>bbb</paragraph></tableCell>' +
- '</tableRow>' +
- '</table>'
- );
- } );
- it( 'should not fix #3 (selection over paragraph & image in table)', () => {
- setModelData( model,
- '<paragraph>foo</paragraph>' +
- '<table>' +
- '<tableRow>' +
- '<tableCell><paragraph>foo</paragraph><image></image></tableCell>' +
- '<tableCell><paragraph>[]bbb</paragraph></tableCell>' +
- '</tableRow>' +
- '</table>'
- );
- model.change( writer => {
- const tableCell = model.document.getRoot().getNodeByPath( [ 1, 0, 0 ] );
- writer.setSelection( writer.createRangeIn( tableCell ) );
- } );
- expect( getModelData( model ) ).to.equal(
- '<paragraph>foo</paragraph>' +
- '<table>' +
- '<tableRow>' +
- '<tableCell><paragraph>[foo</paragraph><image></image>]</tableCell>' +
- '<tableCell><paragraph>bbb</paragraph></tableCell>' +
- '</tableRow>' +
- '</table>'
- );
- } );
- it( 'should not fix #4 (selection over image & paragraph in table)', () => {
- setModelData( model,
- '<paragraph>foo</paragraph>' +
- '<table>' +
- '<tableRow>' +
- '<tableCell><image></image><paragraph>foo</paragraph></tableCell>' +
- '<tableCell><paragraph>[]bbb</paragraph></tableCell>' +
- '</tableRow>' +
- '</table>'
- );
- model.change( writer => {
- const tableCell = model.document.getRoot().getNodeByPath( [ 1, 0, 0 ] );
- writer.setSelection( writer.createRangeIn( tableCell ) );
- } );
- expect( getModelData( model ) ).to.equal(
- '<paragraph>foo</paragraph>' +
- '<table>' +
- '<tableRow>' +
- '<tableCell>[<image></image><paragraph>foo]</paragraph></tableCell>' +
- '<tableCell><paragraph>bbb</paragraph></tableCell>' +
- '</tableRow>' +
- '</table>'
- );
- } );
- it( 'should not fix #5 (selection over blockQuote in table)', () => {
- model.schema.register( 'blockQuote', {
- allowWhere: '$block',
- allowContentOf: '$root'
- } );
- setModelData( model,
- '<paragraph>foo</paragraph>' +
- '<table>' +
- '<tableRow>' +
- '<tableCell><blockQuote><paragraph>foo</paragraph></blockQuote></tableCell>' +
- '<tableCell><paragraph>[]bbb</paragraph></tableCell>' +
- '</tableRow>' +
- '</table>'
- );
- model.change( writer => {
- const tableCell = model.document.getRoot().getNodeByPath( [ 1, 0, 0 ] );
- writer.setSelection( writer.createRangeIn( tableCell ) );
- } );
- expect( getModelData( model ) ).to.equal(
- '<paragraph>foo</paragraph>' +
- '<table>' +
- '<tableRow>' +
- '<tableCell><blockQuote><paragraph>[foo]</paragraph></blockQuote></tableCell>' +
- '<tableCell><paragraph>bbb</paragraph></tableCell>' +
- '</tableRow>' +
- '</table>'
- );
- } );
- it( 'should fix multiple ranges #1', () => {
- model.change( writer => {
- const ranges = [
- writer.createRange(
- writer.createPositionFromPath( modelRoot, [ 0, 1 ] ),
- writer.createPositionFromPath( modelRoot, [ 1, 0 ] )
- ),
- writer.createRange(
- writer.createPositionFromPath( modelRoot, [ 1, 0, 0, 0 ] ),
- writer.createPositionFromPath( modelRoot, [ 1, 1 ] )
- )
- ];
- writer.setSelection( ranges );
- } );
- expect( getModelData( model ) ).to.equal(
- '<paragraph>f[oo</paragraph>' +
- '<table>' +
- '<tableRow>' +
- '<tableCell><paragraph>aaa</paragraph></tableCell>' +
- '<tableCell><paragraph>bbb</paragraph></tableCell>' +
- '</tableRow>' +
- '</table>]' +
- '<paragraph>bar</paragraph>'
- );
- } );
- it( 'should fix multiple ranges #2', () => {
- model.change( writer => {
- const ranges = [
- writer.createRange(
- writer.createPositionFromPath( modelRoot, [ 0, 1 ] ),
- writer.createPositionFromPath( modelRoot, [ 1, 0 ] )
- ),
- writer.createRange(
- writer.createPositionFromPath( modelRoot, [ 1, 0, 0, 0 ] ),
- writer.createPositionFromPath( modelRoot, [ 2, 2 ] )
- )
- ];
- writer.setSelection( ranges );
- } );
- expect( getModelData( model ) ).to.equal(
- '<paragraph>f[oo</paragraph>' +
- '<table>' +
- '<tableRow>' +
- '<tableCell><paragraph>aaa</paragraph></tableCell>' +
- '<tableCell><paragraph>bbb</paragraph></tableCell>' +
- '</tableRow>' +
- '</table>' +
- '<paragraph>ba]r</paragraph>'
- );
- } );
- it( 'should fix multiple ranges #3', () => {
- setModelData( model,
- '<paragraph>foo</paragraph>' +
- '<table>' +
- '<tableRow>' +
- '<tableCell><paragraph>[aaa</paragraph></tableCell>' +
- '<tableCell><paragraph>bbb</paragraph></tableCell>' +
- '</tableRow>' +
- '<tableRow>]' +
- '<tableCell><paragraph>[aaa</paragraph></tableCell>' +
- '<tableCell><paragraph>bbb</paragraph></tableCell>' +
- '</tableRow>' +
- '<tableRow>]' +
- '<tableCell><paragraph>[aaa</paragraph></tableCell>' +
- '<tableCell><paragraph>bbb</paragraph></tableCell>' +
- '</tableRow>' +
- '<tableRow>]' +
- '<tableCell><paragraph>[aaa</paragraph></tableCell>' +
- '<tableCell><paragraph>bbb</paragraph></tableCell>' +
- '</tableRow>' +
- '</table>' +
- '<paragraph>b]az</paragraph>'
- );
- expect( getModelData( model ) ).to.equal(
- '<paragraph>foo</paragraph>' +
- '[<table>' +
- '<tableRow>' +
- '<tableCell><paragraph>aaa</paragraph></tableCell>' +
- '<tableCell><paragraph>bbb</paragraph></tableCell>' +
- '</tableRow>' +
- '<tableRow>' +
- '<tableCell><paragraph>aaa</paragraph></tableCell>' +
- '<tableCell><paragraph>bbb</paragraph></tableCell>' +
- '</tableRow>' +
- '<tableRow>' +
- '<tableCell><paragraph>aaa</paragraph></tableCell>' +
- '<tableCell><paragraph>bbb</paragraph></tableCell>' +
- '</tableRow>' +
- '<tableRow>' +
- '<tableCell><paragraph>aaa</paragraph></tableCell>' +
- '<tableCell><paragraph>bbb</paragraph></tableCell>' +
- '</tableRow>' +
- '</table>' +
- '<paragraph>b]az</paragraph>'
- );
- } );
- it( 'should not fix multiple ranges #1 (not overlapping ranges)', () => {
- model.change( writer => {
- const ranges = [
- writer.createRange(
- writer.createPositionFromPath( modelRoot, [ 0, 1 ] ),
- writer.createPositionFromPath( modelRoot, [ 1, 0 ] )
- ),
- writer.createRange(
- writer.createPositionFromPath( modelRoot, [ 1, 0, 0, 0 ] ),
- writer.createPositionFromPath( modelRoot, [ 2, 1 ] )
- ),
- writer.createRange(
- writer.createPositionFromPath( modelRoot, [ 2, 2 ] ),
- writer.createPositionFromPath( modelRoot, [ 2, 3 ] )
- )
- ];
- writer.setSelection( ranges );
- } );
- expect( getModelData( model ) ).to.equal(
- '<paragraph>f[oo</paragraph>' +
- '<table>' +
- '<tableRow>' +
- '<tableCell><paragraph>aaa</paragraph></tableCell>' +
- '<tableCell><paragraph>bbb</paragraph></tableCell>' +
- '</tableRow>' +
- '</table>' +
- '<paragraph>b]a[r]</paragraph>'
- );
- } );
- it( 'should not fix multiple ranges on objects (table selection)', () => {
- setModelData( model,
- '<table>' +
- '<tableRow>' +
- '[<tableCell><paragraph>a</paragraph></tableCell>]' +
- '[<tableCell><paragraph>b</paragraph></tableCell>]' +
- '</tableRow>' +
- '<tableRow>' +
- '[<tableCell><paragraph>c</paragraph></tableCell>]' +
- '<tableCell><paragraph>d</paragraph></tableCell>' +
- '</tableRow>' +
- '</table>'
- );
- assertEqualMarkup( getModelData( model ),
- '<table>' +
- '<tableRow>' +
- '[<tableCell><paragraph>a</paragraph></tableCell>]' +
- '[<tableCell><paragraph>b</paragraph></tableCell>]' +
- '</tableRow>' +
- '<tableRow>' +
- '[<tableCell><paragraph>c</paragraph></tableCell>]' +
- '<tableCell><paragraph>d</paragraph></tableCell>' +
- '</tableRow>' +
- '</table>'
- );
- } );
- it( 'should fix selection on block', () => {
- model.schema.extend( '$block', { allowIn: 'tableCell' } );
- setModelData( model,
- '<table>' +
- '<tableRow><tableCell>[<paragraph>aaa</paragraph>]</tableCell></tableRow>' +
- '</table>'
- );
- assertEqualMarkup( getModelData( model ),
- '<table>' +
- '<tableRow><tableCell><paragraph>[aaa]</paragraph></tableCell></tableRow>' +
- '</table>'
- );
- } );
- it( 'should allow multi-range selection on non-continues blocks (column selected)', () => {
- setModelData( model,
- '<table>' +
- '<tableRow>' +
- '[<tableCell><paragraph>A1</paragraph></tableCell>]' +
- '<tableCell><paragraph>B1</paragraph></tableCell>' +
- '</tableRow>' +
- '<tableRow>' +
- '[<tableCell><paragraph>A2</paragraph></tableCell>]' +
- '<tableCell><paragraph>B2</paragraph></tableCell>' +
- '</tableRow>' +
- '<tableRow>' +
- '[<tableCell><paragraph>A3</paragraph></tableCell>]' +
- '<tableCell><paragraph>B3</paragraph></tableCell>' +
- '</tableRow>' +
- '</table>'
- );
- assertEqualMarkup( getModelData( model ),
- '<table>' +
- '<tableRow>' +
- '[<tableCell><paragraph>A1</paragraph></tableCell>]' +
- '<tableCell><paragraph>B1</paragraph></tableCell>' +
- '</tableRow>' +
- '<tableRow>' +
- '[<tableCell><paragraph>A2</paragraph></tableCell>]' +
- '<tableCell><paragraph>B2</paragraph></tableCell>' +
- '</tableRow>' +
- '<tableRow>' +
- '[<tableCell><paragraph>A3</paragraph></tableCell>]' +
- '<tableCell><paragraph>B3</paragraph></tableCell>' +
- '</tableRow>' +
- '</table>'
- );
- } );
- it( 'should allow multi-range selection on continues blocks (row selected)', () => {
- setModelData( model,
- '<table>' +
- '<tableRow>' +
- '<tableCell><paragraph>A1</paragraph></tableCell>' +
- '<tableCell><paragraph>B1</paragraph></tableCell>' +
- '<tableCell><paragraph>C1</paragraph></tableCell>' +
- '</tableRow>' +
- '<tableRow>' +
- '[<tableCell><paragraph>A2</paragraph></tableCell>]' +
- '[<tableCell><paragraph>B2</paragraph></tableCell>]' +
- '[<tableCell><paragraph>C2</paragraph></tableCell>]' +
- '</tableRow>' +
- '<tableRow>' +
- '<tableCell><paragraph>A3</paragraph></tableCell>' +
- '<tableCell><paragraph>B3</paragraph></tableCell>' +
- '<tableCell><paragraph>C3</paragraph></tableCell>' +
- '</tableRow>' +
- '</table>'
- );
- assertEqualMarkup( getModelData( model ),
- '<table>' +
- '<tableRow>' +
- '<tableCell><paragraph>A1</paragraph></tableCell>' +
- '<tableCell><paragraph>B1</paragraph></tableCell>' +
- '<tableCell><paragraph>C1</paragraph></tableCell>' +
- '</tableRow>' +
- '<tableRow>' +
- '[<tableCell><paragraph>A2</paragraph></tableCell>]' +
- '[<tableCell><paragraph>B2</paragraph></tableCell>]' +
- '[<tableCell><paragraph>C2</paragraph></tableCell>]' +
- '</tableRow>' +
- '<tableRow>' +
- '<tableCell><paragraph>A3</paragraph></tableCell>' +
- '<tableCell><paragraph>B3</paragraph></tableCell>' +
- '<tableCell><paragraph>C3</paragraph></tableCell>' +
- '</tableRow>' +
- '</table>'
- );
- } );
- it( 'should allow multi-range selection with mixed continues/non-continues blocks (part of table selected)', () => {
- setModelData( model,
- '<table>' +
- '<tableRow>' +
- '<tableCell><paragraph>A1</paragraph></tableCell>' +
- '<tableCell><paragraph>B1</paragraph></tableCell>' +
- '<tableCell><paragraph>C1</paragraph></tableCell>' +
- '</tableRow>' +
- '<tableRow>' +
- '<tableCell><paragraph>A2</paragraph></tableCell>' +
- '[<tableCell><paragraph>B2</paragraph></tableCell>]' +
- '[<tableCell><paragraph>C2</paragraph></tableCell>]' +
- '</tableRow>' +
- '<tableRow>' +
- '<tableCell><paragraph>A3</paragraph></tableCell>' +
- '[<tableCell><paragraph>B3</paragraph></tableCell>]' +
- '[<tableCell><paragraph>C3</paragraph></tableCell>]' +
- '</tableRow>' +
- '</table>'
- );
- assertEqualMarkup( getModelData( model ),
- '<table>' +
- '<tableRow>' +
- '<tableCell><paragraph>A1</paragraph></tableCell>' +
- '<tableCell><paragraph>B1</paragraph></tableCell>' +
- '<tableCell><paragraph>C1</paragraph></tableCell>' +
- '</tableRow>' +
- '<tableRow>' +
- '<tableCell><paragraph>A2</paragraph></tableCell>' +
- '[<tableCell><paragraph>B2</paragraph></tableCell>]' +
- '[<tableCell><paragraph>C2</paragraph></tableCell>]' +
- '</tableRow>' +
- '<tableRow>' +
- '<tableCell><paragraph>A3</paragraph></tableCell>' +
- '[<tableCell><paragraph>B3</paragraph></tableCell>]' +
- '[<tableCell><paragraph>C3</paragraph></tableCell>]' +
- '</tableRow>' +
- '</table>'
- );
- } );
- it( 'should not fix ranges in multi-range selection (each range set differently - but valid)', () => {
- setModelData( model,
- '<paragraph>[foo]</paragraph>' +
- '<table>' +
- '<tableRow>' +
- '[<tableCell><paragraph>aaa</paragraph></tableCell>]' +
- '<tableCell><paragraph>[bbb]</paragraph></tableCell>' +
- '</tableRow>' +
- '</table>'
- );
- assertEqualMarkup( getModelData( model ),
- '<paragraph>[foo]</paragraph>' +
- '<table>' +
- '<tableRow>' +
- '[<tableCell><paragraph>aaa</paragraph></tableCell>]' +
- '<tableCell><paragraph>[bbb]</paragraph></tableCell>' +
- '</tableRow>' +
- '</table>'
- );
- } );
- it( 'should fix partially wrong selection (last range is post-fixed on whole table)', () => {
- setModelData( model,
- '<table>' +
- '<tableRow>' +
- '[<tableCell><paragraph>aaa</paragraph></tableCell>]' +
- '<tableCell><paragraph>bbb</paragraph></tableCell>' +
- '[<tableCell><paragraph>ccc</paragraph></tableCell>' +
- '</tableRow>]' +
- '</table>'
- );
- assertEqualMarkup( getModelData( model ),
- '[<table>' +
- '<tableRow>' +
- '<tableCell><paragraph>aaa</paragraph></tableCell>' +
- '<tableCell><paragraph>bbb</paragraph></tableCell>' +
- '<tableCell><paragraph>ccc</paragraph></tableCell>' +
- '</tableRow>' +
- '</table>]'
- );
- } );
- it( 'should fix partially wrong selection (first range is post-fixed on whole table)', () => {
- setModelData( model,
- '<table>' +
- '[<tableRow>' +
- '<tableCell><paragraph>aaa</paragraph></tableCell>]' +
- '<tableCell><paragraph>bbb</paragraph></tableCell>' +
- '[<tableCell><paragraph>ccc</paragraph></tableCell>]' +
- '</tableRow>' +
- '</table>'
- );
- assertEqualMarkup( getModelData( model ),
- '[<table>' +
- '<tableRow>' +
- '<tableCell><paragraph>aaa</paragraph></tableCell>' +
- '<tableCell><paragraph>bbb</paragraph></tableCell>' +
- '<tableCell><paragraph>ccc</paragraph></tableCell>' +
- '</tableRow>' +
- '</table>]'
- );
- } );
- it( 'should not reset the selection if the final range is the same as the initial one', () => {
- setModelData( model,
- '<table>' +
- '<tableRow>' +
- '<tableCell>[<image></image>]</tableCell>' +
- '</tableRow>' +
- '</table>'
- );
- // Setting a selection attribute will trigger the post-fixer. However, because this
- // action does not affect ranges, the post-fixer should not set a new selection and,
- // in consequence, should not clear the selection attribute (like it normally would when
- // a new selection is set).
- // https://github.com/ckeditor/ckeditor5/issues/6693
- model.change( writer => {
- writer.setSelectionAttribute( 'foo', 'bar' );
- } );
- assertEqualMarkup( getModelData( model ),
- '<table>' +
- '<tableRow>' +
- '<tableCell>[<image></image>]</tableCell>' +
- '</tableRow>' +
- '</table>'
- );
- expect( model.document.selection.hasAttribute( 'foo' ) ).to.be.true;
- } );
- } );
- describe( 'non-collapsed selection - image scenarios', () => {
- beforeEach( () => {
- setModelData( model,
- '<paragraph>[]foo</paragraph>' +
- '<image>' +
- '<caption>xxx</caption>' +
- '</image>' +
- '<paragraph>bar</paragraph>'
- );
- } );
- it( 'should fix #1 (crossing object and limit boundaries)', () => {
- model.change( writer => {
- // <paragraph>f[oo</paragraph><image><caption>x]xx</caption>...
- writer.setSelection( writer.createRange(
- writer.createPositionAt( modelRoot.getChild( 0 ), 1 ),
- writer.createPositionAt( modelRoot.getChild( 1 ).getChild( 0 ), 1 )
- ) );
- } );
- expect( getModelData( model ) ).to.equal(
- '<paragraph>f[oo</paragraph>' +
- '<image>' +
- '<caption>xxx</caption>' +
- '</image>]' +
- '<paragraph>bar</paragraph>'
- );
- } );
- it( 'should fix #2 (crossing object boundary)', () => {
- model.change( writer => {
- // <paragraph>f[oo</paragraph><image>]<caption>xxx</caption>...
- writer.setSelection( writer.createRange(
- writer.createPositionAt( modelRoot.getChild( 0 ), 1 ),
- writer.createPositionAt( modelRoot.getChild( 1 ), 0 )
- ) );
- } );
- expect( getModelData( model ) ).to.equal(
- '<paragraph>f[oo</paragraph>' +
- '<image>' +
- '<caption>xxx</caption>' +
- '</image>]' +
- '<paragraph>bar</paragraph>'
- );
- } );
- it( 'should fix #3 (crossing object boundary)', () => {
- model.change( writer => {
- // <paragraph>f[oo</paragraph><image><caption>xxx</caption>]</image>...
- writer.setSelection( writer.createRange(
- writer.createPositionAt( modelRoot.getChild( 0 ), 1 ),
- writer.createPositionAt( modelRoot.getChild( 1 ), 1 )
- ) );
- } );
- expect( getModelData( model ) ).to.equal(
- '<paragraph>f[oo</paragraph>' +
- '<image>' +
- '<caption>xxx</caption>' +
- '</image>]' +
- '<paragraph>bar</paragraph>'
- );
- } );
- it( 'should fix #4 (element selection of not an object)', () => {
- model.change( writer => {
- // <paragraph>foo</paragraph><image>[<caption>xxx</caption>]</image>...
- writer.setSelection( writer.createRange(
- writer.createPositionAt( modelRoot.getChild( 1 ), 0 ),
- writer.createPositionAt( modelRoot.getChild( 1 ), 1 )
- ) );
- } );
- expect( getModelData( model ) ).to.equal(
- '<paragraph>foo</paragraph>' +
- '[<image>' +
- '<caption>xxx</caption>' +
- '</image>]' +
- '<paragraph>bar</paragraph>'
- );
- } );
- it( 'should not fix #1 (element selection of an object)', () => {
- model.change( writer => {
- // <paragraph>foo</paragraph>[<image><caption>xxx</caption></image>]...
- writer.setSelection( writer.createRange(
- writer.createPositionAt( modelRoot, 1 ),
- writer.createPositionAt( modelRoot, 2 )
- ) );
- } );
- expect( getModelData( model ) ).to.equal(
- '<paragraph>foo</paragraph>' +
- '[<image>' +
- '<caption>xxx</caption>' +
- '</image>]' +
- '<paragraph>bar</paragraph>'
- );
- } );
- it( 'should not fix #2 (inside a limit)', () => {
- model.change( writer => {
- const caption = modelRoot.getChild( 1 ).getChild( 0 );
- // <paragraph>foo</paragraph><image><caption>[xxx]</caption></image>...
- writer.setSelection( writer.createRange(
- writer.createPositionAt( caption, 0 ),
- writer.createPositionAt( caption, 3 )
- ) );
- } );
- expect( getModelData( model ) ).to.equal(
- '<paragraph>foo</paragraph>' +
- '<image>' +
- '<caption>[xxx]</caption>' +
- '</image>' +
- '<paragraph>bar</paragraph>'
- );
- } );
- it( 'should not fix #3 (inside a limit - partial text selection)', () => {
- model.change( writer => {
- const caption = modelRoot.getChild( 1 ).getChild( 0 );
- // <paragraph>foo</paragraph><image><caption>[xx]x</caption></image>...
- writer.setSelection( writer.createRange(
- writer.createPositionAt( caption, 0 ),
- writer.createPositionAt( caption, 2 )
- ) );
- } );
- expect( getModelData( model ) ).to.equal(
- '<paragraph>foo</paragraph>' +
- '<image>' +
- '<caption>[xx]x</caption>' +
- '</image>' +
- '<paragraph>bar</paragraph>'
- );
- } );
- it( 'should not fix #4 (inside a limit - partial text selection)', () => {
- model.change( writer => {
- const caption = modelRoot.getChild( 1 ).getChild( 0 );
- // <paragraph>foo</paragraph><image><caption>x[xx]</caption></image>...
- writer.setSelection( writer.createRange(
- writer.createPositionAt( caption, 1 ),
- writer.createPositionAt( caption, 3 )
- ) );
- } );
- expect( getModelData( model ) ).to.equal(
- '<paragraph>foo</paragraph>' +
- '<image>' +
- '<caption>x[xx]</caption>' +
- '</image>' +
- '<paragraph>bar</paragraph>'
- );
- } );
- it( 'should not fix #5 (selection in root on non limit element that doesn\'t allow text)', () => {
- setModelData( model,
- '[<figure></figure>]'
- );
- expect( getModelData( model ) ).to.equal(
- '[<figure></figure>]'
- );
- } );
- } );
- describe( 'non-collapsed selection - other scenarios', () => {
- it( 'should fix #1 (element selection of not an object)', () => {
- setModelData( model,
- '<paragraph>aaa</paragraph>' +
- '[<paragraph>bbb</paragraph>]' +
- '<paragraph>ccc</paragraph>'
- );
- expect( getModelData( model ) ).to.equal(
- '<paragraph>aaa</paragraph>' +
- '<paragraph>[bbb]</paragraph>' +
- '<paragraph>ccc</paragraph>'
- );
- } );
- it( 'should fix #2 (elements selection of not an object)', () => {
- setModelData( model,
- '<paragraph>aaa</paragraph>' +
- '[<paragraph>bbb</paragraph>' +
- '<paragraph>ccc</paragraph>]'
- );
- expect( getModelData( model ) ).to.equal(
- '<paragraph>aaa</paragraph>' +
- '<paragraph>[bbb</paragraph>' +
- '<paragraph>ccc]</paragraph>'
- );
- } );
- it( 'should fix #3 (partial selection of not an object)', () => {
- setModelData( model,
- '<paragraph>aaa</paragraph>' +
- '[<paragraph>bbb</paragraph>' +
- '<paragraph>ccc]</paragraph>'
- );
- expect( getModelData( model ) ).to.equal(
- '<paragraph>aaa</paragraph>' +
- '<paragraph>[bbb</paragraph>' +
- '<paragraph>ccc]</paragraph>'
- );
- } );
- it( 'should fix #4 (partial selection of not an object)', () => {
- setModelData( model,
- '<paragraph>aaa</paragraph>' +
- '<paragraph>b[bb</paragraph>]' +
- '<paragraph>ccc</paragraph>'
- );
- expect( getModelData( model ) ).to.equal(
- '<paragraph>aaa</paragraph>' +
- '<paragraph>b[bb]</paragraph>' +
- '<paragraph>ccc</paragraph>'
- );
- } );
- it( 'should fix #5 (partial selection of not an object)', () => {
- setModelData( model,
- '<paragraph>aaa</paragraph>' +
- '[<paragraph>bb]b</paragraph>' +
- '<paragraph>ccc</paragraph>'
- );
- expect( getModelData( model ) ).to.equal(
- '<paragraph>aaa</paragraph>' +
- '<paragraph>[bb]b</paragraph>' +
- '<paragraph>ccc</paragraph>'
- );
- } );
- it( 'should fix #6 (selection must not cross a limit element; starts in a root)', () => {
- model.schema.register( 'a', { isLimit: true, allowIn: '$root' } );
- model.schema.register( 'b', { isLimit: true, allowIn: 'a' } );
- model.schema.register( 'c', { allowIn: 'b' } );
- model.schema.extend( '$text', { allowIn: 'c' } );
- setModelData( model,
- '<a><b><c>[</c></b></a>]'
- );
- expect( getModelData( model ) ).to.equal( '[<a><b><c></c></b></a>]' );
- } );
- it( 'should fix #7 (selection must not cross a limit element; ends in a root)', () => {
- model.schema.register( 'a', { isLimit: true, allowIn: '$root' } );
- model.schema.register( 'b', { isLimit: true, allowIn: 'a' } );
- model.schema.register( 'c', { allowIn: 'b' } );
- model.schema.extend( '$text', { allowIn: 'c' } );
- setModelData( model,
- '[<a><b><c>]</c></b></a>'
- );
- expect( getModelData( model ) ).to.equal( '[<a><b><c></c></b></a>]' );
- } );
- it( 'should fix #8 (selection must not cross a limit element; starts in a non-limit)', () => {
- model.schema.register( 'div', { allowIn: '$root' } );
- model.schema.register( 'a', { isLimit: true, allowIn: 'div' } );
- model.schema.register( 'b', { isLimit: true, allowIn: 'a' } );
- model.schema.register( 'c', { allowIn: 'b' } );
- model.schema.extend( '$text', { allowIn: 'c' } );
- setModelData( model,
- '<div>[<a><b><c>]</c></b></a></div>'
- );
- expect( getModelData( model ) ).to.equal( '<div>[<a><b><c></c></b></a>]</div>' );
- } );
- it( 'should fix #9 (selection must not cross a limit element; ends in a non-limit)', () => {
- model.schema.register( 'div', { allowIn: '$root' } );
- model.schema.register( 'a', { isLimit: true, allowIn: 'div' } );
- model.schema.register( 'b', { isLimit: true, allowIn: 'a' } );
- model.schema.register( 'c', { allowIn: 'b' } );
- model.schema.extend( '$text', { allowIn: 'c' } );
- setModelData( model,
- '<div><a><b><c>[</c></b></a>]</div>'
- );
- expect( getModelData( model ) ).to.equal( '<div>[<a><b><c></c></b></a>]</div>' );
- } );
- it( 'should not fix #1 (selection on text node)', () => {
- setModelData( model, '<paragraph>foob[a]r</paragraph>', { lastRangeBackward: true } );
- expect( getModelData( model ) ).to.equal( '<paragraph>foob[a]r</paragraph>' );
- } );
- it( 'should not fix #2 (inline widget selected)', () => {
- setModelData( model,
- '<paragraph>[<inlineWidget></inlineWidget>]</paragraph>'
- );
- expect( getModelData( model ) ).to.equal(
- '<paragraph>[<inlineWidget></inlineWidget>]</paragraph>'
- );
- } );
- it( 'should not fix #3 (text around inline widget)', () => {
- setModelData( model,
- '<paragraph>fo[o<inlineWidget></inlineWidget>b]ar</paragraph>'
- );
- expect( getModelData( model ) ).to.equal(
- '<paragraph>fo[o<inlineWidget></inlineWidget>b]ar</paragraph>'
- );
- } );
- it( 'should not fix #4 (object in object)', () => {
- model.schema.register( 'div', {
- allowIn: [ '$root', 'div' ],
- isObject: true
- } );
- setModelData( model, '<div>[<div></div>]</div>' );
- model.change( writer => {
- const innerDiv = model.document.getRoot().getNodeByPath( [ 0, 0 ] );
- writer.setSelection( writer.createRangeOn( innerDiv ) );
- } );
- expect( getModelData( model ) ).to.equal( '<div>[<div></div>]</div>' );
- } );
- it( 'should not fix #5 (selection starts before a selectable, which is not an object)', () => {
- model.schema.register( 'div', { allowIn: '$root' } );
- model.schema.register( 'selectable', { isSelectable: true, allowIn: 'div' } );
- model.schema.extend( '$text', { allowIn: 'selectable' } );
- setModelData( model,
- '<div>[<selectable>foo]</selectable></div>'
- );
- expect( getModelData( model ) ).to.equal( '<div>[<selectable>foo]</selectable></div>' );
- } );
- it( 'should not fix #6 (selection ends after before a selectable, which is not an object)', () => {
- model.schema.register( 'div', { allowIn: '$root' } );
- model.schema.register( 'selectable', { isSelectable: true, allowIn: 'div' } );
- model.schema.extend( '$text', { allowIn: 'selectable' } );
- setModelData( model,
- '<div><selectable>[foo</selectable>]</div>'
- );
- expect( getModelData( model ) ).to.equal( '<div><selectable>[foo</selectable>]</div>' );
- } );
- } );
- describe( 'non-collapsed selection - inline widget scenarios', () => {
- beforeEach( () => {
- model.schema.register( 'placeholder', {
- allowWhere: '$text',
- isInline: true
- } );
- } );
- it( 'should fix selection that ends in inline element', () => {
- setModelData( model, '<paragraph>aaa[<placeholder>]</placeholder>bbb</paragraph>' );
- expect( getModelData( model ) ).to.equal( '<paragraph>aaa[]<placeholder></placeholder>bbb</paragraph>' );
- } );
- it( 'should fix selection that starts in inline element', () => {
- setModelData( model, '<paragraph>aaa<placeholder>[</placeholder>]bbb</paragraph>' );
- expect( getModelData( model ) ).to.equal( '<paragraph>aaa<placeholder></placeholder>[]bbb</paragraph>' );
- } );
- it( 'should fix selection that ends in inline element that is also an object', () => {
- model.schema.extend( 'placeholder', {
- isObject: true
- } );
- setModelData( model, '<paragraph>aaa[<placeholder>]</placeholder>bbb</paragraph>' );
- expect( getModelData( model ) ).to.equal( '<paragraph>aaa[<placeholder></placeholder>]bbb</paragraph>' );
- } );
- it( 'should fix selection that starts in inline element that is also an object', () => {
- model.schema.extend( 'placeholder', {
- isObject: true
- } );
- setModelData( model, '<paragraph>aaa<placeholder>[</placeholder>]bbb</paragraph>' );
- expect( getModelData( model ) ).to.equal( '<paragraph>aaa[<placeholder></placeholder>]bbb</paragraph>' );
- } );
- } );
- describe( 'collapsed selection', () => {
- beforeEach( () => {
- setModelData( model,
- '<paragraph>foo</paragraph>' +
- '<table>' +
- '<tableRow>' +
- '<tableCell><paragraph>aaa</paragraph></tableCell>' +
- '<tableCell><paragraph>bbb</paragraph></tableCell>' +
- '</tableRow>' +
- '</table>' +
- '<paragraph>bar</paragraph>'
- );
- } );
- it( 'should fix #1 (selection in limit element & before limit element)', () => {
- // <table>[]<tableRow>...
- model.change( writer => {
- writer.setSelection(
- writer.createRange( writer.createPositionAt( modelRoot.getChild( 1 ), 0 ) )
- );
- } );
- expect( getModelData( model ) ).to.equal(
- '<paragraph>foo</paragraph>' +
- '<table>' +
- '<tableRow>' +
- '<tableCell><paragraph>[]aaa</paragraph></tableCell>' +
- '<tableCell><paragraph>bbb</paragraph></tableCell>' +
- '</tableRow>' +
- '</table>' +
- '<paragraph>bar</paragraph>'
- );
- } );
- it( 'should fix #2 (selection in limit element & before limit+object element)', () => {
- // <table><tableRow>[]<tableCell>...
- model.change( writer => {
- const row = modelRoot.getChild( 1 ).getChild( 0 );
- writer.setSelection(
- writer.createRange( writer.createPositionAt( row, 0 ) )
- );
- } );
- expect( getModelData( model ) ).to.equal(
- '<paragraph>foo</paragraph>' +
- '<table>' +
- '<tableRow>' +
- '<tableCell><paragraph>[]aaa</paragraph></tableCell>' +
- '<tableCell><paragraph>bbb</paragraph></tableCell>' +
- '</tableRow>' +
- '</table>' +
- '<paragraph>bar</paragraph>'
- );
- } );
- it( 'should fix #3 (selection inside object element and before block element)', () => {
- setModelData( model,
- '<paragraph>foo</paragraph>' +
- '<table>' +
- '<tableRow>' +
- '<tableCell>[]<paragraph>aaa</paragraph></tableCell>' +
- '</tableRow>' +
- '</table>' +
- '<paragraph>bar</paragraph>'
- );
- assertEqualMarkup( getModelData( model ),
- '<paragraph>foo</paragraph>' +
- '<table>' +
- '<tableRow>' +
- '<tableCell><paragraph>[]aaa</paragraph></tableCell>' +
- '</tableRow>' +
- '</table>' +
- '<paragraph>bar</paragraph>'
- );
- } );
- it( 'should fix multiple ranges outside block element (but not merge them)', () => {
- setModelData( model,
- '[]<paragraph>foo</paragraph>[]' +
- '<table>' +
- '<tableRow>' +
- '<tableCell><paragraph>aaa</paragraph></tableCell>' +
- '</tableRow>' +
- '</table>' +
- '<paragraph>bar</paragraph>'
- );
- assertEqualMarkup( getModelData( model ),
- '<paragraph>[]foo[]</paragraph>' +
- '<table>' +
- '<tableRow>' +
- '<tableCell><paragraph>aaa</paragraph></tableCell>' +
- '</tableRow>' +
- '</table>' +
- '<paragraph>bar</paragraph>'
- );
- } );
- } );
- } );
- } );
|