Skip to content

Commit 99ac5f0

Browse files
authored
Merge pull request #1 from AminSallah/reselect
Prevent reselect first result if needed
2 parents 50f71c0 + c8a2f10 commit 99ac5f0

File tree

4 files changed

+21
-9
lines changed

4 files changed

+21
-9
lines changed

Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,9 +293,10 @@ public interface IPublicAPI
293293
public bool IsGameModeOn();
294294

295295
/// <summary>
296-
/// Reload Query
296+
/// Reloads the query.
297+
/// This method should run
297298
/// </summary>
298-
/// <returns></returns>
299-
public void ReQuery();
299+
/// <param name="reselect">Choose the first result after reload if true; keep the last selected result if false. Default is true.</param>
300+
public void ReQuery(bool reselect = true);
300301
}
301302
}

Flow.Launcher/PublicAPIInstance.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ public bool IsGameModeOn()
315315
public void RegisterGlobalKeyboardCallback(Func<int, int, SpecialKeyState, bool> callback) => _globalKeyboardHandlers.Add(callback);
316316
public void RemoveGlobalKeyboardCallback(Func<int, int, SpecialKeyState, bool> callback) => _globalKeyboardHandlers.Remove(callback);
317317

318-
public void ReQuery() => _mainVM.ReQuery();
318+
public void ReQuery(bool reselect = true) => _mainVM.ReQuery(reselect);
319319

320320
#endregion
321321

Flow.Launcher/ViewModel/MainViewModel.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public partial class MainViewModel : BaseModel, ISavable
3333
#region Private Fields
3434

3535
private bool _isQueryRunning;
36+
private bool _reselect = true;
3637
private Query _lastQuery;
3738
private Result lastContextMenuResult = new Result();
3839
private List<Result> lastContextMenuResults = new List<Result>();
@@ -216,6 +217,15 @@ public void ReQuery()
216217
}
217218
}
218219

220+
public void ReQuery(bool reselect)
221+
{
222+
if (SelectedIsFromQueryResults())
223+
{
224+
_reselect = reselect;
225+
QueryResults(isReQuery: true);
226+
}
227+
}
228+
219229
[RelayCommand]
220230
private void LoadContextMenu()
221231
{
@@ -1151,7 +1161,8 @@ public void UpdateResultView(IEnumerable<ResultsForUpdate> resultsForUpdates)
11511161
}
11521162
}
11531163

1154-
Results.AddResults(resultsForUpdates, token);
1164+
Results.AddResults(resultsForUpdates, token, _reselect);
1165+
_reselect = true;
11551166
}
11561167

11571168
#endregion

Flow.Launcher/ViewModel/ResultsViewModel.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,23 +147,23 @@ public void AddResults(List<Result> newRawResults, string resultId)
147147
/// <summary>
148148
/// To avoid deadlock, this method should not called from main thread
149149
/// </summary>
150-
public void AddResults(IEnumerable<ResultsForUpdate> resultsForUpdates, CancellationToken token)
150+
public void AddResults(IEnumerable<ResultsForUpdate> resultsForUpdates, CancellationToken token, bool reselect = true)
151151
{
152152
var newResults = NewResults(resultsForUpdates);
153153

154154
if (token.IsCancellationRequested)
155155
return;
156156

157-
UpdateResults(newResults, token);
157+
UpdateResults(newResults, token, reselect);
158158
}
159159

160-
private void UpdateResults(List<ResultViewModel> newResults, CancellationToken token = default)
160+
private void UpdateResults(List<ResultViewModel> newResults, CancellationToken token = default, bool reselect = true)
161161
{
162162
lock (_collectionLock)
163163
{
164164
// update UI in one run, so it can avoid UI flickering
165165
Results.Update(newResults, token);
166-
if (Results.Any())
166+
if (reselect && Results.Any())
167167
SelectedItem = Results[0];
168168
}
169169

0 commit comments

Comments
 (0)