Skip to content

Commit 18451a3

Browse files
authored
Merge pull request #1594 from Flow-Launcher/drag_and_drop_explorer
Fix Drag and Drop causing windows hang
2 parents c56a275 + 3415656 commit 18451a3

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

Flow.Launcher/ResultListBox.xaml.cs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ private void ListBox_PreviewMouseDown(object sender, MouseButtonEventArgs e)
9292
private Point start;
9393
private string path;
9494
private string query;
95+
// this method is called by the UI thread, which is single threaded, so we can be sloppy with locking
96+
private bool isDragging;
9597

9698
private void ResultList_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
9799
{
@@ -101,15 +103,16 @@ private void ResultList_PreviewMouseLeftButtonDown(object sender, MouseButtonEve
101103
path = result.Result.CopyText;
102104
query = result.Result.OriginQuery.RawQuery;
103105
start = e.GetPosition(null);
106+
isDragging = true;
104107
}
105-
106108
private void ResultList_MouseMove(object sender, MouseEventArgs e)
107109
{
108-
if (e.LeftButton != MouseButtonState.Pressed)
110+
if (e.LeftButton != MouseButtonState.Pressed|| !isDragging)
109111
{
110112
start = default;
111113
path = string.Empty;
112114
query = string.Empty;
115+
isDragging = false;
113116
return;
114117
}
115118

@@ -123,15 +126,19 @@ private void ResultList_MouseMove(object sender, MouseEventArgs e)
123126
|| Math.Abs(diff.Y) < SystemParameters.MinimumVerticalDragDistance)
124127
return;
125128

129+
isDragging = false;
130+
126131
var data = new DataObject(DataFormats.FileDrop, new[]
127132
{
128133
path
129134
});
130-
DragDrop.DoDragDrop((DependencyObject)sender, data, DragDropEffects.Move | DragDropEffects.Copy);
131-
132-
App.API.ChangeQuery(query, true);
133135

134-
e.Handled = true;
136+
// Reassigning query to a new variable because for some reason
137+
// after DragDrop.DoDragDrop call, 'query' loses its content, i.e. becomes empty string
138+
var rawQuery = query;
139+
var effect = DragDrop.DoDragDrop((DependencyObject)sender, data, DragDropEffects.Move | DragDropEffects.Copy);
140+
if (effect == DragDropEffects.Move)
141+
App.API.ChangeQuery(rawQuery, true);
135142
}
136143
private void ResultListBox_OnPreviewMouseRightButtonDown(object sender, MouseButtonEventArgs e)
137144
{

Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ internal static Result CreateFolderResult(string title, string subtitle, string
5858
SubTitle = Path.GetDirectoryName(path),
5959
AutoCompleteText = GetPathWithActionKeyword(path, ResultType.Folder),
6060
TitleHighlightData = StringMatcher.FuzzySearch(query.Search, title).MatchData,
61+
CopyText = path,
6162
Action = c =>
6263
{
6364
if (c.SpecialKeyState.CtrlPressed || (!Settings.PathSearchKeywordEnabled && !Settings.SearchActionKeywordEnabled))
@@ -174,7 +175,7 @@ internal static Result CreateOpenCurrentFolderResult(string path, bool windowsIn
174175
}, StringSplitOptions.None).Last();
175176

176177
var title = $"Open {folderName}";
177-
178+
178179
var subtitleFolderName = folderName;
179180

180181
// ie. max characters can be displayed without subtitle cutting off: "Program Files (x86)"
@@ -189,6 +190,7 @@ internal static Result CreateOpenCurrentFolderResult(string path, bool windowsIn
189190
AutoCompleteText = GetPathWithActionKeyword(path, ResultType.Folder),
190191
IcoPath = path,
191192
Score = 500,
193+
CopyText = path,
192194
Action = _ =>
193195
{
194196
Context.API.OpenDirectory(path);
@@ -213,6 +215,7 @@ internal static Result CreateFileResult(string filePath, Query query, int score
213215
AutoCompleteText = GetPathWithActionKeyword(filePath, ResultType.File),
214216
TitleHighlightData = StringMatcher.FuzzySearch(query.Search, Path.GetFileName(filePath)).MatchData,
215217
Score = score,
218+
CopyText = filePath,
216219
Action = c =>
217220
{
218221
try

0 commit comments

Comments
 (0)