Skip to content
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

Fix editing items in tree making changes to the wrong item #42423

Closed
wants to merge 1 commit into from

Conversation

EricEzaM
Copy link
Contributor

This was caused by the fact that selecting a new item would immediately change that item to the "popup_edited_item" which meant that when the item_edited method was called, the wrong item was being changed. "popup_edited_item" would change immediately upon selection because bring_up_editor was based on it's current selection status, which could have changed to true just before, in the same method, where selection is handled (see line 1758). This change makes it based upon it's previous selection status (which was already used) so that the editor does not popup immediately on first selection.

This was a pretty big pain to troubleshoot tbh. Tree could do with a refactor... It is quite messy and hard to decipher.

Closes #42419
tree_fixed

This was caused by the fact that selecting a new item would immediately change that item to the "popup_edited_item" which meant that when the `item_edited` method was called, the wrong item was being changed. "popup_edited_item" would change immediately upon selection because bring_up_editor was based on it's current selection status, which could have changed to true just before, in the same method, where selection is handled (see line 1758). This change makes it based upon it's _previous_ selection status (which was already used) so that the editor does not popup immediately on first selection.

This was a pretty big pain to troubleshoot tbh. Tree could do with a refactor... It is quite messy.
@akien-mga akien-mga added this to the 4.0 milestone Sep 30, 2020
@akien-mga
Copy link
Member

Bug #42419 sounds like a regression (otherwise I doubt it would have gone unnoticed so long if it's in 3.x too), so it would be good to figure out what caused the regression before attempting a fix.

This line hasn't been modified since 2017 (cbcf40b), so if there's a regression it's triggered by another part of the code.

@EricEzaM
Copy link
Contributor Author

Yeah it is a regression and only occurs in 4.0, cant repro in 3.X.

I had a look at the commit history of tree.cpp and couldn't see anything that would affect it... Bit I guess bisecting would be the best option.

@EricEzaM
Copy link
Contributor Author

After a long night of bisecting... it appears b3080bc is the first bad commit.

Confirmed after testing it and the previous commit, 09ba290, which does not exhibit the issue. I'll have to look into this tomorrow.

@akien-mga
Copy link
Member

Ouch, sorry I sent you on a chase after such an old mid-refactoring commit. I thought the regression might have been newer than that.

@EricEzaM
Copy link
Contributor Author

All good, I'm generally on a goose chase of a few bugs and fixes while working on #42351 and godotengine/godot-proposals#1532

All part of the fun haha :)

@EricEzaM
Copy link
Contributor Author

EricEzaM commented Oct 1, 2020

@akien-mga After a quick review, I think this still might be the correct solution.

See in the below gif, which is before this fix, when you click on another item it starts editing it immediately? I dont think this is the correct behaviour. It is also what causes the bug attached to this PR.

tree_editing_broken

When you click on an item it should stop editing the previous item but not start editing the one you clicked on:

tree_fixed

It's like on Windows if you are renaming a file, if you then click on another file it does not start immediately editing the one you clicked on.

Additionally the behaviour which occurs before this fix means that if, in response to the item_edited signal, you call tree->get_edited(), you will get the item you clicked on, as opposed to the one you actually edited.

@akien-mga akien-mga requested a review from a team February 25, 2021 16:45
@akien-mga
Copy link
Member

If you can confirm that this should still be the correct fix, we can likely merge as is @EricEzaM, unless someone else in @godotengine/gui-nodes has a strong opinion about this.

Copy link
Member

@Paulb23 Paulb23 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be already working as intended, tested this in Godot v3.3.2 and it works the same as 4.0.

The editor should only appear on first click when allow_reselect is false, setting it to true produces the behaviour seen here.

Might be worth changing the default value from false to true?

@KoBeWi
Copy link
Member

KoBeWi commented Aug 24, 2021

Might be worth changing the default value from false to true?

Wouldn't it basically mean that using non-default value would result in broken behavior? Changing default isn't enough to fix the issue.

@YuriSizov YuriSizov requested a review from a team August 24, 2021 23:33
@Paulb23
Copy link
Member

Paulb23 commented Aug 28, 2021

Wouldn't it basically mean that using non-default value would result in broken behavior?

As far as I know it is working as intended, with this PR allow_reselect no longer does anything. If the users expectations is what we see here, changing the default makes the current behaviour opt-in which should reduce confusion.

@KoBeWi
Copy link
Member

KoBeWi commented Aug 28, 2021

How is the behavior from the GIFs intended? Selecting an item will overwrite its value with the value of the previously selected one. This is definitely a bug.

Still, if the fix breaks something else, it's not correct.

@Paulb23
Copy link
Member

Paulb23 commented Aug 28, 2021

Ahh, no idea how I missed that, yeah that's not indented.

@EricEzaM
Copy link
Contributor Author

EricEzaM commented Oct 3, 2022

Can't repro issue any more

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

Successfully merging this pull request may close these issues.

Editing items in Tree control does not edit the correct item
4 participants