mirror of
https://github.com/Azornes/Comfyui-LayerForge.git
synced 2026-03-25 06:22:14 -03:00
Refactor layer selection and movement logic
Centralizes layer movement logic in CanvasLayers with a new moveLayers function, supporting both up/down and drag-and-drop reordering. Updates selection logic in Canvas to only trigger updates when selection changes, and improves event handling in CanvasLayersPanel for more responsive selection and drag operations. Removes redundant moveLayersToPosition method in favor of the new unified approach.
This commit is contained in:
18
js/Canvas.js
18
js/Canvas.js
@@ -373,6 +373,7 @@ export class Canvas {
|
||||
*/
|
||||
updateSelectionLogic(layer, isCtrlPressed, isShiftPressed, index) {
|
||||
let newSelection = [...this.selectedLayers];
|
||||
let selectionChanged = false;
|
||||
|
||||
if (isShiftPressed && this.canvasLayersPanel.lastSelectedIndex !== -1) {
|
||||
const sortedLayers = [...this.layers].sort((a, b) => b.zIndex - a.zIndex);
|
||||
@@ -385,6 +386,7 @@ export class Canvas {
|
||||
newSelection.push(sortedLayers[i]);
|
||||
}
|
||||
}
|
||||
selectionChanged = true;
|
||||
} else if (isCtrlPressed) {
|
||||
const layerIndex = newSelection.indexOf(layer);
|
||||
if (layerIndex === -1) {
|
||||
@@ -392,12 +394,24 @@ export class Canvas {
|
||||
} else {
|
||||
newSelection.splice(layerIndex, 1);
|
||||
}
|
||||
this.canvasLayersPanel.lastSelectedIndex = index;
|
||||
selectionChanged = true;
|
||||
} else {
|
||||
newSelection = [layer];
|
||||
// Jeśli kliknięta warstwa nie jest częścią obecnego zaznaczenia,
|
||||
// wyczyść zaznaczenie i zaznacz tylko ją.
|
||||
if (!this.selectedLayers.includes(layer)) {
|
||||
newSelection = [layer];
|
||||
selectionChanged = true;
|
||||
}
|
||||
// Jeśli kliknięta warstwa JEST już zaznaczona (potencjalnie z innymi),
|
||||
// NIE rób nic, aby umożliwić przeciąganie całej grupy.
|
||||
this.canvasLayersPanel.lastSelectedIndex = index;
|
||||
}
|
||||
|
||||
this.updateSelection(newSelection);
|
||||
// Aktualizuj zaznaczenie tylko jeśli faktycznie się zmieniło
|
||||
if (selectionChanged) {
|
||||
this.updateSelection(newSelection);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user