Browse Source

Renamed VirtualSelection to Highlight.

Szymon Kupś 8 years ago
parent
commit
b35422a880

+ 22 - 22
packages/ckeditor5-widget/src/virtualselectionstack.js

@@ -4,7 +4,7 @@
  */
 
 /**
- * @module widget/virtualselectionstack
+ * @module widget/highlightstack
  */
 
 import EmitterMixin from '@ckeditor/ckeditor5-utils/src/emittermixin';
@@ -12,14 +12,14 @@ import mix from '@ckeditor/ckeditor5-utils/src/mix';
 
 /**
  * Class used to handle correct order of
- * {@link module:engine/conversion/buildmodelconverter~ModelConverterBuilder#toVirtualSelection virtual selections} on
- * elements. When different virtual selections are applied to same element correct order should be preserved:
- * * virtual selection with highest priority should be applied,
- * * if two virtual selections have same priority - sort by CSS class provided in
- * {@link module:engine/conversion/buildmodelconverter~VirtualSelectionDescriptor}.
- * This way, virtual selection will be applied with the same rules it is applied on texts.
+ * {@link module:engine/conversion/buildmodelconverter~ModelConverterBuilder#toHighlight highlights} on
+ * elements. When different highlights are applied to same element correct order should be preserved:
+ * * highlight with highest priority should be applied,
+ * * if two highlights have same priority - sort by CSS class provided in
+ * {@link module:engine/conversion/buildmodelconverter~HighlightDescriptor}.
+ * This way, highlight will be applied with the same rules it is applied on texts.
  */
-export default class VirtualSelectionStack {
+export default class HighlightStack {
 	/**
 	 * Creates class instance.
 	 */
@@ -28,10 +28,10 @@ export default class VirtualSelectionStack {
 	}
 
 	/**
-	 * Adds virtual selection descriptor to the stack.
+	 * Adds highlight descriptor to the stack.
 	 *
 	 * @fires change:top
-	 * @param {module:engine/conversion/buildmodelconverter~VirtualSelectionDescriptor} descriptor
+	 * @param {module:engine/conversion/buildmodelconverter~HighlightDescriptor} descriptor
 	 */
 	add( descriptor ) {
 		const stack = this._stack;
@@ -67,10 +67,10 @@ export default class VirtualSelectionStack {
 	}
 
 	/**
-	 * Removes virtual selection descriptor from the stack.
+	 * Removes highlight descriptor from the stack.
 	 *
 	 * @fires change:top
-	 * @param {module:engine/conversion/buildmodelconverter~VirtualSelectionDescriptor} descriptor
+	 * @param {module:engine/conversion/buildmodelconverter~HighlightDescriptor} descriptor
 	 */
 	remove( descriptor ) {
 		const stack = this._stack;
@@ -94,7 +94,7 @@ export default class VirtualSelectionStack {
 		stack.splice( i, 1 );
 
 		// Element from stack top was removed - fire `change:top` event with new first element. It might be `undefined`
-		// which informs that no selection is currently at the top.
+		// which informs that no descriptor is currently at the top.
 		if ( i === 0 ) {
 			const data = {
 				oldDescriptor: descriptor
@@ -116,13 +116,13 @@ export default class VirtualSelectionStack {
 	}
 }
 
-mix( VirtualSelectionStack, EmitterMixin );
+mix( HighlightStack, EmitterMixin );
 
-// Compares two virtual selection descriptors by priority and CSS class names. Returns `true` when both descriptors are
+// Compares two highlight descriptors by priority and CSS class names. Returns `true` when both descriptors are
 // considered equal.
 //
-// @param {module:engine/conversion/buildmodelconverter~VirtualSelectionDescriptor} descriptorA
-// @param {module:engine/conversion/buildmodelconverter~VirtualSelectionDescriptor} descriptorB
+// @param {module:engine/conversion/buildmodelconverter~HighlightDescriptor} descriptorA
+// @param {module:engine/conversion/buildmodelconverter~HighlightDescriptor} descriptorB
 // @returns {Boolean}
 function compareDescriptors( descriptorA, descriptorB ) {
 	return descriptorA.priority == descriptorB.priority && descriptorA.class == descriptorB.class;
@@ -130,8 +130,8 @@ function compareDescriptors( descriptorA, descriptorB ) {
 
 // Checks whenever first descriptor should be placed in the stack before second one.
 //
-// @param {module:engine/conversion/buildmodelconverter~VirtualSelectionDescriptor} a
-// @param {module:engine/conversion/buildmodelconverter~VirtualSelectionDescriptor} b
+// @param {module:engine/conversion/buildmodelconverter~HighlightDescriptor} a
+// @param {module:engine/conversion/buildmodelconverter~HighlightDescriptor} b
 // @returns {Boolean}
 function shouldABeBeforeB( a, b ) {
 	if ( a.priority > b.priority ) {
@@ -145,12 +145,12 @@ function shouldABeBeforeB( a, b ) {
 }
 
 /**
- * Fired when top element on {@link module:widget/virtualselectionstack~VirtualSelectionStack} has been changed
+ * Fired when top element on {@link module:widget/highlightstack~HighlightStack} has been changed
  *
  * @event change:top
  * @param {Object} data Additional information about the change.
- * @param {module:engine/conversion/buildmodelconverter~VirtualSelectionDescriptor} [data.newDescriptor] New virtual selection
+ * @param {module:engine/conversion/buildmodelconverter~HighlightDescriptor} [data.newDescriptor] New highlight
  * descriptor. It will be `undefined` when last descriptor is removed from the stack.
- * @param {module:engine/conversion/buildmodelconverter~VirtualSelectionDescriptor} [data.oldDescriptor] Old virtual selection
+ * @param {module:engine/conversion/buildmodelconverter~HighlightDescriptor} [data.oldDescriptor] Old highlight
  * descriptor. It will be `undefined` when first descriptor is added to the stack.
  */

+ 9 - 10
packages/ckeditor5-widget/src/utils.js

@@ -7,7 +7,7 @@
  * @module widget/utils
  */
 
-import VirtualSelectionStack from './virtualselectionstack';
+import HighlightStack from './highlightstack';
 
 const widgetSymbol = Symbol( 'isWidget' );
 const labelSymbol = Symbol( 'label' );
@@ -42,8 +42,7 @@ export function isWidget( element ) {
  * * adds custom `getFillerOffset` method returning `null`,
  * * adds `ck-widget` CSS class,
  * * adds custom property allowing to recognize widget elements by using {@link ~isWidget},
- * * implements `setVirtualSelection` and `removeVirtualSelection` custom properties to handle virtual selection
- * on widgets.
+ * * implements `setHighlight` and `removeHighlight` custom properties to handle view highlight on widgets.
  *
  * @param {module:engine/view/element~Element} element
  * @param {Object} [options={}]
@@ -61,7 +60,7 @@ export function toWidget( element, options = {} ) {
 		setLabel( element, options.label );
 	}
 
-	setVirtualSelectionHandling(
+	setHighlightHandling(
 		element,
 		( element, descriptor ) => element.addClass( descriptor.class ),
 		( element, descriptor ) => element.removeClass( descriptor.class )
@@ -71,15 +70,15 @@ export function toWidget( element, options = {} ) {
 }
 
 /**
- * Sets virtual selection handling methods. Uses {@link module:widget/virtualselectionstack~VirtualSelectionStack} to
- * properly determine which virtual selection should be used at given time.
+ * Sets highlight handling methods. Uses {@link module:widget/highlightstack~HighlightStack} to
+ * properly determine which highlight descriptor should be used at given time.
  *
  * @param {module:engine/view/element~Element} element
  * @param {Function} add
  * @param {Function} remove
  */
-export function setVirtualSelectionHandling( element, add, remove ) {
-	const stack = new VirtualSelectionStack();
+export function setHighlightHandling( element, add, remove ) {
+	const stack = new HighlightStack();
 
 	stack.on( 'change:top', ( evt, data ) => {
 		if ( data.oldDescriptor ) {
@@ -91,8 +90,8 @@ export function setVirtualSelectionHandling( element, add, remove ) {
 		}
 	} );
 
-	element.setCustomProperty( 'setVirtualSelection', ( element, descriptor ) => stack.add( descriptor ) );
-	element.setCustomProperty( 'removeVirtualSelection', ( element, descriptor ) => stack.remove( descriptor ) );
+	element.setCustomProperty( 'setHighlight', ( element, descriptor ) => stack.add( descriptor ) );
+	element.setCustomProperty( 'removeHighlight', ( element, descriptor ) => stack.remove( descriptor ) );
 }
 
 /**

+ 3 - 3
packages/ckeditor5-widget/tests/virtualselectionstack.js

@@ -3,13 +3,13 @@
  * For licensing, see LICENSE.md.
  */
 
-import VirtualSelectionStack from '../src/virtualselectionstack';
+import HighlightStack from '../src/highlightstack';
 
-describe( 'VirtualSelectionStack', () => {
+describe( 'HighlightStack', () => {
 	let stack;
 
 	beforeEach( () => {
-		stack = new VirtualSelectionStack();
+		stack = new HighlightStack();
 	} );
 
 	it( 'should fire event when new descriptor is provided to an empty stack', () => {

+ 27 - 27
packages/ckeditor5-widget/tests/utils.js

@@ -12,7 +12,7 @@ import {
 	setLabel,
 	getLabel,
 	toWidgetEditable,
-	setVirtualSelectionHandling,
+	setHighlightHandling,
 	WIDGET_CLASS_NAME
 } from '../src/utils';
 
@@ -50,20 +50,20 @@ describe( 'widget utils', () => {
 			expect( getLabel( element ) ).to.equal( 'foo bar baz label' );
 		} );
 
-		it( 'should set default virtual selection methods', () => {
+		it( 'should set default highlight handling methods', () => {
 			toWidget( element );
 
-			const set = element.getCustomProperty( 'setVirtualSelection' );
-			const remove = element.getCustomProperty( 'removeVirtualSelection' );
+			const set = element.getCustomProperty( 'setHighlight' );
+			const remove = element.getCustomProperty( 'removeHighlight' );
 
 			expect( typeof set ).to.equal( 'function' );
 			expect( typeof remove ).to.equal( 'function' );
 
-			set( element, { priority: 1, class: 'virtual-selection' } );
-			expect( element.hasClass( 'virtual-selection' ) ).to.be.true;
+			set( element, { priority: 1, class: 'highlight' } );
+			expect( element.hasClass( 'highlight' ) ).to.be.true;
 
-			remove( element, { priority: 1, class: 'virtual-selection' } );
-			expect( element.hasClass( 'virtual-selection' ) ).to.be.false;
+			remove( element, { priority: 1, class: 'highlight' } );
+			expect( element.hasClass( 'highlight' ) ).to.be.false;
 		} );
 	} );
 
@@ -137,7 +137,7 @@ describe( 'widget utils', () => {
 		} );
 	} );
 
-	describe( 'setVirtualSelectionHandling()', () => {
+	describe( 'setHighlightHandling()', () => {
 		let element, addSpy, removeSpy, set, remove;
 
 		beforeEach( () => {
@@ -145,18 +145,18 @@ describe( 'widget utils', () => {
 			addSpy = sinon.spy();
 			removeSpy = sinon.spy();
 
-			setVirtualSelectionHandling( element, addSpy, removeSpy );
-			set = element.getCustomProperty( 'setVirtualSelection' );
-			remove = element.getCustomProperty( 'removeVirtualSelection' );
+			setHighlightHandling( element, addSpy, removeSpy );
+			set = element.getCustomProperty( 'setHighlight' );
+			remove = element.getCustomProperty( 'removeHighlight' );
 		} );
 
-		it( 'should set virtual selection methods', () => {
+		it( 'should set highlight handling methods', () => {
 			expect( typeof set ).to.equal( 'function' );
 			expect( typeof remove ).to.equal( 'function' );
 		} );
 
-		it( 'should call virtual selection methods when descriptor is added and removed', () => {
-			const descriptor = { priority: 10, class: 'virtual-selection' };
+		it( 'should call highlight methods when descriptor is added and removed', () => {
+			const descriptor = { priority: 10, class: 'highlight' };
 
 			set( element, descriptor );
 			remove( element, descriptor );
@@ -168,9 +168,9 @@ describe( 'widget utils', () => {
 			sinon.assert.calledWithExactly( removeSpy, element, descriptor );
 		} );
 
-		it( 'should call virtual selection methods when next descriptor is added', () => {
-			const descriptor = { priority: 10, class: 'virtual-selection' };
-			const secondDescriptor = { priority: 11, class: 'virtual-selection' };
+		it( 'should call highlight methods when next descriptor is added', () => {
+			const descriptor = { priority: 10, class: 'highlight' };
+			const secondDescriptor = { priority: 11, class: 'highlight' };
 
 			set( element, descriptor );
 			set( element, secondDescriptor );
@@ -180,9 +180,9 @@ describe( 'widget utils', () => {
 			expect( addSpy.secondCall.args[ 1 ] ).to.equal( secondDescriptor );
 		} );
 
-		it( 'should not call virtual selection methods when descriptor with lower priority is added', () => {
-			const descriptor = { priority: 10, class: 'virtual-selection' };
-			const secondDescriptor = { priority: 9, class: 'virtual-selection' };
+		it( 'should not call highlight methods when descriptor with lower priority is added', () => {
+			const descriptor = { priority: 10, class: 'highlight' };
+			const secondDescriptor = { priority: 9, class: 'highlight' };
 
 			set( element, descriptor );
 			set( element, secondDescriptor );
@@ -191,9 +191,9 @@ describe( 'widget utils', () => {
 			expect( addSpy.firstCall.args[ 1 ] ).to.equal( descriptor );
 		} );
 
-		it( 'should call virtual selection methods when descriptor is removed changing active descriptor', () => {
-			const descriptor = { priority: 10, class: 'virtual-selection' };
-			const secondDescriptor = { priority: 11, class: 'virtual-selection' };
+		it( 'should call highlight methods when descriptor is removed changing active descriptor', () => {
+			const descriptor = { priority: 10, class: 'highlight' };
+			const secondDescriptor = { priority: 11, class: 'highlight' };
 
 			set( element, descriptor );
 			set( element, secondDescriptor );
@@ -209,9 +209,9 @@ describe( 'widget utils', () => {
 			expect( removeSpy.secondCall.args[ 1 ] ).to.equal( secondDescriptor );
 		} );
 
-		it( 'should call virtual selection methods when descriptor is removed not changing active descriptor', () => {
-			const descriptor = { priority: 10, class: 'virtual-selection' };
-			const secondDescriptor = { priority: 9, class: 'virtual-selection' };
+		it( 'should call highlight methods when descriptor is removed not changing active descriptor', () => {
+			const descriptor = { priority: 10, class: 'highlight' };
+			const secondDescriptor = { priority: 9, class: 'highlight' };
 
 			set( element, descriptor );
 			set( element, secondDescriptor );