Skip to content

Fix ArgumentException when editing a disabled Explorer action keyword#4339

Merged
Jack251970 merged 2 commits into
devfrom
copilot/fix-folder-search-action
Mar 10, 2026
Merged

Fix ArgumentException when editing a disabled Explorer action keyword#4339
Jack251970 merged 2 commits into
devfrom
copilot/fix-folder-search-action

Conversation

@Jack251970
Copy link
Copy Markdown
Member

@Jack251970 Jack251970 commented Mar 10, 2026

Resolve #4289


Summary by cubic

Summary of changes

Fixes an ArgumentException when editing a disabled action keyword in Flow.Launcher.Plugin.Explorer and prevents a potential NullReferenceException. The Action Keyword dialog now updates as you type and only auto-enables when the keyword actually changes.

  • Changed logic/behavior:

    • In SettingsViewModel.EditActionKeyword: handle the (disabled → disabled) case by doing nothing instead of throwing, allowing text edits on a disabled keyword without re-registering it.
    • In Settings.GetActiveActionKeywords: return an empty dictionary when the input string is null/empty (was returning null), avoiding null checks and NullReferenceException risks.
    • In ActionKeywordSetting.ActionKeyword setter: only set KeywordEnabled = true when the value actually changes, preventing unintended auto-enable during no-op sets.
    • In ActionKeywordSetting constructor: initialize backing fields directly to avoid triggering auto-enable during dialog initialization.
    • In ActionKeywordSetting.xaml: TextBox binding uses UpdateSourceTrigger=PropertyChanged so the model updates as the user types, making the enable checkbox reflect changes immediately.
  • New logic/behavior added:

    • Live text updates in the dialog with immediate checkbox feedback while typing.
    • Graceful no-op when editing the text of a disabled keyword that remains disabled.
  • Removed logic/behavior:

    • Throwing ArgumentException for the (false, false) edit case.
    • Returning null from GetActiveActionKeywords on empty input.
  • Memory usage impact:

    • Negligible. Returning an empty dictionary instead of null adds a tiny allocation only when the input is empty; no sustained memory growth.
  • Security risks:

    • None. Changes are confined to UI logic and in-memory state handling.
  • Unit tests:

    • No new unit tests added.

Written for commit 531b452. Summary will update on new commits.

Copilot AI and others added 2 commits March 10, 2026 05:19
…lugin

- Fix (false, false) case in EditActionKeyword to break gracefully instead
  of throwing ArgumentException. This handles the valid scenario where the
  user changes a disabled keyword's text but keeps it disabled.
- Fix GetActiveActionKeywords to return an empty dictionary instead of null
  when actionKeywordStr is null/empty, preventing NullReferenceException.
- Fix ActionKeyword setter to only auto-enable when the value actually
  changes, preventing unintended side-effects during construction.
- Initialize ActionKeywordSetting backing fields directly in constructor to
  avoid the auto-enable triggering during initialization.
- Change TextBox binding to UpdateSourceTrigger=PropertyChanged so the
  checkbox auto-enables as the user types (before they click the checkbox),
  fixing the checkbox toggle issue caused by LostFocus timing.

Co-authored-by: Jack251970 <53996452+Jack251970@users.noreply.github.com>
Copilot AI review requested due to automatic review settings March 10, 2026 05:42
@prlabeler prlabeler Bot added the bug Something isn't working label Mar 10, 2026
@github-actions github-actions Bot added this to the 2.2.0 milestone Mar 10, 2026
@gitstream-cm
Copy link
Copy Markdown

gitstream-cm Bot commented Mar 10, 2026

🥷 Code experts: no user but you matched threshold 10

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

See details

Plugins/Flow.Launcher.Plugin.Explorer/Settings.cs

Activity based on git-commit:

Jack251970
MAR
FEB
JAN
DEC
NOV
OCT

Knowledge based on git-blame:
Jack251970: 82%

Plugins/Flow.Launcher.Plugin.Explorer/ViewModels/SettingsViewModel.cs

Activity based on git-commit:

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

Knowledge based on git-blame:
Jack251970: 99%

Plugins/Flow.Launcher.Plugin.Explorer/Views/ActionKeywordSetting.xaml

Activity based on git-commit:

Jack251970
MAR
FEB
JAN
DEC
NOV
OCT

Knowledge based on git-blame:
Jack251970: 100%

Plugins/Flow.Launcher.Plugin.Explorer/Views/ActionKeywordSetting.xaml.cs

Activity based on git-commit:

Jack251970
MAR
FEB
JAN
DEC
NOV
OCT

Knowledge based on git-blame:
Jack251970: 100%

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

@gitstream-cm
Copy link
Copy Markdown

gitstream-cm Bot commented Mar 10, 2026

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

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 10, 2026

📝 Walkthrough

Walkthrough

Fixed a bug where editing a disabled action keyword throws an exception by replacing the error-throwing logic with a no-op path. Changes also include improved null-handling in keyword retrieval, updated binding behavior for real-time property updates, and refactored property initialization to avoid unintended side effects.

Changes

Cohort / File(s) Summary
Null-Safety in Keyword Retrieval
Plugins/Flow.Launcher.Plugin.Explorer/Settings.cs
Modified GetActiveActionKeywords to return an empty dictionary instead of null when input is null or empty, improving null-safety.
Action Keyword Editing Flow
Plugins/Flow.Launcher.Plugin.Explorer/ViewModels/SettingsViewModel.cs, Plugins/Flow.Launcher.Plugin.Explorer/Views/ActionKeywordSetting.xaml, Plugins/Flow.Launcher.Plugin.Explorer/Views/ActionKeywordSetting.xaml.cs
Fixed exception thrown when editing a disabled action keyword by replacing error logic with no-op handling. Added real-time binding updates via UpdateSourceTrigger=PropertyChanged. Refactored property setter to conditionally enable KeywordEnabled only when value actually changes, and updated constructor to initialize backing fields directly to avoid unintended side effects.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • jjw24
  • onesounds
  • taooceros
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and specifically summarizes the main change: fixing an ArgumentException when editing a disabled Explorer action keyword, which directly matches the changeset's primary objective.
Linked Issues check ✅ Passed All changes in the PR directly address the linked issue #4289: handling the (false, false) case in EditActionKeyword prevents the ArgumentException, returning empty dictionary prevents NullReferenceException, and UpdateSourceTrigger=PropertyChanged provides immediate UI feedback.
Out of Scope Changes check ✅ Passed All changes are directly related to the issue objective of fixing the ArgumentException and improving action keyword editing behavior; no unrelated or out-of-scope modifications detected.
Description check ✅ Passed The PR description clearly explains the bug being fixed and details all changes made across multiple files to address issue #4289.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch copilot/fix-folder-search-action

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
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 4 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="Plugins/Flow.Launcher.Plugin.Explorer/Views/ActionKeywordSetting.xaml">

<violation number="1" location="Plugins/Flow.Launcher.Plugin.Explorer/Views/ActionKeywordSetting.xaml:85">
P2: Updating the binding source on every keystroke can unintentionally enable a disabled keyword even when the final text is unchanged.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Copy link
Copy Markdown
Contributor

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 fixes an ArgumentException that occurred when editing a disabled Explorer action keyword (e.g., Folder Search). The root cause was that the ActionKeywordSetting dialog's ActionKeyword property setter unconditionally set KeywordEnabled = true whenever the property was written to — including during constructor initialization — and a (false, false) case in the switch statement was treated as unreachable when it was actually valid.

Changes:

  • Fixed the ActionKeywordSetting constructor to initialize backing fields directly instead of going through property setters, avoiding the auto-enable side effect during initialization.
  • Made the ActionKeyword property setter only auto-enable the keyword when the value actually changes (via SetProperty return value), and added UpdateSourceTrigger=PropertyChanged to the XAML binding for immediate updates on keystroke.
  • Replaced the throw ArgumentException in the (false, false) case with a break, since changing keyword text while keeping it disabled is a valid operation; also changed GetActiveActionKeywords to return an empty dictionary instead of null for defensive null-safety.

Reviewed changes

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

File Description
Plugins/Flow.Launcher.Plugin.Explorer/Views/ActionKeywordSetting.xaml.cs Initialize backing fields directly in constructor; only auto-enable when keyword text actually changes
Plugins/Flow.Launcher.Plugin.Explorer/Views/ActionKeywordSetting.xaml Add UpdateSourceTrigger=PropertyChanged to ActionKeyword textbox binding
Plugins/Flow.Launcher.Plugin.Explorer/ViewModels/SettingsViewModel.cs Handle (false, false) case with a no-op break instead of throwing
Plugins/Flow.Launcher.Plugin.Explorer/Settings.cs Return empty dictionary instead of null from GetActiveActionKeywords

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

{
var result = new Dictionary<ActionKeyword, string>();
if (string.IsNullOrEmpty(actionKeywordStr)) return null;
if (string.IsNullOrEmpty(actionKeywordStr)) return result;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Any specific resaon for changing or it's about code style?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Return a non-null value to enhance code robustness

@Jack251970 Jack251970 merged commit e8353f7 into dev Mar 10, 2026
27 checks passed
@Jack251970 Jack251970 deleted the copilot/fix-folder-search-action branch March 10, 2026 15:29
@jjw24 jjw24 modified the milestones: 2.2.0, 2.1.2 May 9, 2026
jjw24 pushed a commit that referenced this pull request May 9, 2026
…-action

Fix ArgumentException when editing a disabled Explorer action keyword
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: Exception when setting Folder Search action in Explorer plugin

5 participants