Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only dismiss the Table Mover if the end of the drag is not in the Table Mover div #2727

Merged
merged 1 commit into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading