Skip to content

Commit 382de39

Browse files
committed
Add same-letter cycling for file-jumping
This will allow files selected by their first letter to be cycled when the same letter is pressed. e.g. having files "a.txt" and "ab.txt" Pressing "a" the first time will select "a.txt", pressing "a" a second time will selected "ab.txt" instead of reselecting "a.txt"
1 parent ca3f632 commit 382de39

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

Files UWP/Filesystem/ItemViewModel.cs

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,15 +182,36 @@ public string JumpString
182182
}
183183
set
184184
{
185+
// If current string is "a", and the next character typed is "a",
186+
// search for next file that starts with "a" (a.k.a. _jumpString = "a")
187+
if (_jumpString.Length == 1 && value == _jumpString + _jumpString)
188+
{
189+
value = _jumpString;
190+
}
185191
if (value != "")
186192
{
187193
ListedItem jumpedToItem = null;
188-
try
194+
ListedItem previouslySelectedItem = null;
195+
var candidateItems = _filesAndFolders.Where(f => f.FileName.Length >= value.Length && f.FileName.Substring(0, value.Length).ToLower() == value);
196+
197+
if (App.selectedTabInstance.accessibleContentFrame.SourcePageType == typeof(GenericFileBrowser))
198+
{
199+
previouslySelectedItem = (App.selectedTabInstance.accessibleContentFrame.Content as GenericFileBrowser).AllView.SelectedItem as ListedItem;
200+
}
201+
else if (App.selectedTabInstance.accessibleContentFrame.SourcePageType == typeof(PhotoAlbum))
202+
{
203+
previouslySelectedItem = (App.selectedTabInstance.accessibleContentFrame.Content as PhotoAlbum).gv.SelectedItem as ListedItem;
204+
}
205+
206+
// If the user is trying to cycle through items
207+
// starting with the same letter
208+
if (value.Length == 1 && previouslySelectedItem != null)
189209
{
190-
jumpedToItem = _filesAndFolders.Where(f => f.FileName.Substring(0, value.Length).ToLower() == value).First();
210+
// Try to select item lexicographically bigger than the previous item
211+
jumpedToItem = candidateItems.FirstOrDefault(f => f.FileName.CompareTo(previouslySelectedItem.FileName) > 0);
191212
}
192-
catch (ArgumentOutOfRangeException) { }
193-
catch (InvalidOperationException) { }
213+
if (jumpedToItem == null)
214+
jumpedToItem = candidateItems.FirstOrDefault();
194215

195216
if (jumpedToItem != null)
196217
{

0 commit comments

Comments
 (0)