diff --git a/Flow.Launcher.Plugin/SharedCommands/FilesFolders.cs b/Flow.Launcher.Plugin/SharedCommands/FilesFolders.cs
index 440ac6756..bac3c212b 100644
--- a/Flow.Launcher.Plugin/SharedCommands/FilesFolders.cs
+++ b/Flow.Launcher.Plugin/SharedCommands/FilesFolders.cs
@@ -160,5 +160,30 @@ namespace Flow.Launcher.Plugin.SharedCommands
return false;
}
+
+ ///
+ /// Gets the previous level directory from a path string.
+ /// Checks that previous level directory exists and returns it
+ /// as a path string, or empty string if doesnt exit
+ ///
+ public static string GetPreviousExistingDirectory(Func locationExists, string path)
+ {
+ var previousDirectoryPath = "";
+ int index = path.LastIndexOf('\\');
+ if (index > 0 && index < (path.Length - 1))
+ {
+ previousDirectoryPath = path.Substring(0, index + 1);
+ if (!locationExists(path))
+ {
+ return "";
+ }
+ }
+ else
+ {
+ return "";
+ }
+
+ return previousDirectoryPath;
+ }
}
}
diff --git a/Flow.Launcher.Test/Plugins/ExplorerTest.cs b/Flow.Launcher.Test/Plugins/ExplorerTest.cs
index 12121ec85..14469242e 100644
--- a/Flow.Launcher.Test/Plugins/ExplorerTest.cs
+++ b/Flow.Launcher.Test/Plugins/ExplorerTest.cs
@@ -37,9 +37,9 @@ namespace Flow.Launcher.Test.Plugins
private bool MethodIndexExistsReturnsFalse(string dummyString) => false;
- private bool LocationExistsReturnsTrue(string dummyString) => true;
+ private bool PreviousLocationExistsReturnsTrue(string dummyString) => true;
- private bool LocationNotExistReturnsFalse(string dummyString) => false;
+ private bool PreviousLocationNotExistReturnsFalse(string dummyString) => false;
[TestCase("C:\\Dropbox", "directory='file:C:\\Dropbox'")]
public void GivenWindowsIndexSearch_WhenProvidedFolderPath_ThenQueryWhereRestrictionsShouldUseDirectoryString(string path, string expectedString)
@@ -200,17 +200,30 @@ namespace Flow.Launcher.Test.Plugins
}
- [TestCase(@"C:\Dropbox\Drop", @"C:\Dropbox")]
- [TestCase(@"C:\Dropbox\Drop\App", @"C:\Dropbox\Drop")]
- public void GivenAPartialPath_WhenPreviousLevelDirectoryExists_ThenShouldReturnThePreviousDirectoryPathString()
+ [TestCase(@"C:\Dropbox\Drop", true, @"C:\Dropbox\")]
+ [TestCase(@"C:\Dropbox\Drop\App", true, @"C:\Dropbox\Drop\")]
+ [TestCase(@"C:\Dropbox\Drop", false, "")]
+ public void GivenAPartialPath_WhenPreviousLevelDirectoryExists_ThenShouldReturnThePreviousDirectoryPathString(
+ string path, bool previousDirectoryExists, string expectedString)
{
+ // When
+ Func previousLocationExists = null;
+ if (previousDirectoryExists)
+ {
+ previousLocationExists = PreviousLocationExistsReturnsTrue;
+ }
+ else
+ {
+ previousLocationExists = PreviousLocationNotExistReturnsFalse;
+ }
- }
-
- [TestCase(@"C:\Dropbox\Drop", "")]
- public void GivenAPartialPath_WhenPreviousLevelDirectoryNotExists_ThenShouldReturnEmptyString()
- {
+ // Given
+ var previousDirectoryPath = FilesFolders.GetPreviousExistingDirectory(previousLocationExists, path);
+ //Then
+ Assert.IsTrue(previousDirectoryPath == expectedString,
+ $"Expected path string: {expectedString} {Environment.NewLine} " +
+ $"Actual path string is {previousDirectoryPath} {Environment.NewLine}");
}
public void GivenWindowsIndexSearch_WhenSearchPatternHotKeyIsSearchAll_ThenQueryWhereRestrictionsShouldUseScopeString() { }
diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs
index 155b89831..19fbdc9e6 100644
--- a/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs
+++ b/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs
@@ -113,22 +113,12 @@ namespace Flow.Launcher.Plugin.Explorer.Search
if (locationExists(querySearchString))
return ResultManager.CreateOpenCurrentFolderResult(querySearchString, false);
- var partialPath = "";
- int index = querySearchString.LastIndexOf('\\');
- if (index > 0 && index < (querySearchString.Length - 1))
- {
- partialPath = querySearchString.Substring(0, index + 1);
- if (!locationExists(partialPath))
- {
- return null;
- }
- }
- else
- {
- return null;
- }
+ var previousDirectoryPath = FilesFolders.GetPreviousExistingDirectory(FilesFolders.LocationExists, querySearchString);
- return ResultManager.CreateOpenCurrentFolderResult(partialPath, true);
+ if (string.IsNullOrEmpty(previousDirectoryPath))
+ return null;
+
+ return ResultManager.CreateOpenCurrentFolderResult(previousDirectoryPath, true);
}
}
}