Skip to content

fix: Use shallow copy before reversing#139

Open
BeiChenStanly wants to merge 1 commit intoManim-Notebook:mainfrom
BeiChenStanly:fix-manimClasses-reverse
Open

fix: Use shallow copy before reversing#139
BeiChenStanly wants to merge 1 commit intoManim-Notebook:mainfrom
BeiChenStanly:fix-manimClasses-reverse

Conversation

@BeiChenStanly
Copy link
Copy Markdown

@BeiChenStanly BeiChenStanly commented Mar 22, 2026

Fixes #140.

Problem
getManimClassAtCursor directly calls reverse() on the array returned from findAllIn, which modifies the cached array. This causes the array order to change after the first call, leading to incorrect results on subsequent calls.

Fix
Replace manimClasses.reverse().find(...) with manimClasses.slice().reverse().find(...).

  • slice() creates a shallow copy of the original array.
  • The reversal is applied to the copy, leaving the cached array unchanged.
  • The find operation works on the temporary copy, preserving the original order for future calls.

Copilot AI review requested due to automatic review settings March 22, 2026 07:16
@BeiChenStanly BeiChenStanly changed the title Use shallow copy before reversing in ·getManimClassAtCursor to avoid mutating cached array Use shallow copy before reversing in getManimClassAtCursor to avoid mutating cached array Mar 22, 2026

This comment was marked as off-topic.

@BeiChenStanly BeiChenStanly changed the title Use shallow copy before reversing in getManimClassAtCursor to avoid mutating cached array Fix: Use shallow copy before reversing in getManimClassAtCursor Mar 22, 2026
@Splines Splines changed the title Fix: Use shallow copy before reversing in getManimClassAtCursor fix: Use shallow copy before reversing Mar 24, 2026
@Splines Splines added the bug Something isn't working label Mar 24, 2026
@Splines
Copy link
Copy Markdown
Member

Splines commented Mar 24, 2026

Nice, thanks for the fix! I will have to fix the GitHub Actions pipeline first, currently it fails with this error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

getManimClassAtCursor returns inconsistent results due to in-place array reversal

3 participants