fix: remove extra snapshots when double clicking a card

ci-dev
LeRoyce Pearson 2024-04-21 11:40:13 -06:00
parent 35067f824e
commit 30eefb5279
1 changed files with 10 additions and 3 deletions

View File

@ -475,9 +475,13 @@ pub fn doSelectOrPlace(pressed: bool) !void {
}
}
if (cards_moved) {
try history.append(gpa, snapshot);
}
selected_deck = null;
} else {
var cards_moved = false;
const snapshot = try Snapshot.initFromCurrentGlobalState();
if (selected_deck) |selected| move_from_selected_to_hovered: {
const selected_substack = selected.items[selected_card..];
@ -492,7 +496,7 @@ pub fn doSelectOrPlace(pressed: bool) !void {
hovered.appendSliceAssumeCapacity(selected_substack);
selected.shrinkRetainingCapacity(selected.items.len - selected_substack.len);
hovered_card = indexOfTopOfStack(hovered_deck.?.items);
try history.append(gpa, snapshot);
cards_moved = true;
break :move_from_selected_to_hovered;
}
@ -513,7 +517,7 @@ pub fn doSelectOrPlace(pressed: bool) !void {
foundation.ensureUnusedCapacity(gpa, 1) catch continue;
foundation.appendAssumeCapacity(selected_deck.?.pop());
hovered_card = indexOfTopOfStack(hovered_deck.?.items);
try history.append(gpa, snapshot);
cards_moved = true;
break :move_from_selected_to_hovered;
}
}
@ -533,6 +537,9 @@ pub fn doSelectOrPlace(pressed: bool) !void {
hovered_card = indexOfTopOfStack(hovered_deck.?.items);
try history.append(gpa, snapshot);
}
if (cards_moved) {
try history.append(gpa, snapshot);
}
selected_deck = null;
}
}