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

Ability to customize the keybindings that are recognized while editing a cell value #2184

Open
ei14 opened this issue Dec 21, 2023 · 3 comments
Labels

Comments

@ei14
Copy link

ei14 commented Dec 21, 2023

In visidata/_input.py on line 607, the cell-edit keybindings are hardcoded. It would be nice if we could customize these values in a config file.

My motivating example: I do a lot of manual data entry, so when I'm finished typing the value in a particular row, I want to quickly move to the next row. The shortcut to do this is Shift+Down, but this requires moving my hand from the numbers to the arrow keys; for a lot of data entry, this time wastage adds up fast! I want Ctrl+N and Ctrl-P to mean "next line" and "previous line" respectively, as these are much faster to type. I actually achieved this by modifying the source code and recompiling, but it would be nice if I didn't have to resort to such measures.

Thanks in advance! I'm really impressed by visidata; I only first heard of it a few hours ago. Wonderful software!

@ei14 ei14 added the wishlist label Dec 21, 2023
@ajkerrigan
Copy link
Collaborator

ajkerrigan commented Dec 21, 2023

That's an interesting point. I imagine there's a good/historical reason for not exposing those keys for easy customization, but in case it helps it looks like you can still handle this with an addition to your ~/.visidatarc file:

from functools import partialmethod

from visidata import Sheet
from visidata._input import acceptThenFunc

Sheet.editCell = partialmethod(Sheet.editCell, bindings={
    "^N": acceptThenFunc('go-down', 'edit-cell'),
    "^P": acceptThenFunc('go-up', 'edit-cell'),
})

It's a bit awkward compared to the more typical key bindings, but probably still less messy than maintaining a personal/local fork.

It's also possible that there's a different/better way to do this, or that this approach could break something else. 🧐

@saulpw
Copy link
Owner

saulpw commented Dec 25, 2023

@ajkerrigan You're a total pro at the monkey-patching! We need to change the keystrokes for input keybindings to the new-style Ctrl+N etc. and I agree, we should find a better way to do this, or devise an API to let us. But the need to accept/cancel the current input complicates things. What do you think it should look like, @ei14 and @ajkerrigan?

@ajkerrigan
Copy link
Collaborator

ajkerrigan commented Dec 27, 2023

we should find a better way to do this, or devise an API to let us. But the need to accept/cancel the current input complicates things. What do you think it should look like, @ei14 and @ajkerrigan?

Hmm one way might be to optimize for the "accept and do a thing" case, maybe with an option that maps keystrokes to an iterable of functions that run after accepting input? With these sample changes, the monkeypatching suggestion turns into:

vd.options.edit_accept_keybindings = {
    "Ctrl+N": ("go-down", "edit-cell"),
    "Ctrl+P": ("go-up", "edit-cell"),
}

I'm not sure if that's the best way to handle it or not (even if it is, the naming and description could probably use some work), but it does seem a wee bit friendlier. It may be making too many assumptions though, overindexed on this particular issue. So other ideas or tweaks are very welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants