obsidian-keyshots icon indicating copy to clipboard operation
obsidian-keyshots copied to clipboard

Support configuring separate modifier keys for double-tap commands (i.e. Alt for caret, Ctrl for command palette)

Open gaggle opened this issue 1 year ago • 1 comments

First off, I love this plugin – thanks for building it! It fits right into how I want to use Obsidian.

I’ve hacked a local version to support the Alt key for double-press commands instead of just Ctrl, like so:

var DOUBLE_KEY_COMMANDS = (plugin) => [
  {
    conditional: (plugin2) => plugin2.settings.carets_via_double_ctrl || plugin2.settings.command_palette_via_double_ctrl,
    object: {
      key: "Alt",

This works better for me because IntelliJ on my system (MacOS) uses Alt for multiple carets. However, the plugin only binds double-Ctrl for both “add-caret” and “open-command-palette”, but I’d like to split this:

  • Alt (double-tap) should trigger “add caret”
  • Ctrl (double-tap) should trigger “open command palette”

Is this kind of config something you’d be open to supporting (with both defaulting to Ctrl to preserve behavior)? I can maybe try a PR if you think it’s in scope. I don't have a sense at this point if I'm suggesting a massive rework (the underlying commands appear to exist, so maybe it's "just" a change to DOUBLE_KEY_COMMANDS registry?), but if you have pointers I'd be happy to learn.

Thanks again for the great plugin!

gaggle avatar Apr 13 '25 14:04 gaggle

As an aside: with this change locally, I noticed that the double-tap logic doesn’t seem to override normal keybindings. For example, Alt-Alt-Up still triggered the Alt+Up. I unbound my Alt+Up binding but I'm mentioning it here since supporting the Ctrl/Alt split like in this feature request could surface this issue more clearly.

gaggle avatar Apr 13 '25 14:04 gaggle

Hello @gaggle, thank you for your issue post.

First I apologize for late response, I was busy finishing semester at Uni.

Good job hacking my plugin :D However, this feature was fully inspired by JetBrains IDEs, where the bindings works this way, also I use this feature on Windows, didn't know that MacOS version uses alt instead. But allowing to change keys sounds like a convenient idea, which improves the user experience.

This feature would require to change behavior of DoubleKeyRegistry, main plugin and settings logic to fully implement what you requested. I will look into it deeply for next hours/days. Thank you for offering help, but my code was unmaintained for a long time so I had to refactor it in dev branch. Now the logic and structure is little bit different than before. In case of DoubleKeyRegistry class I did not touch it for 17 months (wow the time flies fast).

I will implement and release this in 2.5.0 with previously said rework + additional features.

Stay tuned, I will inform you through this issue post. Thank you for making Keyshots a better plugin.

KrazyManJ avatar Jul 23 '25 01:07 KrazyManJ

Now I have released version 2.5.0 fixing this. Please try it and let me know if everything is okay.

https://github.com/KrazyManJ/obsidian-keyshots/releases/tag/2.5.0

KrazyManJ avatar Jul 23 '25 14:07 KrazyManJ

I have to say both Ctrl Ctrl and Shift Shift don't work OK, while in the previous version they worked.

Ctrl Ctrl + Down doesn't create multiple carets. Shift Shift triggers only sometimes, while in other times i have to press Shift a few more times.

~~Something's buggeed.~~ Ah, i know what it is. It looks like if i double tap like i normally do, it doesn't register either the first or the second tap. If i press slowly, like 1s between my key key up , then key downpresses, then both command trigger with success.

So what i have to do in order to reliably trigger the 2 commands is:

  • press down
  • wait 1s
  • lift up
  • wait 1s
  • press down
  • wait 1s
  • lift up
  • command activates

I would say this is a bug introduced in 2.5.0 - Keyshots doesn't react on quickly typing Ctrl Ctrl or Shift Shift

My config:

Image

TheBestPessimist avatar Jul 23 '25 18:07 TheBestPessimist

This is how fast i double tap Left Control in my normal muscle memory:

down 0 up 0.08 - i lift my finger 0.08s after i press down

down 0.12 - This is where the second-down-up starts. there is a pause of 0.12s between the previous 'ctrl up' up 0.09 - This is where the second 'i lift my finger' happens, 0.09s after i press down

I measured this in autohotkey, here is a picture:

Image

TheBestPessimist avatar Jul 23 '25 19:07 TheBestPessimist

Thanks @TheBestPessimist I found the problem here, it is this line

https://github.com/KrazyManJ/obsidian-keyshots/blob/0eb83979c077856da86472f760d0c56fb99a6da6/src/classes/DoubleKeyRegistry.ts#L62

Where I forgot to flip conditional for timing difference (now it filters out commands completing this difference, which is the quite opposite). The difference is right here:

https://github.com/KrazyManJ/obsidian-keyshots/blob/0eb83979c077856da86472f760d0c56fb99a6da6/src/commands/double-key/add-carets.ts#L11

So I will fix it in hotfix 2.5.1 soon.

KrazyManJ avatar Jul 23 '25 19:07 KrazyManJ

I have released hotfix 2.5.1 for this issue. Please try it out.

https://github.com/KrazyManJ/obsidian-keyshots/releases/tag/2.5.1

KrazyManJ avatar Jul 23 '25 19:07 KrazyManJ

Works as expected 👍

Nicely done!

TheBestPessimist avatar Jul 24 '25 05:07 TheBestPessimist

Works as expected 👍

Nicely done!

Thank you, I will wait for @gaggle to confirm the same behavior to close this issue. Thank you for participating in other issues, and making Keyshots a better plugin. ❤️

KrazyManJ avatar Jul 24 '25 10:07 KrazyManJ

BTW, I hope university end of year went well for you.

TheBestPessimist avatar Jul 24 '25 11:07 TheBestPessimist

@gaggle confirmed the correct behavior via reactions. I am closing the issue. If am I wrong, re-open issue with additional comment.

BTW, I hope university end of year went well for you.

Also @TheBestPessimist thank you, it went well for me :D

KrazyManJ avatar Jul 25 '25 10:07 KrazyManJ