From 13986824070f1e7fc849c4d611b1ad813c78d546 Mon Sep 17 00:00:00 2001 From: Leo dev Date: Sun, 8 Feb 2026 18:13:32 +0100 Subject: [PATCH] fixed issues --- src/app/runs/[runId]/components/Editor.tsx | 25 +++++++++------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/src/app/runs/[runId]/components/Editor.tsx b/src/app/runs/[runId]/components/Editor.tsx index f4114be..52035c4 100644 --- a/src/app/runs/[runId]/components/Editor.tsx +++ b/src/app/runs/[runId]/components/Editor.tsx @@ -48,28 +48,23 @@ export default function Editor({ run }: { run: LiveRun | null | undefined }) { [run], ); - const [lastMoveId, setLastMoveId] = useState(-1); + const [_, setLastMoveId] = useState(-1); const [moves, setMoves] = useState([]); useEffect(() => { - let moves = rawMoves?.filter((move) => move.moveId > lastMoveId) || []; + if (!rawMoves || rawMoves.length === 0) return; - if (moves.length === 0) return; + setLastMoveId((prevLastMoveId) => { + const newMoves = rawMoves.filter((move) => move.moveId > prevLastMoveId); - setMoves(moves); - setLastMoveId(lastMoveId + moves.length); + if (newMoves.length === 0) return prevLastMoveId; - if (rawMoves?.length || 0 > 0) { - console.log("raw", rawMoves); - } + setMoves(newMoves); + + return Math.max(...newMoves.map((m) => m.moveId)); + }); }, [rawMoves]); - useEffect(() => { - if (moves.length > 0) { - console.log("moves", moves); - } - }, [moves]); - useEffect(() => { if (!editorView || !moves) return; @@ -81,7 +76,7 @@ export default function Editor({ run }: { run: LiveRun | null | undefined }) { if (!editorView || cancelled) return resolve(); editorView.dispatch({ - // selection: { anchor: move.cursor }, + selection: { anchor: move.cursor }, scrollIntoView: true, changes: move.changes, });