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

Do not use fixed index in the TreeNode.PrevNode if the TreeView is sorted #10493

Conversation

elachlan
Copy link
Contributor

@elachlan elachlan commented Dec 18, 2023

Fixes #8768

This is a re-roll of the PR in #8774, but with the switch added.

Microsoft Reviewers: Open in CodeFlow

@elachlan elachlan requested a review from a team as a code owner December 18, 2023 00:11
@ghost ghost assigned elachlan Dec 18, 2023
@elachlan
Copy link
Contributor Author

CC: @snnz

@lonitra lonitra added the 📭 waiting-author-feedback The team requires more information from the author label Dec 19, 2023
@elachlan elachlan force-pushed the TreeNode-PrevNode-DoNotUseFixedIndexWhenSorted branch from 831082a to 4dc936e Compare January 2, 2024 01:39
@ghost ghost removed the 📭 waiting-author-feedback The team requires more information from the author label Jan 2, 2024
@elachlan
Copy link
Contributor Author

elachlan commented Jan 2, 2024

@lonitra I added the xml comment and renamed the switch to be more specific to its behavior.

@snnz
Copy link

snnz commented Jan 2, 2024

But this re-roll, it is totally incorrect. The purpose is to make sure that fixed index is NOT used if the tree is sorted, not vice versa. See the original PR: there should be !TreeView.Sorted in the condition.

@lonitra
Copy link
Member

lonitra commented Jan 3, 2024

@lonitra I added the xml comment and renamed the switch to be more specific to its behavior.

Thank you! The change looks good. Could you add tests to capture the behavior of the switch when it is on?

@lonitra lonitra added 📭 waiting-author-feedback The team requires more information from the author 📚 documentation Documentation bug or improvement labels Jan 3, 2024
@ghost
Copy link

ghost commented Jan 17, 2024

This submission has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 14 days.

It will be closed if no further activity occurs within 7 days of this comment.

@elachlan
Copy link
Contributor Author

Sorry! I'll try and get this sorted soon.

@ghost ghost removed 📭 waiting-author-feedback The team requires more information from the author 💤 no-recent-activity labels Jan 17, 2024
@elachlan
Copy link
Contributor Author

elachlan commented Feb 5, 2024

@lonitra I am unsure how we can unit test this. As the behavior of affects the underlying win32 tree view control.

Edit: I think I found a solution. I will push through in a bit.

@elachlan
Copy link
Contributor Author

elachlan commented Feb 5, 2024

I did some manual testing and was getting different results than what was specified in the #8768.

I then looked into the differences, we changed the behavior of the insert in #9078 by @gpetrou

Did we want to change the behavior back, or keep it as is? It used to add in "almost" reverse order, but now it adds it in the order provided (almost).

Before:
223826227-6cf6d1aa-3605-4e39-98a8-65116d5db21a

After:
image

Method of adding:

  treeView1.Nodes.AddRange([
  new TreeNode("3"),
  new TreeNode("5"),
  new TreeNode("1"),
  new TreeNode("4")
]);

@elachlan elachlan force-pushed the TreeNode-PrevNode-DoNotUseFixedIndexWhenSorted branch from 4be254b to 24593fe Compare February 5, 2024 06:49
@elachlan
Copy link
Contributor Author

elachlan commented Feb 5, 2024

Test is showing some weird behavior and I am not sure why. It doesn't line up with what I observed when manually testing.

Expected: 2,5,3,1,4
Actual: 2,3,4,5,1

@elachlan elachlan requested a review from lonitra February 5, 2024 06:53
@elachlan elachlan added waiting-on-team This work item needs to be discussed with team or is waiting on team action in order to proceed waiting-review This item is waiting on review by one or more members of team and removed waiting-on-team This work item needs to be discussed with team or is waiting on team action in order to proceed labels Feb 7, 2024
@lonitra
Copy link
Member

lonitra commented Feb 9, 2024

Did we want to change the behavior back, or keep it as is? It used to add in "almost" reverse order, but now it adds it in the order provided (almost).

Had you investigated what exactly caused the behavior change? From glancing at the PR it doesn't seem like the change was intentional.

Test is showing some weird behavior and I am not sure why. It doesn't line up with what I observed when manually testing.

Hm.. That is concerning. It seems like the state between our control and the underlying one is mismatched and the results you are getting are actually being sorted when it comes to the underlying control.. This looks a bit suspicious to me

if (tv is not null && tv.Sorted)
{
return _owner.AddSorted(tv, node);
}

this is where it looks like we eventually get to from AddRange. Could you maybe debug through this and see if somewhere along the line we are adding the tree node to a unexpected index for the underlying control? -- I cannot look into this too deepy right now, apologies!

@lonitra lonitra added 📭 waiting-author-feedback The team requires more information from the author and removed waiting-review This item is waiting on review by one or more members of team labels Feb 9, 2024
@elachlan
Copy link
Contributor Author

Sorry I haven't sorted this yet. Hopefully soon.

currentInd = fixedInd;
if (!LocalAppContextSwitches.TreeNodePrevNodeDoNotUseFixedIndexWithSortedTreeView || TreeView is null || !TreeView.Sorted)
{
currentIndex = fixedIndex;
Copy link
Member

Choose a reason for hiding this comment

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

The idea of this fix is that we want to skip the fixed index perf optimization when we are sorting the treeview.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, based on this comment from the issue reporter.
#10493 (comment)

Copy link
Member

Choose a reason for hiding this comment

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

Then we don't have to set FIxedIndex to the currently displayed number of child nodes, I prefer fix in #11300

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No problem. Ill close this then. The tests still seem weird. So worth investigating.

@elachlan elachlan closed this May 9, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Jun 9, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
📚 documentation Documentation bug or improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TreeNodeCollection.AddRange works incorrectly for non-empty collection of the sorted TreeView
4 participants