Skip to content

Commit c72568f

Browse files
committed
Re-run on current array state after sort completion instead of reshuffling
1 parent 62cb0c4 commit c72568f

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

src/lib/components/SortPanel.svelte

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,18 @@
6767
export const resetPanel = () => {
6868
initialize();
6969
};
70+
71+
/**
72+
* Re-arm the generator on the CURRENT working array (no copy from baseArray).
73+
* Used when the user clicks Start after a previous run finished — they
74+
* expect the algorithm to run on whatever the array currently looks like
75+
* (typically sorted), not to silently reshuffle back to the starting state.
76+
*/
77+
export const restart = () => {
78+
instance = algorithm.function(workingArray);
79+
stats = emptyStats();
80+
isDone = false;
81+
};
7082
</script>
7183

7284
<div class="flex flex-1 min-w-0 min-h-0">

src/routes/+page.svelte

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,12 @@
6767
6868
const beginNewRunIfNeeded = () => {
6969
if (runCompleted) {
70-
panelA?.resetPanel();
71-
if (compareMode) panelB?.resetPanel();
70+
// restart() re-arms the generator on the CURRENT working array (already
71+
// sorted from the previous run) instead of copying baseArray back.
72+
// Otherwise a Start click after completion would silently re-shuffle and
73+
// re-sort instead of running on the visible state.
74+
panelA?.restart();
75+
if (compareMode) panelB?.restart();
7276
runCompleted = false;
7377
}
7478
};

0 commit comments

Comments
 (0)