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

Can we get a one_shot option at the key level? #6536

Open
louis-vinchon opened this issue Jan 1, 2025 · 8 comments
Open

Can we get a one_shot option at the key level? #6536

louis-vinchon opened this issue Jan 1, 2025 · 8 comments
Labels
enhancement New feature or request

Comments

@louis-vinchon
Copy link

Is your feature request related to a problem? Please describe.
I want to be able to keep a table "open" just like we can currently do with the one_shot option of wezterm.action.ActivateKeyTable, but at the key level.

Currently, if I want a given key to not close the table, I have to make the entire table one_shot, or move that key to its own table, which is unwieldy.

Describe the solution you'd like
Ideally something like this:

config.keys = {
    { key = 'a', action = action.ActivateLastTab, one_shot = false },
}
-- or
config.keys = {
    { key = 'a', action = action.ActivateLastTab, opts = { one_shot = false } },
}

That would be way more flexible.

Describe alternatives you've considered
I considered moving the key to its own table, but as far as I can tell, that would mean lengthening my key sequence by one more character, which is inconvenient and less ergonomic. And it also adds a lot of boilerplate code.

Additional context
~

@louis-vinchon louis-vinchon added the enhancement New feature or request label Jan 1, 2025
@bew
Copy link
Contributor

bew commented Jan 1, 2025

There is no automatic way to do that no.

But for a single key you could explicitly call PopKeyTable action after the wanted action to simulate the one-shot behavior
Something like this:

...
{ key = "a", action = act.Multiple { act.ActivateLastTab, act.PopKeyTable } }
...

@louis-vinchon
Copy link
Author

I see, so I could make a table one_shot = false, but then for each individual key that DO need to be one_shot, do what you suggested to explicitly trigger the one_shot anyway.

It's still a lot of code for what it does.

@bew
Copy link
Contributor

bew commented Jan 2, 2025

Yes, keep in mind you are in a Lua interpreter, you can always write functions to simplify recurring patterns in your config ;)

@louis-vinchon
Copy link
Author

How would that work for the "root table" config.keys? As far as I know I can't make it one_shot = false.

@bew
Copy link
Contributor

bew commented Jan 2, 2025

I'm not sure what behavior you want with the root table, as those keys are always available anyway 🤔

@louis-vinchon
Copy link
Author

Yeees, I am getting mixed up with another (technically unrelated) issue I have that also impacts the "openess" of tables.

If I have mods = 'CTRL', keys = 'h,j,k,l' mappings in the root table. I can press CTRL and then h, then j, then k ... without letting go of CTRL and it will work. But I cannot do that with mods = LEADER, I can do Leader then h, then I need to let go of LEADER and then press it again with j. Basically start from scratch, which to me feels like a closed table, without actually, technically being closed. It's due to the LEADER key press being dropped after the next keystroke.

That's the scenario I was thinking of.

@bew
Copy link
Contributor

bew commented Jan 2, 2025

For anything slightly more complex that the default LEADER system (which predates the Key Tables system), I'd highly suggest you to make your own leader Key Table, and then use the flexibility of ActivateKeyTable to enable one shot mode as needed.

@louis-vinchon
Copy link
Author

That's the direction I am currently working towards I think?

config.keys = {
    {
        key = 'VoidSymbol',
        action = action.ActivateKeyTable({ name = 'config_keys', one_shot = false }),
    }
}

And then cram everything in the config_keys table.

For the one_shot mappings, I think they'll be the exception rather than the norm, so making an action wrapper with action.Multiple and action.ClearKeyTableStack shouldn't be to bad.

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

No branches or pull requests

2 participants