Skip to content

Commit

Permalink
Fixed #5783 - Weird drag behaviour to empty survey in Safari - stop u…
Browse files Browse the repository at this point in the history
…ndo/redo transaction on banned drop (#5880)

* Fixed #5783 - Weird drag behaviour to empty survey in Safari - stop undo/redo transaction on banned drop

* Update .eslintrc.json

---------

Co-authored-by: tsv2013 <[email protected]>
  • Loading branch information
tsv2013 and tsv2013 authored Sep 12, 2024
1 parent 7c80b6b commit efaf958
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
5 changes: 3 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@
"linebreak-style": [
"off",
"windows"
]
],
"react/no-is-mounted": "off"
}
}
}
3 changes: 3 additions & 0 deletions packages/survey-creator-core/src/creator-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1925,6 +1925,9 @@ export class SurveyCreatorModel extends Base
this.setModified({ type: "ADDED_FROM_TOOLBOX", question: options.draggedElement });
}
});
this.dragDropSurveyElements.onDragClear.add((sender, options) => {
this.stopUndoRedoTransaction();
});
}
private initDragDropChoices() {
this.dragDropChoices = new DragDropChoices(null, this);
Expand Down
44 changes: 44 additions & 0 deletions packages/survey-creator-core/tests/creator-undo-redo.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,50 @@ test("undo/redo DnD ", (): any => {
expect(creator.survey.pages[0].elements.map(e => e.name)).toEqual(["question1", "question2"]);
expect(creator.survey.pages[0].rows.length).toEqual(1);
});
test("undo/redo DnD stops transaction onDragClear", (): any => {
const creator = new CreatorTester();
creator.JSON = {
"logoPosition": "right",
"pages": [
{
"name": "page1",
"elements": [
{
"type": "radiogroup",
"name": "question1",
"choices": [
"item1",
"item2",
"item3"
]
},
{
"type": "radiogroup",
"name": "question2",
"startWithNewLine": false,
"choices": [
"item1",
"item2",
"item3"
]
}
]
}
]
};

const q1 = creator.survey.pages[0].elements[0];
const q2 = creator.survey.pages[0].elements[1];
creator.dragDropSurveyElements.onDragStart.fire({ dropTarget: q2, draggedElement: q1 }, {});

expect(creator.undoRedoManager["transactionCounter"]).toEqual(1);
expect(creator.undoRedoManager["_preparingTransaction"]).toBeDefined();

creator.dragDropSurveyElements.onDragClear.fire({ dropTarget: q2, draggedElement: q1 }, {});

expect(creator.undoRedoManager["transactionCounter"]).toEqual(0);
expect(creator.undoRedoManager["_preparingTransaction"]).toBe(null);
});
test("Undo restore deleted page and question", (): any => {
const creator = new CreatorTester();
creator.JSON = {
Expand Down

0 comments on commit efaf958

Please sign in to comment.