Skip to content

Commit

Permalink
Only dismiss the Table Mover if the end of the drag is not in the Tab…
Browse files Browse the repository at this point in the history
…le Mover div #2727
  • Loading branch information
BryanValverdeU committed Jun 25, 2024
1 parent 9dc5f50 commit bddd1d9
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,10 @@ export class TableEditor {
this.editor.takeSnapshot();
}

private onEndTableMove = () => {
this.disposeTableMover();
private onEndTableMove = (disposeHandler: boolean) => {
if (disposeHandler) {
this.disposeTableMover();
}
return this.onFinishEditing();
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export function createTableMover(
isRTL: boolean,
onFinishDragging: (table: HTMLTableElement) => void,
onStart: () => void,
onEnd: () => void,
onEnd: (disposeHandler: boolean) => void,
contentDiv?: EventTarget | null,
anchorContainer?: HTMLElement,
onTableEditorCreated?: OnTableEditorCreatedCallback,
Expand Down Expand Up @@ -118,7 +118,7 @@ export interface TableMoverContext {
div: HTMLElement;
onFinishDragging: (table: HTMLTableElement) => void;
onStart: () => void;
onEnd: () => void;
onEnd: (disposeHandler: boolean) => void;
disableMovement?: boolean;
}

Expand Down Expand Up @@ -298,9 +298,9 @@ export function onDragEnd(
setTableMoverCursor(editor, false);

if (element == context.div) {
// Table mover was only clicked, select whole table
// Table mover was only clicked, select whole table and do not dismiss the handler element.
selectWholeTable(table);
context.onEnd();
context.onEnd(false /* disposeHandler */);
return true;
} else {
// Check if table was dragged on itself, element is not in editor, or movement is disabled
Expand All @@ -310,7 +310,7 @@ export function onDragEnd(
disableMovement
) {
editor.setDOMSelection(initValue?.initialSelection ?? null);
context.onEnd();
context.onEnd(true /* disposeHandler */);
return false;
}

Expand Down Expand Up @@ -376,7 +376,7 @@ export function onDragEnd(
// No movement, restore initial selection
editor.setDOMSelection(initValue?.initialSelection ?? null);
}
context.onEnd();
context.onEnd(true /* disposeHandler */);
return insertionSuccess;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,70 @@ describe('Table Mover Tests', () => {
expect(parseFloat(divRect.style.left)).toBeGreaterThan(0);
});

it('Do not dismiss the TableMover if only clicking the handler element', () => {
//Act
const table = document.createElement('table');
const div = document.createElement('div');
const onFinishDragging = jasmine.createSpy('onFinishDragging');
const onStart = jasmine.createSpy('onStart');
const onEnd = jasmine.createSpy('onEnd');

const context: TableMoverContext = {
table,
zoomScale: 1,
rect: null,
isRTL: true,
editor,
div,
onFinishDragging,
onStart,
onEnd,
disableMovement: false,
};

onDragEnd(
context,
<any>{
target: div,
},
undefined
);

expect(onEnd).toHaveBeenCalledWith(false);
});

it('Dismiss the TableMover if drag end did not end in the handler element', () => {
//Act
const table = document.createElement('table');
const div = document.createElement('div');
const onFinishDragging = jasmine.createSpy('onFinishDragging');
const onStart = jasmine.createSpy('onStart');
const onEnd = jasmine.createSpy('onEnd');

const context: TableMoverContext = {
table,
zoomScale: 1,
rect: null,
isRTL: true,
editor,
div,
onFinishDragging,
onStart,
onEnd,
disableMovement: false,
};

onDragEnd(
context,
<any>{
target: table,
},
undefined
);

expect(onEnd).toHaveBeenCalledWith(true);
});

describe('Move - onDragEnd', () => {
let target: HTMLTableElement;
const nodeHeight = 300;
Expand Down

0 comments on commit bddd1d9

Please sign in to comment.