Skip to content

Commit

Permalink
Merge branch 'main' of github.com:benson1029/go-slang into main
Browse files Browse the repository at this point in the history
  • Loading branch information
rama-pang committed Apr 12, 2024
2 parents d842a33 + d390154 commit cbd4866
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/CodeEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ function CodeEditor() {
const [autoPlay, setAutoPlay] = useState(false);
const [tabIndex, setTabIndex] = useState(0);
const [speed, setSpeed] = useState(5);
const [switchThread, setSwitchThread] = useState(true);

const [searchParams, setSearchParams] = useSearchParams();
const codeParam = searchParams.get("code");
Expand Down Expand Up @@ -84,7 +85,7 @@ function CodeEditor() {
const newTabIndex = snapshots[snapshotStep + 1].findIndex(thread => thread.current);
if (currentThreadIndex == null || currentThreadIndex === -1) {
setTabIndex(newTabIndex);
} else {
} else if (switchThread) {
setTabIndex(currentThreadIndex);
setTimeout(() => setTabIndex(newTabIndex), 5000/speed);
}
Expand All @@ -96,7 +97,7 @@ function CodeEditor() {
return () => {
clearInterval(autoPlayTask);
}
}, [autoPlay, snapshotStep, snapshots, tabIndex, speed]);
}, [autoPlay, snapshotStep, snapshots, tabIndex, speed, switchThread]);

return (
<>
Expand Down Expand Up @@ -296,6 +297,13 @@ function CodeEditor() {
value={speed}
onChange={(e) => setSpeed(e.target.value)}
/>
<input
type="checkbox"
style={{ marginLeft: '10px' }}
checked={switchThread}
onChange={(e) => setSwitchThread(e.target.checked)}
/>
Switch Thread
<Tabs selectedIndex={tabIndex} onSelect={(index) => setTabIndex(index)}>
<TabList>
{
Expand Down

0 comments on commit cbd4866

Please sign in to comment.