piranha/keymage

Use with specific DOM element, don't attach to window

orbitbot opened this issue · 4 comments

I'm trying to replace combokeys with keymage in a project, since it's considerably smaller when not minified (minfied as well, OFC). However, to support the use case, keymage would need to attach to a specific DOM element and not window, and additionally support cleaning up.

Implementation should be fairly easy, it's mainly a question of what the new API should be and if this is a desired feature(?). Some solutions that come to mind will probably break existing code that assumes keymage would be attached to the window and immediately available.

Can I ask you what's the usecase for that? Because there is scope (namespacing) support for the case when you want to enable/disable shortcuts in cases like popup is shown or something like that.

Thing is that binding on element receives keys only when focus on an element or any of it's children, which is often not the case. But I'm open for discussion. :)

The idea would be to only capture keypresses when an element is focused, rather than globally. In my usecase, I have implemented a lightweight library for IDE-like behaviour for contenteditable html tags: https://orbitbot.github.io/misbehave/ , and keymage should probably be able to handle my needs for that project (with the filed issues fixed) while cutting the unminified size of misbehave in half.

Instantiation with a target element would enable 1) easier use without needing to bother with global scopes for keymage, 2) multiple simultaneous instances that do not interfere with each other (such as needing to figure out which element the event was fired on etc.)

Oh, right, with contenteditable it would work this way.

As for figuring it out - you don't usually need that, you just catch focus on that element and set/unset scope.

But I'll think what's the best way to bind to a concrete element. Don't want to change API much. :)

So yeah, if anybody wants to implement that - I would consider taking a patch, but I see no real need for it.