How to use the @ckeditor/ckeditor5-utils/src/count function in @ckeditor/ckeditor5-utils

To help you get started, we’ve selected a few @ckeditor/ckeditor5-utils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ckeditor / ckeditor5-engine / src / view / selection.js View on Github external
isSimilar( otherSelection ) {
		if ( this.isBackward != otherSelection.isBackward ) {
			return false;
		}

		const numOfRangesA = count( this.getRanges() );
		const numOfRangesB = count( otherSelection.getRanges() );

		// If selections have different number of ranges, they cannot be similar.
		if ( numOfRangesA != numOfRangesB ) {
			return false;
		}

		// If both selections have no ranges, they are similar.
		if ( numOfRangesA == 0 ) {
			return true;
		}

		// Check if each range in one selection has a similar range in other selection.
		for ( let rangeA of this.getRanges() ) {
			rangeA = rangeA.getTrimmed();
github ckeditor / ckeditor5-engine / src / view / selection.js View on Github external
isSimilar( otherSelection ) {
		if ( this.isBackward != otherSelection.isBackward ) {
			return false;
		}

		const numOfRangesA = count( this.getRanges() );
		const numOfRangesB = count( otherSelection.getRanges() );

		// If selections have different number of ranges, they cannot be similar.
		if ( numOfRangesA != numOfRangesB ) {
			return false;
		}

		// If both selections have no ranges, they are similar.
		if ( numOfRangesA == 0 ) {
			return true;
		}

		// Check if each range in one selection has a similar range in other selection.
		for ( let rangeA of this.getRanges() ) {
			rangeA = rangeA.getTrimmed();

			let found = false;
github ckeditor / ckeditor5-engine / tests / model / delta / delta.js View on Github external
it( 'should iterate over delta operations', () => {
			const delta = new Delta();

			delta.addOperation( {} );
			delta.addOperation( {} );
			delta.addOperation( {} );

			const totalNumber = count( delta.operations );

			expect( totalNumber ).to.equal( 3 );
		} );
	} );
github ckeditor / ckeditor5-engine / tests / model / selection.js View on Github external
it( 'keeps all existing ranges and fires no change:range when no modifications needed', () => {
			selection.setTo( [ range, liveRange ] );

			const spy = sinon.spy();
			selection.on( 'change:range', spy );

			selection.setFocus( selection.focus );

			expect( count( selection.getRanges() ) ).to.equal( 2 );
			expect( spy.callCount ).to.equal( 0 );
		} );
github ckeditor / ckeditor5-engine / tests / view / domconverter / dom-to-view.js View on Github external
it( 'should create tree of view elements from DOM element without children', () => {
			const domImg = createElement( document, 'img' );
			const domText = document.createTextNode( 'foo' );
			const domP = createElement( document, 'p', { 'class': 'foo' }, [ domImg, domText ] );

			const viewImg = new ViewElement( 'img' );

			converter.bindElements( domImg, viewImg );

			const viewP = converter.domToView( domP, { withChildren: false } );

			expect( viewP ).to.be.an.instanceof( ViewElement );
			expect( viewP.name ).to.equal( 'p' );

			expect( viewP.getAttribute( 'class' ) ).to.equal( 'foo' );
			expect( count( viewP.getAttributeKeys() ) ).to.equal( 1 );

			expect( viewP.childCount ).to.equal( 0 );
			expect( converter.mapViewToDom( viewP ) ).to.not.equal( domP );
		} );
github ckeditor / ckeditor5-engine / tests / model / element.js View on Github external
it( 'should create element with attributes', () => {
			const element = new Element( 'elem', { foo: 'bar' } );

			expect( count( element.getAttributes() ) ).to.equal( 1 );
			expect( element.getAttribute( 'foo' ) ).to.equal( 'bar' );
		} );
github ckeditor / ckeditor5-engine / tests / view / element.js View on Github external
it( 'should create element with attributes as map', () => {
			const attrs = new Map();
			attrs.set( 'foo', 'bar' );

			const el = new Element( 'p', attrs );

			expect( el ).to.have.property( 'name' ).that.equals( 'p' );
			expect( count( el.getAttributeKeys() ) ).to.equal( 1 );
			expect( el.getAttribute( 'foo' ) ).to.equal( 'bar' );
		} );
github ckeditor / ckeditor5-engine / tests / model / node.js View on Github external
it( 'should initialize attribute list with passed attributes', () => {
			const foo = new Node( { foo: true, bar: false } );

			expect( count( foo.getAttributes() ) ).to.equal( 2 );
			expect( foo.getAttribute( 'foo' ) ).to.equal( true );
			expect( foo.getAttribute( 'bar' ) ).to.equal( false );
		} );
	} );
github ckeditor / ckeditor5-engine / tests / model / element.js View on Github external
it( 'should create empty element', () => {
			const element = new Element( 'elem' );

			expect( element ).to.be.an.instanceof( Node );
			expect( element ).to.have.property( 'name' ).that.equals( 'elem' );

			expect( count( element.getAttributes() ) ).to.equal( 0 );
			expect( count( element.getChildren() ) ).to.equal( 0 );
		} );
github ckeditor / ckeditor5-engine / tests / model / liveselection.js View on Github external
root = doc.createRoot();
			root.insertChildren( 0, [
				new Element( 'img' ),
				new Element( 'p', [], new Text( 'foobar' ) )
			] );
			doc.schema.registerItem( 'img' );
			doc.schema.registerItem( 'p', '$block' );
			selection = doc.selection;

			const ranges = Array.from( selection.getRanges() );

			expect( ranges.length ).to.equal( 1 );
			expect( selection.anchor.isEqual( new Position( root, [ 1, 0 ] ) ) ).to.be.true;
			expect( selection.focus.isEqual( new Position( root, [ 1, 0 ] ) ) ).to.be.true;
			expect( selection ).to.have.property( 'isBackward', false );
			expect( count( selection.getAttributes() ) ).to.equal( 0 );
		} );
	} );