Dear all,
How would one be able to create a dialog window to search through the entire clipboard history, find an entry based on the item's content and paste it into the current selection?
I imagine a window like this:

Why not use the built-in search?
Maybe I just haven't found it yet. :-)
How do I use it?
Let's say I am inside this composing text box and want to paste something from my clipboard history.
How would I do that without having to open CopyQ's window?
You need to open main window to use the built-in search. Why is that a problem? Why is it better to open simple dialog for searching?
Here is the command just to prove it's possible :).
[Command]
Command="
copyq:
// Read search history tab.
tab('Search')
var history = ['', '']
for (var i = 0; i < count(); ++i) {
var text = str(read(i))
history.push(text)
}
// Ask user for search expression (case insensitive).
var what = dialog('.title', 'Search and Paste', 'Search', history)
if (!what)
abort()
add(what) // Store new search to history tab.
what = str(what).toLowerCase()
// Tab to search.
var tab_name = config('clipboard_tab')
if (!tab_name)
tab_name = tab()[0]
tab(tab_name)
// Search and paste if found.
for (var i = 0; i < count(); ++i) {
var text = str(read(i))
if (text.toLowerCase().indexOf(what) != -1) {
copy(text)
paste()
abort()
}
}
popup(
'Search failed!',
'Item containing \"' + what + '\" was not found.')"
GlobalShortcut=ctrl+shift+f
Icon=\xf002
Name=Search and Paste
Wow, this is great! :-)
Thank you so much.
One question:
Example content from my clipboard history: {"bonus":60}
If I run the command and begin to type bonus, can it auto-complete to match the content of my history?
This would be useful, for instance, if I have two entries {"bonus":60} and {"bonus":120}, and want to distinguish which of the two to import.
It will autocomplete previously searched text but not an item text. For better search functionality you have to search in main window.
OK! Then I am good for now. Thanks! :-)
I found a problem.
It pastes all content as lower case. :-(
Oops. I fixed the command above.
Works! Oh, this is so great. :-)
Hey! Here is improved command that opens selection dialog if search matches multiple items.
[Command]
Command="
copyq:
var title = 'Search and Paste'
// Read search history tab.
tab('Search')
var history = ['', '']
for (var i = 0; i < count(); ++i) {
var text = str(read(i))
history.push(text)
}
// Ask user for search expression (case insensitive).
var what = dialog(
'.title', title,
'Search', history)
if (!what)
abort()
add(what) // Store new search to history tab.
what = str(what).toLowerCase()
// Tab to search.
var tab_name = config('clipboard_tab')
if (!tab_name)
tab_name = tab()[0]
tab(tab_name)
// Search items.
var matches = []
for (var i = 0; i < count(); ++i) {
var text = str(read(i))
if (text.toLowerCase().indexOf(what) != -1)
matches.push(text)
}
// Nothing found?
if (matches.length == 0) {
popup(
'Search failed!',
'Item containing \"' + what + '\" was not found.')
abort()
}
var match = matches[0]
// If multiple items matches, show selection dialog.
if (matches.length > 1) {
matches.unshift(matches[0])
match = dialog(
'.title', title,
'.label', 'Multiple items were found. Select one to paste.',
'', matches)
if (!match)
abort()
}
// Paste matched item.
copy(match)
paste()"
GlobalShortcut=ctrl+shift+f
Icon=\xf002
Name=Search and Paste

Can you resize or maximize the second dialog?
BTW, I fixed the dialog size today and added list widget for custom dialogs.
Can you resize or maximize the second dialog?
No. :-(
BTW, I fixed the dialog size today and added list widget for custom dialogs.
How do I get this update? You refer to CopyQ or just the command above?
New version for Ubuntu 16.04 is available here.
Wow, that one fixed it and your new selection dropdown menu is just amazing! :-)
...and here is version of the command for new beta version with list of multiple matches instead of simple combo box.
[Command]
Command="
copyq:
var title = 'Search and Paste'
// Read search history tab.
tab('Search')
var history = ['', '']
for (var i = 0; i < count(); ++i) {
var text = str(read(i))
history.push(text)
}
// Ask user for search expression (case insensitive).
var what = dialog(
'.title', title,
'Search', history)
if (!what)
abort()
add(what) // Store new search to history tab.
what = str(what).toLowerCase()
// Tab to search.
var tab_name = config('clipboard_tab')
if (!tab_name)
tab_name = tab()[0]
tab(tab_name)
// Search items.
var matches = []
for (var i = 0; i < count(); ++i) {
var text = str(read(i))
if (text.toLowerCase().indexOf(what) != -1)
matches.push(text)
}
// Nothing found?
if (matches.length == 0) {
popup(
'Search failed!',
'Item containing \"' + what + '\" was not found.')
abort()
}
var match = matches[0]
// If multiple items matches, show selection dialog.
if (matches.length > 1) {
var i = dialog(
'.title', title,
'.label', matches.length + ' items were found. Select one to paste.',
'.style', 'QListWidget{font-family:mono}',
'.list:', matches)
if (!i)
abort()
match = matches[i]
}
// Paste matched item.
copy(match)
paste()"
GlobalShortcut=ctrl+shift+f
Icon=\xf002
Name=Search and Paste
I think typing a text in the list should select the first item starting with the typed text.
Yep, this is perfect! Thanks. :-)
Thanks for your support (as always)! :)
I'm glad I finally got to improve the dialog() function. I'll try to simplify setting icon for the dialogs too -- right now it can be set only from a file (e.g. '/usr/share/icons/gnome/32x32/actions/search.png').
https://www.youtube.com/watch?v=_9Tc-u6IpJk&feature=youtu.be
That's software worth supporting. :-)
Nice! Amazing indeed. :) Thanks!
The script is nice, however for me it pastes the string 'undefined' if there are more than one results.
My version is: 2.7.1.r58
@Negirno You need the beta version mentioned above.
You can use the command with CopyQ v2.8.2.
Most helpful comment
...and here is version of the command for new beta version with list of multiple matches instead of simple combo box.
I think typing a text in the list should select the first item starting with the typed text.