[ZeroBrane Studio] Re: zbs-vim plugin

  • From: Paul K <paul@xxxxxxxxxxxxx>
  • To: Paul Reilly <pajthbr@xxxxxxxxx>
  • Date: Tue, 24 Oct 2017 10:52:13 -0700

Hi Paul,

ide:SetHotKey(ID, shortcut)
... using the retrieved ID doesn't restore the previous functionality after
changing the shortcut to a custom one with a previous call to SetHotKey.

It actually works in most cases, except the one you probably care
about here: when SetHotKey is set to a function. It keeps the
accelerator, which continues to work even after the new value is set.
The following patch fixes this issue for me:

diff --git a/src/editor/package.lua b/src/editor/package.lua
index c9ac9e7..a328f0a 100644
--- a/src/editor/package.lua
+++ b/src/editor/package.lua
@@ -1264,6 +1264,10 @@ function ide:SetHotKey(id, ksc)
     -- continue with the loop as there may be multiple associations
with the same hotkey
   end

+  -- remove an existing accelerator (if any)
+  local acid = self:GetHotKey(ksc)
+  if acid then self:SetAccelerator(acid) end
+
   -- if the hotkey is associated with a function, handle it first
   if type(id) == "function" then
     local fakeid = NewID()

Paul.

Other related posts: