Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Input Smooth & Search delay #3350

Draft
wants to merge 23 commits into
base: dev
Choose a base branch
from

Conversation

Jack251970
Copy link
Contributor

@Jack251970 Jack251970 commented Mar 15, 2025

Delay time when typing to search

More details in #1677. Codes are edited from PowerToys Run project and they are all done and works well on FL.

Close #1677.

TODO

  • Support delay time for every plugin.
  • Use dictionary for search delay group like for action keyword.
  • No need to construct query for many times.
  • Add default value from plugin.json & Add document
  • Improved design in Unify Settings Panel Design & Fix JsonRPC Settings Empty Issue #3265.
  • Remove debug codes: // TODO: Remove debug codes.
  • Support no delay for some keywords.

Test

  • Turning On and off Search delay can work.
  • Context menu / History still work.
  • Plugin search delay can work.
  • If changing query text and search delay tasks is still running, those task will not be called.

@prlabeler prlabeler bot added the bug Something isn't working label Mar 15, 2025
@Jack251970 Jack251970 changed the title Search delay Input Smooth & Search delay Mar 15, 2025
Copy link

gitstream-cm bot commented Mar 15, 2025

🥷 Code experts: onesounds, Yusyuriv

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

See details

Flow.Launcher.Infrastructure/UserSettings/Settings.cs

Activity based on git-commit:

Jack251970
MAR 3 additions & 1 deletions
FEB 10 additions & 4 deletions
JAN 17 additions & 4 deletions
DEC 1 additions & 1 deletions
NOV
OCT

Knowledge based on git-blame:
onesounds: 24%
Yusyuriv: 13%

Flow.Launcher/Flow.Launcher.csproj

Activity based on git-commit:

Jack251970
MAR 1 additions & 1 deletions
FEB 11 additions & 10 deletions
JAN 4 additions & 2 deletions
DEC 4 additions & 0 deletions
NOV
OCT

Knowledge based on git-blame:
onesounds: 17%

Flow.Launcher/Languages/en.xaml

Activity based on git-commit:

Jack251970
MAR 6 additions & 3 deletions
FEB 10 additions & 7 deletions
JAN 1 additions & 0 deletions
DEC
NOV
OCT

Knowledge based on git-blame:
onesounds: 43%
Yusyuriv: 6%

Flow.Launcher/MainWindow.xaml.cs

Activity based on git-commit:

Jack251970
MAR 1 additions & 1 deletions
FEB 1 additions & 1 deletions
JAN
DEC 5 additions & 10 deletions
NOV
OCT

Knowledge based on git-blame:
onesounds: 33%
Yusyuriv: 1%

Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs

Activity based on git-commit:

Jack251970
MAR 22 additions & 23 deletions
FEB 17 additions & 8 deletions
JAN 33 additions & 3 deletions
DEC
NOV
OCT

Knowledge based on git-blame:
Yusyuriv: 83%

Flow.Launcher/SettingPages/Views/SettingsPaneGeneral.xaml

Activity based on git-commit:

Jack251970
MAR 8 additions & 8 deletions
FEB 1 additions & 1 deletions
JAN 8 additions & 1 deletions
DEC
NOV
OCT

Knowledge based on git-blame:
onesounds: 61%
Yusyuriv: 36%

Flow.Launcher/ViewModel/MainViewModel.cs

Activity based on git-commit:

Jack251970
MAR
FEB 63 additions & 21 deletions
JAN 17 additions & 21 deletions
DEC 59 additions & 63 deletions
NOV 39 additions & 15 deletions
OCT

Knowledge based on git-blame:
onesounds: 11%
Yusyuriv: 3%

To learn more about /:\ gitStream - Visit our Docs

This comment has been minimized.

Copy link
Contributor

coderabbitai bot commented Mar 15, 2025

📝 Walkthrough

Walkthrough

This pull request introduces delayed search functionality across the application. Two new properties are added to the settings for configuring delay behavior, and corresponding UI elements along with language strings are provided for user configuration. Reactive programming is integrated into the main window to delay query executions based on user input. Additionally, adjustments in the main view model now invoke queries explicitly via a dedicated method rather than through property setters. A new package reference for reactive programming is also included.

Changes

File(s) Change Summary
Flow.Launcher.Infrastructure/.../Settings.cs Added two properties: SearchQueryResultsWithDelay (bool, default false) and SearchInputDelay (int, default 120).
Flow.Launcher.csproj Added package reference: System.Reactive.Linq version 6.0.1.
Flow.Launcher/Languages/en.xaml Added four string resources (searchDelay, searchDelayToolTip, searchDelayTime, searchDelayTimeToolTip) for search delay configuration.
Flow.Launcher/MainWindow.xaml.cs Introduced reactive handling for search input with new methods (SetupSearchTextBoxReactiveness, QueryTextBox_TextChanged, etc.) and refactored progress bar and mouse event handling.
Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs Added property: SearchInputDelayRange (IEnumerable with predefined delay options).
Flow.Launcher/SettingPages/Views/SettingsPaneGeneral.xaml Added new UI cards featuring a ToggleSwitch and ComboBox for configuring search delay options.
Flow.Launcher/ViewModel/MainViewModel.cs Modified query flow by moving the query invocation from the QueryText setter to the ChangeQueryText method.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant QueryTextBox
    participant MainWindow
    participant ReactivePipeline
    participant SearchEngine

    User->>QueryTextBox: Types query text
    QueryTextBox->>MainWindow: Triggers TextChanged event
    MainWindow->>ReactivePipeline: Processes event with delay (Throttle)
    ReactivePipeline->>MainWindow: Emits delayed event
    MainWindow->>SearchEngine: Executes search query
Loading
sequenceDiagram
    participant User
    participant MainViewModel
    participant QueryEngine

    User->>MainViewModel: Updates query text via UI
    MainViewModel->>MainViewModel: Updates QueryText property
    MainViewModel->>QueryEngine: Calls Query() via ChangeQueryText method
Loading

Suggested labels

enhancement, kind/ui, 5 min review

Suggested reviewers

  • jjw24
  • taooceros

Poem

I'm a rabbit, hopping with delight,
Reading code changes deep into the night.
With delays in search, I skip and play,
Reactive flows lead my queries on their way.
In a garden of code, carrots and bytes unite,
Celebrating smooth hops in every highlight!
🥕🐇

Tip

⚡🧪 Multi-step agentic review comment chat (experimental)
  • We're introducing multi-step agentic chat in review comments. This experimental feature enhances review discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments.
    - To enable this feature, set early_access to true under in the settings.
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.

This comment has been minimized.

@Jack251970 Jack251970 mentioned this pull request Mar 15, 2025
2 tasks
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

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4bb8bff and a41356c.

📒 Files selected for processing (7)
  • Flow.Launcher.Infrastructure/UserSettings/Settings.cs (1 hunks)
  • Flow.Launcher/Flow.Launcher.csproj (1 hunks)
  • Flow.Launcher/Languages/en.xaml (1 hunks)
  • Flow.Launcher/MainWindow.xaml.cs (5 hunks)
  • Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs (1 hunks)
  • Flow.Launcher/SettingPages/Views/SettingsPaneGeneral.xaml (1 hunks)
  • Flow.Launcher/ViewModel/MainViewModel.cs (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: gitStream.cm
  • GitHub Check: gitStream.cm
🔇 Additional comments (11)
Flow.Launcher.Infrastructure/UserSettings/Settings.cs (1)

278-279: Good implementation of the search delay settings

The addition of these two settings properties is clean and fits well within the existing settings structure. The default values (delay disabled by default with a 120ms duration when enabled) are reasonable choices.

Flow.Launcher/Flow.Launcher.csproj (1)

107-107: Appropriate package addition for implementing reactive search behavior

Adding System.Reactive.Linq is a good choice for implementing the delayed search functionality, as it provides the tools needed for throttling input events.

Flow.Launcher/SettingPages/Views/SettingsPaneGeneral.xaml (1)

175-195: UI elements for search delay are well structured

The UI elements follow the application's design patterns with appropriate use of CardGroup and Cards. The toggle switch and ComboBox are correctly bound to the corresponding ViewModel properties, and the use of localized strings for labels and tooltips supports internationalization.

Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs (1)

153-156: Range of delay values is comprehensive

The delay range from 30ms to 300ms provides good flexibility for users to find their preferred responsiveness level. The 120ms default is a reasonable middle ground.

Flow.Launcher/Languages/en.xaml (1)

97-100: Well-formatted and clear string resources for search delay feature.

The added string resources for the new search delay functionality follow the existing naming conventions and provide helpful tooltips that clearly explain the feature's purpose and default values.

Flow.Launcher/ViewModel/MainViewModel.cs (2)

633-633: Explicit query call for better control of search execution.

This change separates setting the query text from executing the query, which enables the delayed search functionality. Now the query is explicitly triggered after setting the text rather than being automatically triggered by the property setter.


698-698: Ensures query is executed when selecting results with empty query text.

Adds an explicit call to Query() after clearing the query text, which maintains the expected behavior while supporting the new delayed search implementation.

Flow.Launcher/MainWindow.xaml.cs (4)

29-29: Added required namespace for reactive programming.

The System.Reactive.Linq namespace provides the essential extensions for implementing delayed search using the Observable pattern and Throttle operator.


71-71: Initializes search delay functionality when window loads.

Properly sets up the reactive behavior of the search text box based on user settings when the window is loaded.


209-265: Improved code organization for window visibility and progress bar handling.

The refactored property change handlers flatten the nested conditionals and improve the organization of the code, making it more readable while maintaining the same functionality.


864-932: Well-implemented search delay using reactive programming.

The search delay implementation:

  1. Uses the Observable pattern with Throttle operator to delay search execution
  2. Properly handles subscription lifecycle (creation and disposal)
  3. Maintains auto-complete functionality
  4. Separates concerns into well-defined methods
  5. Follows good reactive programming practices derived from PowerToys

The code effectively implements the search delay functionality requested in issue #1677.

@Jack251970 Jack251970 requested a review from onesounds March 16, 2025 00:51

This comment has been minimized.

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 (1)
Flow.Launcher/MainWindow.xaml.cs (1)

865-936: Well-implemented search delay functionality

The implementation of search delay using Reactive Extensions is well-structured and handles all edge cases:

  1. Properly cleans up previous subscriptions before creating new ones
  2. Uses appropriate throttling mechanism to delay search execution
  3. Correctly handles both delayed and immediate search modes
  4. Properly manages auto-complete text clearing
  5. Includes attribution to the original PowerToys implementation

Consider adding XML documentation to these methods to improve code maintainability for future developers.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a41356c and dc3f663.

📒 Files selected for processing (4)
  • Flow.Launcher.Infrastructure/UserSettings/Settings.cs (1 hunks)
  • Flow.Launcher/MainWindow.xaml.cs (6 hunks)
  • Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs (1 hunks)
  • Flow.Launcher/SettingPages/Views/SettingsPaneGeneral.xaml (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • Flow.Launcher/SettingPages/Views/SettingsPaneGeneral.xaml
  • Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: gitStream.cm
🔇 Additional comments (5)
Flow.Launcher.Infrastructure/UserSettings/Settings.cs (1)

278-288: New search delay functionality looks good

The implementation adds two well-designed properties to support search query delay functionality:

  1. SearchQueryResultsWithDelay - toggle to enable/disable the delay feature
  2. SearchInputDelay - configurable delay value (default 120ms)

The properties follow proper MVVM patterns with appropriate property change notification.

Flow.Launcher/MainWindow.xaml.cs (4)

29-29: Added Reactive Extensions dependency

Added the necessary dependency to implement reactive programming for the search delay functionality.


71-71: Appropriate initialization of search reactiveness

The search reactiveness setup is called during window loading, which is the correct place to initialize this functionality.


205-264: Improved property change handlers structure

The property change handlers for MainWindowVisibilityStatus and ProgressBarVisibility have been refactored to be more readable with better structure and explicit break statements.


300-302: Good handling of settings property change

The code properly responds to settings changes by setting up the search reactiveness when the delay toggle changes.

This comment has been minimized.

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 (1)
Flow.Launcher/MainWindow.xaml.cs (1)

926-926: Consider using case-insensitive comparison for autocomplete

The code uses StringComparison.Ordinal for autocomplete prefix matching, which is case-sensitive. For better user experience, consider using StringComparison.OrdinalIgnoreCase to match autocomplete suggestions regardless of case.

- return string.IsNullOrEmpty(queryText) || !autoCompleteText.StartsWith(queryText, StringComparison.Ordinal);
+ return string.IsNullOrEmpty(queryText) || !autoCompleteText.StartsWith(queryText, StringComparison.OrdinalIgnoreCase);
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between dc3f663 and e98b144.

📒 Files selected for processing (1)
  • Flow.Launcher/MainWindow.xaml.cs (6 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: gitStream.cm
🔇 Additional comments (6)
Flow.Launcher/MainWindow.xaml.cs (6)

29-29: Added Reactive Extensions dependency

The code now includes System.Reactive.Linq for implementing throttled search functionality.


198-199: Search reactiveness initialization added

Good addition of search reactiveness setup during window loading, which allows for delayed search functionality.


210-246: Improved window visibility handling

The code has been reorganized for better readability while maintaining the same functionality. The conditional structure is now clearer with better indentation.


249-265: Refactored progress bar visibility logic

The progress bar visibility handling has been improved with clearer conditional statements and better structure.


301-303: Added handler for search delay setting changes

Good implementation of a property change handler that reconfigures search reactiveness when the user toggles the delay setting.


889-889:

✅ Verification successful

Verify search delay configuration

The throttle delay is set from user settings, which is a good approach for configurability.


🌐 Web query:

What is a good throttle delay for search input in UI applications?

💡 Result:

Throttling delays for search inputs in UI applications typically range between 200-500 milliseconds, but the optimal choice depends on balancing responsiveness and performance. Here's a breakdown of key considerations:

Throttle vs. Debounce Preference

  • Debouncing is generally preferred for search inputs[1][5][9], as it waits until typing stops completely (e.g., 300ms pause) before executing, reducing unnecessary API calls.
  • Throttling forces regular execution intervals, which can feel more responsive but might generate more network traffic than needed[2][3].

When Using Throttle

For scenarios where immediate feedback is critical:

  • 200-300ms: Provides near real-time updates for short queries
  • 400-500ms: Better for complex searches or slower backends

Performance Considerations

Delay Pros Cons
200ms Feels instantaneous High server load
300ms Balanced UX Slight lag
500ms Server-friendly Noticeable delay

Implementation Example

const throttleSearch = throttle((query) => {
  // API call here
}, 300); // Adjust delay based on testing

inputElement.addEventListener('input', (e) => {
  throttleSearch(e.target.value);
});

In practice, most teams opt for debouncing with 300ms delay for search inputs[5][7][9], reserving throttling for scroll/resize handlers or rate-limited APIs[4][6]. Always test with real users to find the sweet spot between perceived performance and system load[8].

Citations:


Search Delay Configuration Verified

The current implementation sets the throttle delay from user settings, which is a flexible approach. Based on industry guidance, a throttle delay in the range of 200–500 ms is generally ideal for search inputs. As a best practice, please ensure that the default value in _settings.SearchInputDelay falls within this range (around 300 ms is common). Additionally, consider whether a debouncing strategy might better suit your use case if minimizing unnecessary API calls is a priority.

@@ -631,6 +630,7 @@ public void ChangeQueryText(string queryText, bool isReQuery = false)
{
// re-query is done in QueryText's setter method
QueryText = queryText;
Query();
Copy link
Member

Choose a reason for hiding this comment

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

why do we need this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

From original codes, when QueryText is changed, it will call Query().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

And I remove Query() in QueryText setter, so we need to manually call it.

Copy link
Member

Choose a reason for hiding this comment

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

Why do we do that?

Copy link
Contributor Author

@Jack251970 Jack251970 Mar 16, 2025

Choose a reason for hiding this comment

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

QueryText is a property used by others functions in MainViewModel like auto complete text, backspace event, change query text event, etc. So we need to update it once users input.

Query is a function to load results and we can delay them.

@Jack251970 Jack251970 added this to the Future milestone Mar 16, 2025
@Jack251970 Jack251970 marked this pull request as draft March 16, 2025 04:49

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

Copy link

@check-spelling-bot Report

🔴 Please review

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

❌ Errors Count
❌ forbidden-pattern 24
⚠️ ignored-expect-variant 1
⚠️ non-alpha-in-dictionary 19

See ❌ Event descriptions for more information.

Forbidden patterns 🙅 (1)

In order to address this, you could change the content to not match the forbidden patterns (comments before forbidden patterns may help explain why they're forbidden), add patterns for acceptable instances, or adjust the forbidden patterns themselves.

These forbidden patterns matched content:

s.b. workaround(s)

\bwork[- ]arounds?\b
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
10 min review bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants