Skip to content

Conversation

@renatomen
Copy link
Contributor

Problem

Bug: Project autosuggestion filter settings (tags, folders, properties) were incorrectly applied to custom field file/link suggestions when users typed [[ in custom fields.
Bug: #905

Bug: When I click on "Add to Project" button in the Task Edit modal, the project suggestions do not return the same results as the Task Creation modal.

While the Task Creation modal correctly returns results filtered by the plugin's "project auto-suggest" settings respecting hierarchical tags and exclusion settings, the "Task Edit" modal still filters based on simple tags.
Bug: #907

Impact: Users could not select files that didn't match their project filter criteria when using wikilink suggestions in custom fields, even though custom fields should show all vault files.

Root Cause

  1. FileSuggestHelper always applied project filters to ALL callers, regardless of context
  2. ProjectSelectModal (used by Task Edit modal) used simple tag matching instead of hierarchical matching with exclusion support

This caused:

  • Custom field wikilink suggestions to only show filtered project files instead of all vault files
  • Task Edit modal to show fewer projects than Task Creation modal (missing files that matched via hierarchical tags)

Solution

Made filtering opt-in and generic:

  • Helper is now filter-agnostic
  • Callers explicitly decide which filters to apply
  • Both modals use consistent hierarchical tag matching
  • Future-proof for custom field-specific filters

Changes by File

src/suggest/FileSuggestHelper.ts

What changed: Added generic FileFilterConfig interface and made filtering optional

Why:

  • Previously always read from plugin.settings.projectAutosuggest and applied filters to all callers
  • Now accepts optional filterConfig parameter - undefined means no filtering
  • Generic interface not tied to "project" concept, reusable for future custom field filters

Key change:

// Before: Always applied project filters
const requiredTags = plugin.settings?.projectAutosuggest?.requiredTags ?? [];

// After: Only apply if filterConfig provided
const requiredTags = filterConfig?.requiredTags ?? [];

src/modals/TaskCreationModal.ts

What changed: Explicitly passes project filter config to FileSuggestHelper

Why:

  • Project field (+ trigger) should filter by project settings
  • Makes intent explicit: "I want project filtering"
  • No longer relies on helper's default behavior

Key change:

// Explicitly pass project filter configuration
const list = await FileSuggestHelper.suggest(
    this.plugin,
    queryAfterTrigger,
    20,
    this.plugin.settings.projectAutosuggest  // Explicit filter config
);

src/modals/TaskModal.ts

What changed: Calls FileSuggestHelper without filterConfig for custom fields

Why:

  • Custom fields ([[ trigger) should show ALL vault files
  • No filterConfig parameter = no filtering
  • Clear intent: "Show me everything"

Key change:

// No filterConfig = shows all files
const list = await FileSuggestHelper.suggest(this.plugin, partial);

src/modals/ProjectSelectModal.ts

What changed: Updated tag filtering to use FilterUtils.matchesTagConditions()

Why:

  • Previously used simple .some() matching (exact matches only)
  • Now uses same hierarchical tag matching as FileSuggestHelper
  • Supports exclusion patterns (tags with - prefix)
  • Consistent behavior across Task Creation and Task Edit modals

Key change:

// Before: Simple exact matching
const hasRequiredTag = requiredTags.some((reqTag) => allTags.includes(reqTag));

// After: Hierarchical matching with exclusion support
if (!FilterUtils.matchesTagConditions(allTags, requiredTags)) {
    return false;
}

tests/unit/suggest/FileSuggestHelper.test.ts

What changed: Added 12 unit tests covering filtering behavior

Why:

  • Verify no filterConfig returns all files
  • Verify filterConfig applies filters correctly
  • Test tag, folder, and property filtering independently and combined
  • Ensure query matching works regardless of filter settings

Test coverage:

  • Filter configuration (with/without filterConfig)
  • Tag filtering (filtered vs unfiltered)
  • Folder filtering (filtered vs unfiltered)
  • Property filtering (filtered vs unfiltered)
  • Multiple filters combined
  • Query matching

- Add generic FileFilterConfig interface for flexible filtering
- Update FileSuggestHelper.suggest() to accept optional filterConfig parameter
- No filterConfig = no filtering (returns all files)
- TaskCreationModal explicitly passes project filter config for project field
- TaskModal passes no filterConfig for custom fields (shows all files)
- Update ProjectSelectModal to use FilterUtils.matchesTagConditions for consistent tag matching
- Add unit tests for FileSuggestHelper filtering behavior

Root cause: FileSuggestHelper always applied project filters to ALL callers,
breaking custom field wikilink suggestions which should show all vault files.
ProjectSelectModal used simple tag matching instead of hierarchical matching.

Solution: Made filtering opt-in and generic. Helper is now filter-agnostic.
Callers decide which filters to apply. Both modals now use consistent tag matching.
Future-proof for custom field filters.
@renatomen renatomen marked this pull request as ready for review October 12, 2025 01:58
@renatomen renatomen changed the title Fix: Prevent project filters from affecting custom field suggestions / Inconistent Project Suggestions (Bugs #905, #907) fix: Prevent project filters from affecting custom field suggestions / Inconistent Project Suggestions (Bugs #905, #907) Oct 12, 2025
@callumalpass callumalpass merged commit b9c09be into callumalpass:main Oct 12, 2025
4 checks passed
@callumalpass
Copy link
Owner

Thank you @renatomen ! Much appreciated!

callumalpass pushed a commit that referenced this pull request Oct 25, 2025
…908)

- Add generic FileFilterConfig interface for flexible filtering
- Update FileSuggestHelper.suggest() to accept optional filterConfig parameter
- No filterConfig = no filtering (returns all files)
- TaskCreationModal explicitly passes project filter config for project field
- TaskModal passes no filterConfig for custom fields (shows all files)
- Update ProjectSelectModal to use FilterUtils.matchesTagConditions for consistent tag matching
- Add unit tests for FileSuggestHelper filtering behavior

Root cause: FileSuggestHelper always applied project filters to ALL callers,
breaking custom field wikilink suggestions which should show all vault files.
ProjectSelectModal used simple tag matching instead of hierarchical matching.

Solution: Made filtering opt-in and generic. Helper is now filter-agnostic.
Callers decide which filters to apply. Both modals now use consistent tag matching.
Future-proof for custom field filters.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants