@@ -80,6 +80,7 @@ export default class Preview extends PreviewCollection {
80
80
private resizeUtils : Resize ;
81
81
private gridSizeHistory : Map < number , number [ ] > = new Map ( ) ;
82
82
private interactionLevel : number = 0 ;
83
+ private startDragEvent : JQueryEventObject ;
83
84
84
85
/**
85
86
*
@@ -345,11 +346,12 @@ export default class Preview extends PreviewCollection {
345
346
} ) ;
346
347
return helper ;
347
348
} ,
348
- start : ( event : Event ) => {
349
+ start : ( event : JQueryEventObject ) => {
349
350
const columnInstance : ContentTypeCollectionInterface = ko . dataFor ( $ ( event . target ) [ 0 ] ) ;
350
351
// Use the global state as columns can be dragged between groups
351
352
setDragColumn ( ( columnInstance . parent as ContentTypeCollectionInterface < ColumnPreview > ) ) ;
352
353
this . dropPositions = calculateDropPositions ( this . parent ) ;
354
+ this . startDragEvent = event ;
353
355
354
356
events . trigger ( "column:dragStart" , {
355
357
column : columnInstance ,
@@ -372,6 +374,7 @@ export default class Preview extends PreviewCollection {
372
374
373
375
this . dropPlaceholder . removeClass ( "left right" ) ;
374
376
this . movePlaceholder . removeClass ( "active" ) ;
377
+ this . startDragEvent = null ;
375
378
376
379
events . trigger ( "column:dragStop" , {
377
380
column : draggedColumn ,
@@ -783,44 +786,30 @@ export default class Preview extends PreviewCollection {
783
786
const currentX = event . pageX - groupPosition . left ;
784
787
785
788
// Are we within the same column group or have we ended up over another?
786
- if ( columnInstance . parent === this . parent ) {
787
- const currentColumn = dragColumn . preview . element ;
788
- const currentColumnRight = currentColumn . position ( ) . left + currentColumn . width ( ) ;
789
- const lastColInGroup = ( this . parent . children ( ) [ this . parent . children ( ) . length - 1 ]
790
- . preview as ColumnPreview ) . element ;
791
- const insertLastPos = lastColInGroup . position ( ) . left + ( lastColInGroup . width ( ) / 2 ) ;
789
+ if ( columnInstance . parent === this . parent && this . startDragEvent ) {
790
+ const dragDirection = ( event . pageX <= this . startDragEvent . pageX ? "left" : "right" ) ;
791
+ const adjacentLeftColumn = getAdjacentColumn ( dragColumn , "-1" ) ;
792
792
793
+ // Determine the current move position based on the cursors position and direction of drag
793
794
this . movePosition = this . dropPositions . find ( ( position ) => {
794
- // Only ever look for the left placement, except the last item where we look on the right
795
- const placement = ( currentX >= insertLastPos ? "right" : "left" ) ;
796
- // There is 200px area over each column borders
797
- return comparator ( currentX , position [ placement ] , 100 ) &&
798
- ! comparator ( currentX , currentColumnRight , 100 ) &&
799
- position . affectedColumn !== columnInstance && // Check affected column isn't the current column
800
- position . placement === placement ; // Verify the position, we only check left on sorting
795
+ return currentX > position . left && currentX < position . right &&
796
+ position . placement === dragDirection && position . affectedColumn !== dragColumn ;
801
797
} ) ;
802
798
799
+ // Differences in the element & event positions cause a right movement to activate on the left column
800
+ if ( this . movePosition && dragDirection === "right" &&
801
+ this . movePosition . affectedColumn === adjacentLeftColumn
802
+ ) {
803
+ this . movePosition = null ;
804
+ }
805
+
803
806
if ( this . movePosition ) {
804
807
this . dropPlaceholder . removeClass ( "left right" ) ;
805
- const width = dragColumn . preview . element . outerWidth ( ) ;
806
- let left = ( this . movePosition . placement === "left" ? this . movePosition . left : null ) ;
807
- // The right position is only used when moving a column to the last position in the group
808
- const right = ( this . movePosition . placement === "right" ?
809
- groupPosition . outerWidth - this . movePosition . right : null
810
- ) ;
811
- /**
812
- * If we're dragging the column from the left to the right we need to show the placeholder on
813
- * the left hand side.
814
- */
815
- if ( left !== null && this . parent . children ( ) . indexOf ( dragColumn ) <
816
- this . parent . children ( ) . indexOf ( this . movePosition . affectedColumn )
817
- ) {
818
- left = left - width ;
819
- }
820
- this . movePlaceholder . css ( {
821
- width,
822
- left,
823
- right,
808
+ this . movePlaceholder . removeClass ( "left right" ) . css ( {
809
+ left : ( this . movePosition . placement === "left" ? this . movePosition . left : "" ) ,
810
+ right : ( this . movePosition . placement === "right"
811
+ ? groupPosition . width - this . movePosition . right : "" ) ,
812
+ width : dragColumn . preview . element . outerWidth ( ) + "px" ,
824
813
} ) . addClass ( "active" ) ;
825
814
} else {
826
815
this . movePlaceholder . removeClass ( "active" ) ;
0 commit comments