[ZeroBrane Studio] Re: Overriding ZBS key commands from plugin?

  • From: "Paul Reilly" <pajthbr@xxxxxxxxx>
  • To: "zerobrane@xxxxxxxxxxxxx" <zerobrane@xxxxxxxxxxxxx>
  • Date: Tue, 10 Oct 2017 00:25:08 +0100

Hi Paul
Yes, #2 is the way forward because I don't want to change anything at all in 
ZBS. I can redirect with ide:SetHotKey, so it is - as you predict - restoring 
the original functionality for the shortcut which is the sticking point.

That would be great if you could look into what is required to do this.
Regards
Paul

&#x200b;
From: Paul K
Received: 09/10/2017 20:45:29 +01:00
To: zerobrane@xxxxxxxxxxxxx
Hi Paul,

One issue I am having is a clash between Ctrl+R with ZBS native and the Vim 
mode. I am wondering if there is a way of intercepting these before they are 
executed? I want to keep both modes entirely separate.

You have a couple of options:

(1) You can remove the existing association from Ctrl+R and use it for
whatever you need in the Vim mode. This is going to work if used in
the config file, but it may not be sufficient to use it in the
onRegister event as the shortcuts may already appear on the menu
items; see the second option for that case.

The existing associations are listed in editor/keymap.lua file and can
be changed by following the instructions here:
https://studio.zerobrane.com/doc-general-preferences#key-mapping. You
can also remove the mapping instead of re-assigning it by setting the
value to an empty string.

(2) You can link the shortcut with a function using ide:SetHotKey; for
example, ide:SetHotKey(function() end, "Ctrl+R") will associate the
function you need with that shortcut. Using SetHotKey should also
resolve the conflict by removing any existing handlers (including
those that may already exist in the menu).

If you are thinking about being able to switch on/off between using
current association (linking Ctrl+R to Search&Replace) and the one you
have in the Vim mode, it's probably a bit more challenging, but may
still be possible using SetHotKey. I think the main issue you are
going to face is the lack of a pair to SetHotKey that you can use to
retrieve the current value to save and restore it later (after
switching from the Vim mode back to the normal one). Having that
function could allow you to save the values for the current
associations (for which you have conflicts) and then restore them
later. If that's what you are missing, I can look at what would be
needed to implement GetHotKey() function.

Paul.

On Mon, Oct 9, 2017 at 12:18 PM, Paul Reilly wrote:

Hi

I am writing a plugin to integrate some Vim functionality into ZBS, which is
going well now.

One issue I am having is a clash between Ctrl+R with ZBS native and the Vim
mode. I am wondering if there is a way of intercepting these before they are
executed? I want to keep both modes entirely separate.

Thanks for any assistance,

Paul


Other related posts: