-
-
Notifications
You must be signed in to change notification settings - Fork 34.2k
gh-91167: Fix cloned turtle pen not clearing completely #145406
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2879,6 +2879,8 @@ def clone(self): | |||||||||||||||||||||||||||||||||||||||||||||||
| q.turtle._item = [screen._createpoly() for item in | ||||||||||||||||||||||||||||||||||||||||||||||||
| screen._shapes[self.turtle.shapeIndex]._data] | ||||||||||||||||||||||||||||||||||||||||||||||||
| q.currentLineItem = screen._createline() | ||||||||||||||||||||||||||||||||||||||||||||||||
| q.currentLine = [q._position] if q._drawing else [] | ||||||||||||||||||||||||||||||||||||||||||||||||
| q.items = [q.currentLineItem] | ||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||
| q.items = [q.currentLineItem] | |
| q.items = [q.currentLineItem] | |
| # Reset ownership/undo state so the clone cannot affect the source | |
| # turtle's existing canvas items via non-clear operations. | |
| # The transient animation line item will be recreated on demand. | |
| if hasattr(q, "drawingLineItem"): | |
| q.drawingLineItem = None | |
| # The clone should start with no stamps of its own. | |
| if hasattr(q, "stampItems"): | |
| q.stampItems = [] | |
| # Clear the clone's undo history so q.undo() cannot replay or | |
| # delete items created before cloning. | |
| if hasattr(q, "undobuffer"): | |
| reset = getattr(q.undobuffer, "reset", None) | |
| if callable(reset): | |
| reset() | |
| # If a fill operation is active on the source, avoid sharing the | |
| # same fill item/path ids with the clone. | |
| if hasattr(q, "_fillitem") and getattr(self, "_fillitem", None) is not None: | |
| q._fillitem = None | |
| if hasattr(q, "_fillpath") and getattr(self, "_fillitem", None) is not None: | |
| q._fillpath = [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test only asserts that
clone.clear()doesn’t delete items fromself.turtle.items, but the bug class here also involves other clone-owned collections (notablystampItemsandundobuffer) that can still contain source-owned canvas ids afterdeepcopy(). Extending the test to cover stamps (e.g., sourcestamp()thenclone.clear()/clearstamps()) and undo behavior (e.g.,clone.undo()doesn’t touch source drawings) would prevent regressions onceclone()is updated to reinitialize those fields too.