mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-20 19:32:15 +00:00
feat(editor): Add undo/redo when moving nodes in new canvas (no-changelog) (#10137)
This commit is contained in:
@@ -49,7 +49,12 @@ import { useSettingsStore } from '@/stores/settings.store';
|
||||
import { useTagsStore } from '@/stores/tags.store';
|
||||
import { useUIStore } from '@/stores/ui.store';
|
||||
import { useWorkflowsStore } from '@/stores/workflows.store';
|
||||
import type { CanvasConnection, CanvasConnectionCreateData, CanvasNode } from '@/types';
|
||||
import type {
|
||||
CanvasConnection,
|
||||
CanvasConnectionCreateData,
|
||||
CanvasNode,
|
||||
CanvasNodeMoveEvent,
|
||||
} from '@/types';
|
||||
import { CanvasConnectionMode } from '@/types';
|
||||
import {
|
||||
createCanvasConnectionHandleString,
|
||||
@@ -138,20 +143,33 @@ export function useCanvasOperations({
|
||||
* Node operations
|
||||
*/
|
||||
|
||||
function updateNodesPosition(
|
||||
events: CanvasNodeMoveEvent[],
|
||||
{ trackHistory = false, trackBulk = true } = {},
|
||||
) {
|
||||
if (trackHistory && trackBulk) {
|
||||
historyStore.startRecordingUndo();
|
||||
}
|
||||
|
||||
events.forEach(({ id, position }) => {
|
||||
updateNodePosition(id, position, { trackHistory });
|
||||
});
|
||||
|
||||
if (trackBulk) {
|
||||
historyStore.stopRecordingUndo();
|
||||
}
|
||||
}
|
||||
|
||||
function updateNodePosition(
|
||||
id: string,
|
||||
position: CanvasNode['position'],
|
||||
{ trackHistory = false, trackBulk = true } = {},
|
||||
{ trackHistory = false } = {},
|
||||
) {
|
||||
const node = workflowsStore.getNodeById(id);
|
||||
if (!node) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (trackHistory && trackBulk) {
|
||||
historyStore.startRecordingUndo();
|
||||
}
|
||||
|
||||
const oldPosition: XYPosition = [...node.position];
|
||||
const newPosition: XYPosition = [position.x, position.y];
|
||||
|
||||
@@ -159,13 +177,18 @@ export function useCanvasOperations({
|
||||
|
||||
if (trackHistory) {
|
||||
historyStore.pushCommandToUndo(new MoveNodeCommand(node.name, oldPosition, newPosition));
|
||||
|
||||
if (trackBulk) {
|
||||
historyStore.stopRecordingUndo();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function revertUpdateNodePosition(nodeName: string, position: CanvasNode['position']) {
|
||||
const node = workflowsStore.getNodeByName(nodeName);
|
||||
if (!node) {
|
||||
return;
|
||||
}
|
||||
|
||||
updateNodePosition(node.id, position);
|
||||
}
|
||||
|
||||
async function renameNode(currentName: string, newName: string, { trackHistory = false } = {}) {
|
||||
if (currentName === newName) {
|
||||
return;
|
||||
@@ -1648,7 +1671,9 @@ export function useCanvasOperations({
|
||||
addNodes,
|
||||
addNode,
|
||||
revertAddNode,
|
||||
updateNodesPosition,
|
||||
updateNodePosition,
|
||||
revertUpdateNodePosition,
|
||||
setNodeActive,
|
||||
setNodeActiveByName,
|
||||
setNodeSelected,
|
||||
|
||||
Reference in New Issue
Block a user