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

fuzzy search on all tabs #1288

Open
Raialbe opened this issue Jan 11, 2020 · 7 comments
Open

fuzzy search on all tabs #1288

Raialbe opened this issue Jan 11, 2020 · 7 comments
Labels
feature New feature request

Comments

@Raialbe
Copy link

Raialbe commented Jan 11, 2020

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

it would be extremely useful to have a fuzzy search system in copyq. I usually search for code snippet or other stuff with the search function, right now however this function searches only on the current tab. A way to do real fuzzy search on all the tabs at the same time would be incredibly useful for when one has many different tabs in which to search for the item.
In my specific use case i have many python snippets that are on different tabs related to different libraries. If i would like to search for an item that has 'np' in it (an abbreviation for a very popular python library) i would have to click on each tab to look for the appropriate snippet of code.

Describe the solution you'd like
it would be optimal to have an option to change the kind of search in the preferences, one will keep the current system while the other will use a system that when fuzzy searching will filter the items from all the sub-tabs of the current tab for the searched string.

Describe alternatives you've considered
I found and tried to use the copyq command that the author of this library released online, this however is extremely clunky to use with the necessity of calling it with a key combination ( instead of just starting to type) and having the results in a ulterior tab. Overall the most fundamental problem of the command is the inability to make the search fuzzy and real-time (you have to send the query by hitting return), this strongly limits the ability of using copyq as a snippet manager.

@Raialbe Raialbe added the feature New feature request label Jan 11, 2020
@axonasif
Copy link
Contributor

I was looking for the same thing 😄

@axonasif
Copy link
Contributor

Wait hey.
We've an option.
Check this out, simply import it in your commands menu.
https://github.com/hluk/copyq-commands/blob/master/Application/search-all-tabs.ini

@axonasif
Copy link
Contributor

Hmm, but it sadly doesn't work @hluk
image

@hluk
Copy link
Owner

hluk commented May 14, 2021

@axonasif Oh, nice find. Internal exceptions are not handled well in the new scripting engine. There is some new functionality in Qt 5.12 and greater which could help - I will try to fix that in the app.

For now you can use modified version of the command:

[Command]
Command="
    copyq:
    // Name for tab for storing matching items.
    var search_tab_name = \"Search\"

    // Returns true iff item at index matches regex.
    function item_matches(item_index, re)
    {
        var item = getitem(j)
        var note = str(item[mimeItemNotes])
        var text = str(item[mimeText])
        return text && (re.test(text) || re.test(note))
    }

    // Ask for search expression.
    var match = dialog(\"Search\")
    if (!match)
      abort()
    var re = new RegExp(match,'i') // 'i' case-insensitive

    // Clear tab with results.
    if ( tab().indexOf(search_tab_name) != -1 )
      removeTab(search_tab_name)

    // Search all tabs.
    var tab_names = tab()
    for (var i in tab_names) {
      var tab_name = tab_names[i]
      tab(tab_name)
      var item_count = count()

      // Search all items in tab.
      for (var j = 0; j < item_count; ++j) {
        // Add matching item to tab with results.
        if (item_matches(j, re)) {
          var item = getItem(j)
          tab(search_tab_name)
          setItem(j, item)
          tab(tab_name)
        }
      }
    }

    show(search_tab_name)"
Icon=\xf002
InMenu=true
Name=Search All Tabs
Shortcut=ctrl+shift+f

@axonasif
Copy link
Contributor

@axonasif Oh, nice find. Internal exceptions are not handled well in the new scripting engine. There is some new functionality in Qt 5.12 and greater which could help - I will try to fix that in the app.

For now you can use modified version of the command:

[Command]
Command="
    copyq:
    // Name for tab for storing matching items.
    var search_tab_name = \"Search\"

    // Returns true iff item at index matches regex.
    function item_matches(item_index, re)
    {
        var item = getitem(j)
        var note = str(item[mimeItemNotes])
        var text = str(item[mimeText])
        return text && (re.test(text) || re.test(note))
    }

    // Ask for search expression.
    var match = dialog(\"Search\")
    if (!match)
      abort()
    var re = new RegExp(match,'i') // 'i' case-insensitive

    // Clear tab with results.
    if ( tab().indexOf(search_tab_name) != -1 )
      removeTab(search_tab_name)

    // Search all tabs.
    var tab_names = tab()
    for (var i in tab_names) {
      var tab_name = tab_names[i]
      tab(tab_name)
      var item_count = count()

      // Search all items in tab.
      for (var j = 0; j < item_count; ++j) {
        // Add matching item to tab with results.
        if (item_matches(j, re)) {
          var item = getItem(j)
          tab(search_tab_name)
          setItem(j, item)
          tab(tab_name)
        }
      }
    }

    show(search_tab_name)"
Icon=\xf002
InMenu=true
Name=Search All Tabs
Shortcut=ctrl+shift+f

Works!
It would be really nice if this was a built-in feature for the default search bar with live updates.
Thanks.

@AllanLeanderRostockHansen
Copy link

AllanLeanderRostockHansen commented Mar 28, 2022

I would also really like an option to fuzzy search across all clips.
I have no idea about how much work it requires, but would it be possible to plug in an existing fuzzy searcher for the normal search field, such as fzy (a library and commandline tool written i C), or some of it's alternatives e.g. skim (written in Rust, also a library and commandline tool) or fzf (the most known fuzzy matcher, but AFAIK it isn't intended to be used as a library).

Oh, and thanks for providing this software BTW, it's hands down the best clipboard manager I've ever used.

@vysmaty
Copy link

vysmaty commented Feb 5, 2023

@axonasif Oh, nice find. Internal exceptions are not handled well in the new scripting engine. There is some new functionality in Qt 5.12 and greater which could help - I will try to fix that in the app.

For now you can use modified version of the command:

[Command]
Command="
    copyq:
    // Name for tab for storing matching items.
    var search_tab_name = \"Search\"

    // Returns true iff item at index matches regex.
    function item_matches(item_index, re)
    {
        var item = getitem(j)
        var note = str(item[mimeItemNotes])
        var text = str(item[mimeText])
        return text && (re.test(text) || re.test(note))
    }

    // Ask for search expression.
    var match = dialog(\"Search\")
    if (!match)
      abort()
    var re = new RegExp(match,'i') // 'i' case-insensitive

    // Clear tab with results.
    if ( tab().indexOf(search_tab_name) != -1 )
      removeTab(search_tab_name)

    // Search all tabs.
    var tab_names = tab()
    for (var i in tab_names) {
      var tab_name = tab_names[i]
      tab(tab_name)
      var item_count = count()

      // Search all items in tab.
      for (var j = 0; j < item_count; ++j) {
        // Add matching item to tab with results.
        if (item_matches(j, re)) {
          var item = getItem(j)
          tab(search_tab_name)
          setItem(j, item)
          tab(tab_name)
        }
      }
    }

    show(search_tab_name)"
Icon=\xf002
InMenu=true
Name=Search All Tabs
Shortcut=ctrl+shift+f

Would it be possible to search all notes as well?

Thank you for the best app for the clipboard!

@hluk hluk added incomplete Missing information about the problem and removed incomplete Missing information about the problem labels Sep 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature request
Projects
None yet
Development

No branches or pull requests

5 participants