File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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" >
Original file line number Diff line number Diff line change 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 };
You can’t perform that action at this time.
0 commit comments