Rubberduck: Sorting in the Code Explorer doesn't work properly on initial sort.

Created on 15 Jul 2016  路  19Comments  路  Source: rubberduck-vba/Rubberduck

The initial sort order shown in the CodeExplorer doesn't seem to make much sense:
rd

It's not sorted by name (Get should come after all the Gathers) nor by code order (GatherData is defined first, yet listed third).

However, if there are different item types in the module, they are sorted by type, then name:
rd2
Almost:
rd3
Unless it's a matter of case sensitivity in the sort, except:
rd4
_cut me some slack, have you tried drawing a question mark using a trackball lately???_

And it's not a matter of Public vs Private or Sub vs Function:

Private Sub PrintSbMTotalRow
Public Sub BuildReportDriver
Public Sub ReportClinicChange
Public Sub TestBuildReport
Public Sub UpdatePivotDates
Private Sub PrintSbMValue

However, once sort settings have been manually changed, everything seems to be just fine:
rd6
rd7

Though sorting does seem to be case sensitive, can that be changed, or at least an option given?
rd8

But, reselecting group sorting is still a bit wonky:
rd9

Private Sub PrintNPSDataRows
Public Sub BuildReportDriver
Public Sub ReportClinicChange
Public Sub TestBuildReport
Private Sub PrintNPSFooterRows

_Note: Public Sub UpdatePivotDates, which was sorted into this group in the initial sort, is no longer here, I've confirmed that it's sorted in its proper location._
rd8

Also, sort settings are not preserved. I usually uncheck By Type, yet each time I start an IDE, it's selected.

bug feature-code-explorer user-interface

Most helpful comment

I guess this was closed because of the commit message. If it isn't fixed in the next release, just reopen it.

All 19 comments

@Hosch250 I thought this was as designed, but it doesn't appear to be. Can you take a look?

At @Hosch250's request:

for the first image:
rd

Private Function GatherScoreByMonthData
Private Function GetCount
Public Function GatherData
Private Sub GatherCareExperienceData
Private Sub GatherSatSurveyData

hmmm... maybe it is grouping those by type, then by visibility, then alpha. _However_, the 4th image (the one with the _awesome_ question mark), shows all Subs but the visibility changes from Private to Public, then back to Private

Notice that item 3 doesn't have the same image as the ones above and below it. How did that get put in the middle of a group?

The others have pretty much the same problem.

OK, those are different images for public/private functions.

Turning By Type off, then on again, fixes this.

Except that it doesn't, @Hosch250.

The 2nd to last image in my OP shows 3 Public Sub between several Private Sub _after_ I reselected ByType (you'll see that I disabled by Type in the image 2 above that with the big exclamation point). There are a long list of Private Sub above and below that small snapshot. I can get a broader view if you'd like.

Could you share the project with me? I found that changing this:

_projects = new ObservableCollection<CodeExplorerItemViewModel>(value.OrderBy(o => o.NameWithSignature));
ReorderChildNodes(_projects);

to this:

ReorderChildNodes(value);
_projects = new ObservableCollection<CodeExplorerItemViewModel>(value.OrderBy(o => o.NameWithSignature));

fixes the initial sort problem (don't ask me why...)

Are there any hidden Unicode or unusual characters classified as unidefined being sorted within hex or strings that RD collected in the initial run? Just thinking that this could have been seen as part of its logic.

I guess this was closed because of the commit message. If it isn't fixed in the next release, just reopen it.

Sadly, this doesn't seem to have been fixed in 2.0.6.

rd

Same code, same module declarations, same example shot as originally posted (well, it's a new screen grab with 2.0.6 running, but it's the same place in the tree. You knew what I meant...

I'm don't see anywhere that I can reopen it, so one of y'alls gonna have to.

Could you make a minimal reproducable example and share the project so I can see this first hand?

Rename this from .txt to .xlsm to get around Git restrictions
RD Default Sort Issue.txt
rd

Hmm, as soon as I change it, it messes everything up.

Yeah, it does sort properly once you change any of the sort order settings, but not until then.

Also, the sort settings are not retained from one launch to the next, but that may need to be a different issue

Opposite here. Worked right the first time, but not afterward... And yeah, we don't remember sort orders.

that's.... weird...

I'm running Office 2010 (v14.0.7166) 64-bit in 64-bit Win7, if that makes any difference

Got it. I essentially wrote a random sort generator :P

// keep types with different icons and the same declaration type (document/class module) separate
// documents come first
if (x.ExpandedIcon != y.ExpandedIcon)
{
    // ReSharper disable once PossibleInvalidOperationException - this will have a component
    return x.QualifiedSelection.Value.QualifiedName.Component.Type ==
           Microsoft.Vbe.Interop.vbext_ComponentType.vbext_ct_Document
        ? -1
        : 1;
}

Notice that it correctly puts documents first; otherwise, it always returns 1, regardless of what x is and what y is.

Was this page helpful?
0 / 5 - 0 ratings