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