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

[vi-mode] mapping ctrl+{j,k} to next/previous is buggy in search mode #1511

Closed
laur89 opened this issue Nov 4, 2020 · 6 comments
Closed

Comments

@laur89
Copy link

laur89 commented Nov 4, 2020

Clarification
The goal of using next & previous commands is to move the selection in clipboard elements in the same manner as arrow Down & Up are behaving by default.

Reproduction:

  • Make sure vi mode is enabled (unsure if necessary)
  • Map ctrl+{j,k} to next/previous, in parallel to default Up/Down arrow.
  • toggle copyq
  • verify new mapping works as expected (it does, ie exactly the same behaviour as using arrow up&down)
  • enter search mode via / and filter your clipboard down to smaller number of elements
  • try said mappings again

Expected result:
ctrl+{j,k} should behave the same as Up/Down arrow in this filtered search mode

Actual result:
Looks like ctrl+{j,k} are still working against the full list of elements, although filtered list of elements is shown.

copyq-commands.ini contents defining the mappings:

[Commands]
1\Command=copyq: next()
1\GlobalShortcut=ctrl+j
1\Icon=\xf063
1\IsGlobalShortcut=true
1\Name=Copy next item
2\Command=copyq: previous()
2\GlobalShortcut=ctrl+k
2\Icon=\xf062
2\IsGlobalShortcut=true
2\Name=Copy previous item

Version, OS and Environment

CopyQ Clipboard Manager v3.13.0
Qt: 5.14.2
Compiler: GCC
Arch: x86_64-little_endian-lp64
OS: Debian GNU/Linux bullseye/sid
@hluk
Copy link
Owner

hluk commented Nov 8, 2020

The "Copy next/previous item" predefined commands are used to copy the following item.

You probably want this command:

[Command]
Command="
    copyq:
    var shortcut = str(data(mimeShortcut))
    var row = selectedItems()[0]
    if (shortcut == 'ctrl+j')
        selectItems(row + 1)
    else
        selectItems(row - 1)"
Icon=\xf338
InMenu=true
Name=Up/Down
Shortcut=ctrl+j, ctrl+k

@hluk hluk removed the bug label Nov 8, 2020
@laur89
Copy link
Author

laur89 commented Nov 8, 2020

That's just amazing. Thanks!

@laur89 laur89 closed this as completed Nov 8, 2020
@laur89
Copy link
Author

laur89 commented Jun 10, 2021

Just noticed it's not quite same as moving by arrows.

A

  1. toggle clipboard
  2. filter items by searching for keyword
  3. move by the ctrl + {j,k} keys as defined above
  4. try to edit selected/highlighted item by F2 - note nothing happens

Now if user had used arrow keys in step 3., then F2 would open the editor as expected.

B
Additionally, we also break the cursor in this mode if we try to move up when first element is selected, or move down if last element is selected.

What's up with these cases?

Am on same copyq & qt ver as in the original post.

@hluk
Copy link
Owner

hluk commented Jun 21, 2021

F2 shortcut works only if the item list has keyboard focus. When you search, it is the filter text box that is focused. You may need to override the shortcut so it works when filtering:

[Command]
Command="
    copyq:
    edit(currentItem())"
Icon=\xf044
InMenu=true
Name=Edit Current
Shortcut=f2

In the B case, using currentItem() would work a bit better - the current item is still deselected but is marked as current.

[Command]
Command="
    copyq:
    var shortcut = str(data(mimeShortcut))
    var row = currentItem()
    if (shortcut == 'ctrl+j')
        selectItems(row + 1)
    else
        selectItems(row - 1)"
Icon=\xf338
InMenu=true
Name=Up/Down
Shortcut=ctrl+j, ctrl+k

@laur89
Copy link
Author

laur89 commented Jun 23, 2021

All valid solutions, awesome!
Only issue with A case is that F2 now causes error message to pop up:

CopyQ Error
Editor command: execvp: No such file or directory

Note functionally everything works, just the (think it's qt's?) error is shown.

Copyq commands.ini

@hluk
Copy link
Owner

hluk commented Jun 28, 2021

My guess is that External editor command in configuration (History tab) is not configured correctly (the editor program is not found).

The edit() in the F2 command opens an external editor if configured, otherwise it opens the internal editor.

laur89 added a commit to laur89/dotfiles that referenced this issue Jun 30, 2021
- Up/Down is the ctrl+{j,k}
- Edit Current makes sure F2 always works
- both these cases are described here:
  hluk/CopyQ#1511 (comment)
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

No branches or pull requests

2 participants