8
0
Просмотр исходного кода

Internal: Fixed center resizing compensation. Also added some missing docs.

Marek Lewandowski 6 лет назад
Родитель
Сommit
dd433141ca

+ 9 - 5
packages/ckeditor5-widget/src/resizecontext.js

@@ -62,16 +62,20 @@ export default class ResizeContext {
 			y: 0
 		};
 
-		// @todo: ---- options below seems like a little outside of a scope of a single context ----
-
-		// Reference point of resizer where the dragging started. It is used to measure the distance to user cursor
-		// traveled, thus how much the image should be enlarged.
-		// This information is only known after DOM was rendered, so it will be updated later.
+		/**
+		 * Reference point of resizer where the dragging started. It is used to measure the distance to user cursor
+		 * traveled, thus how much the image should be enlarged.
+		 * This information is only known after DOM was rendered, so it will be updated later.
+		 *
+		 * @protected
+		 */
 		this.referenceCoordinates = {
 			y: 0,
 			x: 0
 		};
 
+		// @todo: ---- options below seems like a little outside of a scope of a single context ----
+
 		this._cleanupContext();
 
 		/**

+ 15 - 4
packages/ckeditor5-widget/src/resizertopbound.js

@@ -64,19 +64,30 @@ export default class ResizerTopBound {
 		const isCentered = this.options.isCentered ? this.options.isCentered( this.context ) : true;
 		const initialSize = this.context.originalSize;
 
+		// Enlargement defines how much the resize host has changed in a given axis. Naturally it could be a negative number
+		// meaning that it has been shrunk.
+		//
+		// +----------------+--+
+		// |                |  |
+		// |       img      |  |
+		// |                |  |
+		// +----------------+  | ^
+		// |                   | | - enlarge y
+		// +-------------------+ v
+		// 					<-->
+		// 					 enlarge x
 		const enlargement = {
-			// @todo it could be simplified if context.referenceCoordinates was an inverted corner (at least for bottom-left).
 			x: this.context.referenceCoordinates.x - ( currentCoordinates.x + initialSize.width ),
 			y: ( currentCoordinates.y - initialSize.height ) - this.context.referenceCoordinates.y
 		};
 
-		// temp workaround
 		if ( isCentered && this.context.referenceHandlerPosition.endsWith( '-right' ) ) {
 			enlargement.x = currentCoordinates.x - ( this.context.referenceCoordinates.x + initialSize.width );
 		}
 
-		// @todo: oddly enough, this condition **check** is not needed for tables.
-		if ( isCentered && enlargement.x < 0 ) {
+		// Objects needs to be resized twice as much in horizontal axis if centered, since enlargement is counted from one resized
+		// corner to your cursor. It needs to be duplicated to compensate for the other side too.
+		if ( isCentered ) {
 			enlargement.x *= 2;
 		}