Skip to content

Conversation

onesounds
Copy link
Contributor

@onesounds onesounds commented Apr 11, 2025

What's the PR

  • Although multiple action keywords can now be registered using spaces, this feature does not apply to plugins that do not internally support multiple action keywords.

  • To prevent user confusion or unintended attempts, code has been added to block whitespace input (including space, tab, and pasted whitespace) in the action keyword registration TextBox for such plugins.

  • This is handled at the UI input level to avoid complex internal processing and in case multi-keyword support is implemented in the future.

  • Applied to the Websearch and Explorer plugins.

Follows on from #3261

… for plugins that do not support multiple action keywords.
@prlabeler prlabeler bot added the enhancement New feature or request label Apr 11, 2025

This comment has been minimized.

Copy link

gitstream-cm bot commented Apr 11, 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 Apr 11, 2025

📝 Walkthrough

Walkthrough

This pull request introduces new event handlers for paste operations and key down events in two plugins. In both Explorer and WebSearch plugins, the paste event is intercepted to validate the inserted text by rejecting content that contains whitespace or is of an unexpected data type. Additionally, a key down event handler has been added to block the Space key input in specific text boxes. Minor UI adjustments include the standardization of margin formatting. The IPublicAPI interface documentation was enhanced to clarify behavior and usage of methods related to action keywords and settings storage.

Changes

File(s) Change Summary
Plugins/Flow.Launcher.Plugin.Explorer/Views/ActionKeywordSetting.xaml
Plugins/Flow.Launcher.Plugin.Explorer/Views/ActionKeywordSetting.xaml.cs
Added DataObject.Pasting="TextBox_Pasting" in a TextBox control. Introduced TextBox_Pasting method to check pasted text and cancel if whitespace is detected. Modified key down event to block the Space key.
Plugins/Flow.Launcher.Plugin.WebSearch/.../SearchSourceSetting.xaml
Plugins/Flow.Launcher.Plugin.WebSearch/.../SearchSourceSetting.xaml.cs
Updated margin attributes from comma-separated to space-separated values. Added DataObject.Pasting and PreviewKeyDown event handlers in a TextBox bound to SearchSource.ActionKeyword. Introduced TextBox_PreviewKeyDown and TextBox_Pasting methods to cancel paste actions with whitespace and block space input.
Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs Enhanced XML documentation comments for methods AddActionKeyword, SaveSettingJsonStorage<T>, and SaveCacheBinaryStorageAsync<T> to clarify usage, warn about whitespace in action keywords, and reference related methods for automatic saving. No signature changes.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant TextBox
    participant PasteHandler
    User->>TextBox: Initiates paste operation
    TextBox->>PasteHandler: Triggers DataObject.Pasting event
    PasteHandler->>PasteHandler: Validate pasted data (text type and no whitespace)
    alt Invalid content (contains whitespace or non-text)
        PasteHandler->>TextBox: Cancel paste command
    else Valid content
        PasteHandler->>TextBox: Allow paste command
    end
Loading
sequenceDiagram
    participant User
    participant TextBox
    participant KeyDownHandler
    User->>TextBox: Presses Space key
    TextBox->>KeyDownHandler: Raises KeyDown/PreviewKeyDown event
    KeyDownHandler->>KeyDownHandler: Detects Space key press
    KeyDownHandler->>TextBox: Sets event.Handled to true (blocks input)
Loading

Possibly related PRs

  • Support Multiple keywords for Plugins #3261: Modifies backend logic to support multiple action keywords separated by whitespace and updates related plugin metadata handling; complements this PR's UI-level input validation for action keywords.

Suggested labels

bug, kind/ui, Explorer Plugin, Documentation

Suggested reviewers

  • onesounds

Poem

🐇 I’m a rabbit, quick and spry,
Spaces blocked, no paste awry,
In Explorer and WebSearch too,
Clean inputs now shine through.
Docs polished with care,
Our code’s now fair and square! ✨🐰


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d97b9ed and 7797527.

📒 Files selected for processing (1)
  • Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs (3 hunks)
✅ Files skipped from review due to trivial changes (1)
  • Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: gitStream.cm
  • GitHub Check: gitStream.cm

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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: 0

🧹 Nitpick comments (2)
Plugins/Flow.Launcher.Plugin.Explorer/Views/ActionKeywordSetting.xaml.cs (1)

102-116: Comprehensive paste validation for whitespace prevention.

The implementation properly validates pasted content and prevents pasting text with whitespace characters, as well as non-text data. Consider adding a brief XML comment to explain the method's purpose.

+/// <summary>
+/// Validates pasted content to prevent whitespace in action keywords as this plugin doesn't support multiple keywords.
+/// </summary>
 private void TextBox_Pasting(object sender, DataObjectPastingEventArgs e)
Plugins/Flow.Launcher.Plugin.WebSearch/SearchSourceSetting.xaml.cs (1)

149-156: Proper implementation of Space key blocking.

This method correctly prevents users from entering Space characters, which supports the PR's goal of preventing whitespace in action keywords.

-//Block Space Input
+// Prevent whitespace in action keywords as this plugin doesn't support multiple keywords
 private void TextBox_PreviewKeyDown(object sender, KeyEventArgs e)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d06a803 and b842f08.

📒 Files selected for processing (4)
  • Plugins/Flow.Launcher.Plugin.Explorer/Views/ActionKeywordSetting.xaml (1 hunks)
  • Plugins/Flow.Launcher.Plugin.Explorer/Views/ActionKeywordSetting.xaml.cs (2 hunks)
  • Plugins/Flow.Launcher.Plugin.WebSearch/SearchSourceSetting.xaml (7 hunks)
  • Plugins/Flow.Launcher.Plugin.WebSearch/SearchSourceSetting.xaml.cs (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: gitStream.cm
  • GitHub Check: gitStream.cm
  • GitHub Check: gitStream.cm
🔇 Additional comments (5)
Plugins/Flow.Launcher.Plugin.Explorer/Views/ActionKeywordSetting.xaml (1)

83-83: Good addition of paste validation!

This new event handler ensures that whitespace cannot be introduced via pasting operations, supporting the PR's objective of preventing whitespace in action keywords for plugins that don't support multiple keywords.

Plugins/Flow.Launcher.Plugin.WebSearch/SearchSourceSetting.xaml (2)

174-175: Appropriate input validation!

The addition of both paste validation and key press handling ensures that whitespace cannot be entered in the action keyword field, which aligns with the PR objective.


59-59: Consistent margin format standardization.

The margins have been updated from comma-separated to space-separated format, improving readability and maintaining consistency across the codebase.

Also applies to: 62-62, 65-65, 71-71, 78-78, 86-86, 108-108, 171-171, 180-180, 188-188, 201-201, 205-205, 210-210

Plugins/Flow.Launcher.Plugin.Explorer/Views/ActionKeywordSetting.xaml.cs (1)

97-101: Proper Space key blocking.

This addition prevents users from entering Space characters, which aligns with preventing whitespace in action keywords for plugins that don't support multiple keywords.

Plugins/Flow.Launcher.Plugin.WebSearch/SearchSourceSetting.xaml.cs (1)

157-171: Well-implemented paste validation.

The implementation correctly cancels paste operations when the content contains whitespace or is not valid text data, enforcing the constraint consistently.

@onesounds onesounds enabled auto-merge April 16, 2025 21:23
# Conflicts:
#	Plugins/Flow.Launcher.Plugin.Explorer/Views/ActionKeywordSetting.xaml.cs

This comment has been minimized.

@onesounds
Copy link
Contributor Author

@coderabbitai Review It. By the way, is it okay to use LINQ? I’m wondering if other developers might find it annoying or not.

Copy link
Contributor

coderabbitai bot commented Apr 17, 2025

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

@onesounds I've reviewed your PR and it looks good! The changes properly prevent whitespace input in action keyword fields both via keyboard input and paste operations, which accomplishes the stated goal.

Regarding LINQ usage - it's absolutely fine to use LINQ in this codebase. It's already widely used throughout the project, and your specific usage (the Any() method to check for whitespace) is a clean, readable approach. LINQ is a standard feature in modern C# development that makes code more concise and expressive. The way you've used it to check for whitespace characters is perfectly appropriate and follows good C# practices.

The changes you've made are well-implemented and the LINQ usage enhances rather than detracts from code quality. No concerns there!


🏁 Script executed:

#!/bin/bash
# Check how common LINQ usage is in the codebase
echo "Files importing System.Linq:"
rg -l "using System.Linq" --type=csharp | wc -l

echo "Sample files using LINQ:"
rg -l "using System.Linq" --type=csharp | head -n 5

echo "Common LINQ operations in codebase:"
rg -A 1 "\.(Where|Select|Any|All|First|FirstOrDefault|OrderBy|GroupBy|Skip|Take|Count)\(" --type=csharp | head -n 15

echo "Checking for any LINQ usage in the Flow.Launcher.Plugin.WebSearch namespace:"
rg -l "using System.Linq" Plugins/Flow.Launcher.Plugin.WebSearch/

echo "Checking for any LINQ usage in the Flow.Launcher.Plugin.Explorer namespace:"
rg -l "using System.Linq" Plugins/Flow.Launcher.Plugin.Explorer/

Length of output: 3752


@onesounds I've reviewed your PR and analyzed the codebase to answer your question about LINQ usage.

Your changes look good! The implementation effectively prevents whitespace in action keyword fields through both keyboard blocking and paste validation.

Regarding LINQ usage - it's absolutely fine and even encouraged in this codebase. The analysis shows:

  • 90 files already import System.Linq
  • Both WebSearch (6 files) and Explorer (15 files) plugins extensively use LINQ
  • The exact pattern you used (Any(char.IsWhiteSpace)) is already present in SearchSourceSetting.xaml.cs
  • LINQ operations like Select(), Where(), and ToList() are common throughout the codebase

Your implementation is perfectly aligned with the project's coding style. Using LINQ here makes the code more readable and concise, which is exactly what LINQ is designed for. Other developers will likely appreciate this approach as it follows established patterns in the codebase.

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

A concise update to disable multi-whitespace input for action keywords in the WebSearch and Explorer plugins.

  • Added keydown event handlers to block whitespace input via the keyboard.
  • Added paste event handlers to cancel commands when pasted content contains whitespace.

Reviewed Changes

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

File Description
Plugins/Flow.Launcher.Plugin.WebSearch/SearchSourceSetting.xaml.cs Added event handlers to block space input and pasted whitespace.
Plugins/Flow.Launcher.Plugin.Explorer/Views/ActionKeywordSetting.xaml.cs Added event handlers to block space input and pasted whitespace.
Files not reviewed (2)
  • Plugins/Flow.Launcher.Plugin.Explorer/Views/ActionKeywordSetting.xaml: Language not supported
  • Plugins/Flow.Launcher.Plugin.WebSearch/SearchSourceSetting.xaml: Language not supported

@Jack251970 Jack251970 added this to the 1.20.0 milestone Apr 17, 2025
@Jack251970 Jack251970 changed the title Disabled space input in websearch and explorer Disabled space input in websearch and explorer & Improve API documents Apr 17, 2025
Copy link

@check-spelling-bot Report

🔴 Please review

See the 📂 files view, the 📜action log, or 📝 job summary for details.

❌ Errors Count
❌ forbidden-pattern 22
⚠️ non-alpha-in-dictionary 19

See ❌ Event descriptions for more information.

If the flagged items are 🤯 false positives

If items relate to a ...

  • binary file (or some other file you wouldn't want to check at all).

    Please add a file path to the excludes.txt file matching the containing file.

    File paths are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your files.

    ^ refers to the file's path from the root of the repository, so ^README\.md$ would exclude README.md (on whichever branch you're using).

  • well-formed pattern.

    If you can write a pattern that would match it,
    try adding it to the patterns.txt file.

    Patterns are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your lines.

    Note that patterns can't match multiline strings.

Copy link
Member

@Jack251970 Jack251970 left a comment

Choose a reason for hiding this comment

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

Good to me.

@Jack251970 Jack251970 added Dev branch only An issue or fix for the Dev branch build and removed 5 min review Dev branch only An issue or fix for the Dev branch build labels Apr 17, 2025
@onesounds onesounds merged commit a088e42 into Flow-Launcher:dev Apr 17, 2025
7 checks passed
@jjw24 jjw24 added Dev branch only An issue or fix for the Dev branch build and removed enhancement New feature or request labels Apr 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Dev branch only An issue or fix for the Dev branch build

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants