Skip to content

Conversation

AWAS666
Copy link

@AWAS666 AWAS666 commented Oct 9, 2025

Closes #3548

Might be worth to consider to also add a feature to reorder with select and arrow up/down buttons

@prlabeler prlabeler bot added the enhancement New feature or request label Oct 9, 2025
@github-actions github-actions bot added this to the 2.1.0 milestone Oct 9, 2025
Copy link

gitstream-cm bot commented Oct 9, 2025

🥷 Code experts: Jack251970, onesounds

Jack251970 has most 👩‍💻 activity in the files.
Jack251970, onesounds have most 🧠 knowledge in the files.

See details

Plugins/Flow.Launcher.Plugin.WebSearch/SettingsControl.xaml

Activity based on git-commit:

Jack251970
OCT 25 additions & 17 deletions
SEP
AUG
JUL
JUN
MAY

Knowledge based on git-blame:
Jack251970: 38%
onesounds: 37%

Plugins/Flow.Launcher.Plugin.WebSearch/SettingsControl.xaml.cs

Activity based on git-commit:

Jack251970
OCT 23 additions & 0 deletions
SEP
AUG
JUL
JUN
MAY

Knowledge based on git-blame:
Jack251970: 16%
onesounds: 11%

✨ Comment /gs review for LinearB AI review. Learn how to automate it here.

Copy link

gitstream-cm bot commented Oct 9, 2025

Be a legend 🏆 by adding a before and after screenshot of the changes you made, especially if they are around UI/UX.

Copy link
Contributor

coderabbitai bot commented Oct 9, 2025

📝 Walkthrough

Walkthrough

Adds drag-and-drop reordering to the WebSearch settings ListView. XAML enables drag/drop and wires PreviewMouseLeftButtonDown, PreviewMouseMove, and Drop events. Code-behind implements drag initiation, movement threshold detection, drop handling to reorder items, and helpers to resolve item containers and traverse the visual tree. No public APIs changed.

Changes

Cohort / File(s) Summary
WebSearch settings drag-and-drop
Plugins/Flow.Launcher.Plugin.WebSearch/SettingsControl.xaml, Plugins/Flow.Launcher.Plugin.WebSearch/SettingsControl.xaml.cs
XAML: enables AllowDrop, adds PreviewMouseLeftButtonDown, PreviewMouseMove, and Drop handlers on ListView. Code-behind: tracks drag start point, initiates drag on movement, handles drop to reorder ListView items, adds helper methods for item container/ancestor lookup.

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant ListView as Settings ListView
  participant CodeBehind as SettingsControl.xaml.cs
  participant Collection as ItemsSource

  User->>ListView: MouseLeftButtonDown (on item)
  ListView->>CodeBehind: PreviewMouseLeftButtonDown
  CodeBehind->>CodeBehind: Record drag start point

  User->>ListView: Mouse move with button pressed
  ListView->>CodeBehind: PreviewMouseMove
  CodeBehind->>CodeBehind: Check threshold and source item
  CodeBehind->>ListView: DoDragDrop(start item, Move)

  User->>ListView: Drop on target position
  ListView->>CodeBehind: Drop
  CodeBehind->>Collection: Remove source item
  CodeBehind->>Collection: Insert at target index
  CodeBehind->>ListView: Update selection/visuals
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Title Check ✅ Passed The title clearly summarizes the main change by indicating that web searches can be reordered via drag and drop, directly reflecting the implemented feature.
Linked Issues Check ✅ Passed The changes implement the drag-and-drop mechanism in the settings panel as requested by issue #3548, providing users the ability to rearrange web search engines and fulfilling the core coding objectives from the linked issue.
Out of Scope Changes Check ✅ Passed All modifications are focused on adding drag-and-drop reorder functionality in the settings control, with no unrelated or out-of-scope code changes present.
Description Check ✅ Passed The description references closing issue #3548 and discusses the implemented drag-and-drop reorder feature while suggesting future enhancements, making it related to the changeset.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
Plugins/Flow.Launcher.Plugin.WebSearch/SettingsControl.xaml.cs (2)

176-195: Consider removing the unnecessary cast.

The drag initiation logic is correct. However, line 185 unnecessarily casts sender to ListView when the parameter type already guarantees it.

Apply this diff to remove the cast:

-            ListView listView = sender as ListView;
+            var listView = (ListView)sender;

Or simply use sender directly if type safety is clear from context.


211-217: Consider using full variable names for improved readability.

The abbreviations removedIdx and targetIdx are functional but could be more readable as removedIndex and targetIndex. This also addresses the spelling warnings from static analysis.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5ae159d and b9a4314.

📒 Files selected for processing (2)
  • Plugins/Flow.Launcher.Plugin.WebSearch/SettingsControl.xaml (1 hunks)
  • Plugins/Flow.Launcher.Plugin.WebSearch/SettingsControl.xaml.cs (3 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-09-13T06:04:26.977Z
Learnt from: Jack251970
PR: Flow-Launcher/Flow.Launcher#3593
File: Plugins/Flow.Launcher.Plugin.WebSearch/SettingsControl.xaml.cs:143-165
Timestamp: 2025-09-13T06:04:26.977Z
Learning: In Plugins/Flow.Launcher.Plugin.WebSearch/SettingsControl.xaml, the ListView_SizeChanged handler in the C# file assumes 5 GridViewColumns but the XAML may have more columns. The user Jack251970 indicated this mismatch doesn't need to be fixed when pointed out during PR #3593 review.

Applied to files:

  • Plugins/Flow.Launcher.Plugin.WebSearch/SettingsControl.xaml
🪛 GitHub Check: Check Spelling
Plugins/Flow.Launcher.Plugin.WebSearch/SettingsControl.xaml.cs

[warning] 217-217:
Idx is not a recognized word. (unrecognized-spelling)


[warning] 214-214:
Idx is not a recognized word. (unrecognized-spelling)


[warning] 214-214:
Idx is not a recognized word. (unrecognized-spelling)


[warning] 212-212:
Idx is not a recognized word. (unrecognized-spelling)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: gitStream.cm
🔇 Additional comments (5)
Plugins/Flow.Launcher.Plugin.WebSearch/SettingsControl.xaml.cs (4)

18-18: LGTM!

The _dragStartPoint field correctly tracks the initial mouse position for drag threshold detection.


171-174: LGTM!

The handler correctly captures the mouse position when the left button is pressed, which is then used to calculate the drag threshold in ListView_PreviewMouseMove.


222-229: LGTM!

The visual tree traversal logic correctly locates the nearest ListViewItem container.


231-240: LGTM!

The generic ancestor finder is a standard WPF pattern and correctly traverses the visual tree.

Plugins/Flow.Launcher.Plugin.WebSearch/SettingsControl.xaml (1)

55-58: LGTM!

The XAML changes correctly wire up the drag-and-drop functionality by adding the necessary event handlers and enabling drop support on the ListView.

Comment on lines +197 to +220
private void ListView_Drop(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(typeof(SearchSource)))
{
SearchSource droppedData = e.Data.GetData(typeof(SearchSource)) as SearchSource;
ListView listView = sender as ListView;
var target = GetNearestContainer(e.OriginalSource);

if (target == null)
return;

SearchSource targetData = (SearchSource)listView.ItemContainerGenerator.ItemFromContainer(target);

var items = _settings.SearchSources;
int removedIdx = items.IndexOf(droppedData);
int targetIdx = items.IndexOf(targetData);

if (removedIdx == targetIdx)
return;

items.RemoveAt(removedIdx);
items.Insert(targetIdx, droppedData);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Add null check for targetData to prevent NullReferenceException.

Line 208 retrieves targetData from the item container, but there's no validation before using it on line 212. If ItemContainerGenerator.ItemFromContainer returns null, the subsequent IndexOf call will throw a NullReferenceException.

Apply this diff to add the null check:

             SearchSource targetData = (SearchSource)listView.ItemContainerGenerator.ItemFromContainer(target);
+
+            if (targetData == null)
+                return;

             var items = _settings.SearchSources;

Additionally, line 202 has an unnecessary cast (similar to line 185):

-            ListView listView = sender as ListView;
+            var listView = (ListView)sender;
🧰 Tools
🪛 GitHub Check: Check Spelling

[warning] 217-217:
Idx is not a recognized word. (unrecognized-spelling)


[warning] 214-214:
Idx is not a recognized word. (unrecognized-spelling)


[warning] 214-214:
Idx is not a recognized word. (unrecognized-spelling)


[warning] 212-212:
Idx is not a recognized word. (unrecognized-spelling)

🤖 Prompt for AI Agents
In Plugins/Flow.Launcher.Plugin.WebSearch/SettingsControl.xaml.cs around lines
197 to 220, the code obtains targetData via
ItemContainerGenerator.ItemFromContainer but does not check for null before
using it, which can cause a NullReferenceException; add a null check after
retrieving targetData and return early if it's null (so subsequent IndexOf calls
are safe). Also remove the unnecessary cast at line 202 (the redundant "as
ListView" or similar) to simplify the code.

@Jack251970 Jack251970 requested a review from Copilot October 10, 2025 04:23
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements drag and drop functionality to enable reordering of web search entries in the Flow Launcher Plugin WebSearch settings interface.

  • Added drag and drop event handlers to the ListView control
  • Implemented mouse tracking and visual tree helper methods to support drag operations
  • Added necessary using statements for drag and drop functionality

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
SettingsControl.xaml.cs Added drag and drop implementation with mouse event handlers and helper methods
SettingsControl.xaml Added event handler bindings and AllowDrop property to ListView

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

return;

items.RemoveAt(removedIdx);
items.Insert(targetIdx, droppedData);
Copy link

Copilot AI Oct 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The insertion logic is incorrect when dragging items downward. When an item is removed from an earlier position and inserted at a later position, the target index should be adjusted by -1 to account for the removal. Consider using items.Insert(removedIdx < targetIdx ? targetIdx - 1 : targetIdx, droppedData);

Suggested change
items.Insert(targetIdx, droppedData);
items.Insert(removedIdx < targetIdx ? targetIdx - 1 : targetIdx, droppedData);

Copilot uses AI. Check for mistakes.

Comment on lines +185 to +186
ListView listView = sender as ListView;
ListViewItem listViewItem = FindAncestor<ListViewItem>((DependencyObject)e.OriginalSource);
Copy link

Copilot AI Oct 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Use pattern matching instead of 'as' operator for better null safety and readability: if (sender is not ListView listView) return; and similar for listViewItem.

Copilot uses AI. Check for mistakes.

Comment on lines +201 to +202
SearchSource droppedData = e.Data.GetData(typeof(SearchSource)) as SearchSource;
ListView listView = sender as ListView;
Copy link

Copilot AI Oct 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Use pattern matching instead of 'as' operator for better null safety: if (e.Data.GetData(typeof(SearchSource)) is not SearchSource droppedData) return; and if (sender is not ListView listView) return;

Copilot uses AI. Check for mistakes.

@Jack251970
Copy link
Member

Please resolve reviews from coderabbitai[bot] and Copilot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature Request: Ability to Rearrange Web Search Engines via Drag and Drop
2 participants