Skip to content

[FEATURE] Fuzzy search or a hook to validate  #15

@Just-Moh-it

Description

@Just-Moh-it

Is your feature request related to a problem? Please describe.

Currently, kmenu only supports exact searches through and keyword detection. However, when users type something like "bercel" instead of "vercel" (which is like so common that the people over at vercel bought the domain), so an existing, lightweight algorithm for fuzzy search using JavaScript would be awesome. Also, a way to control the strictness of the match, like most fuzzy search algoithms give on a 0-1 float number basis, would be an awesome addition.

Also, since kmenu can be used in commercial software as well, where performance is critical and users would love to use their own in-house algorithms for text search, a custom search logic (preferably through hooks) would be cool to have.

Describe the solution you'd like

  1. For the built-in fuzzy search, a config option, like fuzziness: int, that has possible values from 0-1 and 0 by default, which means only exact searches would be matched.

  2. For the out-sourced matching logic, since users could already get the text from the input box in the kmenu, but only an option to conditionally render blocks is missing, a clever and out-of-the-box solution would be to have a variable like filterAutomatically: boolean or something similar, and when that's disabled, any text in the search bar wouldn't affect the command menu at all (basically like disconnecting the input-box from the command menu), and users could conditionally render the commands, like

// Get the input from the kmenu textbox
const { input } = useKmenu();

const config = { filterAutomatically: false };

const allCommands = [
  {
    name: "help",
    description: "Displays this message.",
  },
];

const main = [
  {
    category: "main",
    // Conditionally render the commands
    commands: allCommands.filter(
      command.keywords.include(input) || commands.name.include(input)
    ),
  },
];

Describe alternatives you've considered

The same as above, but haven't been able to turn off the searchAutomatically parameter yet.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions