'Cycle Items', but with the ability to paste row 0 and cancel
- Dominant language
- C++
- Stars
- 12.3k
- Forks
- 593
- Avg merge
- 2d 8h
- Merged PRs (30d)
- 9
Description
I'm working on a modification to the [Cycle Items](https://github.com/hluk/copyq-commands/blob/master/Global/cycle-items.ini) command.
Currently the behaviour of Cycle Items is:
- Focus the window on first keypress
- Cycle to the next rows on subsequent keypresses
- Paste on key release release, but _only if the user has moved the row at least one time_. If the key is released when no subsequent keypresses have been processed, the window stays focused and nothing is pasted.
I made a modification to Cycle Items so that the first row is pasted even if the user hasn't made any subsequent keypresses. But there's an issue, I have no way to 'cancel' pasting if I change my mind after focusing the window. I'm looking for a way to listen for a particular keypress that blocks any paste from happening, whether the selected row has changed or not.
My current implementation is below. I also have an equivalent `Cycle Items Backward` command that uses `const row = rows.length > 0 ? (rows[0] - 1) % length() : 0;` instead.
```
[Command]
Command="
copyq:
// Pops up the main window (if the shortcut is pressed once), cycles through items
// (if the shortcut is pressed again) and pastes selected item when the shortcut
// is released.
const selectedRowOption = 'cycleItemsSelectedRow';
const selectedTabOption = 'cycleItemsSelectedTab';
if (focused()) {
// When the window is focused, the command should cycle through the rows
const sel = ItemSelection().current();
const rows = sel.rows();
const row = rows.length > 0 ? (rows[0] + 1) % length() : 0;
settings(selectedRowOption, row);
settings(selectedTabOption, selectedTab());
selectItems(row);
} else {
// If the window isn't open, default to selecting the first row
settings(selectedRowOption, 0);
selectItems(0);
show();
// Then wait at most 20 milliseconds for key release
while (queryKeyboardModifiers().length > 0) {
sleep(20);
}
const row = settings(selectedRowOption)
settings(selectedRowOption, row);
settings(selectedTabOption, selectedTab());
selectItems(row);
tab(settings(selectedTabOption));
select(row);
hide();
paste();
}"
GlobalShortcut="ctrl+alt+y"
Icon=\xf1b8
InMenu=true
IsGlobalShortcut=true
Name=Cycle Items Forward
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.