Skip to content

Commit

Permalink
Bug 1891: Correct letter case variant of remote directory in director…
Browse files Browse the repository at this point in the history
…y tree was not always selected

https://winscp.net/tracker/1891
(cherry picked from commit ce46019)

Source commit: 89f636c09bbe784c3ac1878b72cd5a2882ec808c
  • Loading branch information
martinprikryl committed Nov 26, 2020
1 parent 3859e04 commit adfb862
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion source/components/UnixDriveView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,8 @@ TTreeNode * __fastcall TCustomUnixDriveView::FindNodeToPath(UnicodeString Path)
{
UnicodeString DirName = UnixExtractFileName(Path);
int StartIndex = 0;
int EndIndex = Parent->Count - 1;
int LastIndex = Parent->Count - 1;
int EndIndex = LastIndex;

while (true)
{
Expand All @@ -786,6 +787,20 @@ TTreeNode * __fastcall TCustomUnixDriveView::FindNodeToPath(UnicodeString Path)
int C = DoCompareText(DirName, NodeDir);
if (C == 0)
{
// In case there are more items that are case insensitivelly or logically equivalent,
// walk back to find the first such one and then walk forward through all such items,
// looking for an exact binary match.
// If so such match is found (can it even happen?), return the last equivalent item.
while ((Index > 0) && (DoCompareText(DirName, Parent->Item[Index - 1]->Text) == 0))
{
Index--;
}
while (!SameStr(DirName, Parent->Item[Index]->Text) &&
(Index < LastIndex) &&
(DoCompareText(DirName, Parent->Item[Index + 1]->Text) == 0))
{
Index++;
}
Result = Parent->Item[Index];
break;
}
Expand Down

0 comments on commit adfb862

Please sign in to comment.