ZeroBranePackage icon indicating copy to clipboard operation
ZeroBranePackage copied to clipboard

Add. HotKeys plugin

Open moteus opened this issue 4 years ago • 3 comments

Support chanied hotkeys

Usage

local HotKeys = require 'hotkeys.storage'
local Package = {...}
Package.onRegister = function(package)
    HotKeys:add(package, {          'Ctrl-M'}, function() ide:Print('Regular action') end)
    HotKeys:add(package, {'Ctrl-K', 'Ctrl-M'}, function() ide:Print('Chained action') end)
end
Package.onUnRegister = function(package)
    HotKeys:close_package(package)
end
return Package

Possible improvements

  • Show current chain in the statusbar
  • Allow to add menu items as actions (e.g. ID.NEW)
  • Allow to add chanined actions to already exists one. E.g. Ctrl-D by default duplicates current line. It should be possible to add Ctrl-K Ctrl-D to do some other action.

moteus avatar Sep 11 '21 22:09 moteus

I still not sure how to answer to these questins

  1. How to detect that chain is failed? Currently I detect

    • hit escape key
    • timeout for 5 second after last hotkey handler
    • change current editor or cursor position (e.g mouse click tab)
    • press any key (symbol excluding shift)
  2. How to handle hot key in case of failed chain? E.e. we have shortcuts Ctrl-K Ctrl-M and Ctrl-J and user enters Ctrl-K Ctrl-J sequence. Should we just clear chain after Ctrl-J or we should try to handle Ctrl-J as a regular hot key? Currently module try to find handler and if there no such it trying to set it as a new chain

  3. How to redefine default keys from Scintilla editor itself.

moteus avatar Sep 12 '21 16:09 moteus

Show current chain in the statusbar

I think that would be very useful!

How to detect that chain is failed? Currently I detect

I agree; all of these sound good/reasonable. In fact I'd think that 5 seconds can be too much.

When I thought about this in the past, I considered adding an auto-complete popup with the currently available options in the chain along with their descriptions. That would "force" the interaction for the user and make the flow easier to handle and potentially a bit more convenient for the user, as the shortcuts (and what's going on) would be more discoverable.

How to handle hot key in case of failed chain? E.e. we have shortcuts Ctrl-K Ctrl-M and Ctrl-J and user enters Ctrl-K Ctrl-J sequence. Should we just clear chain after Ctrl-J or we should try to handle Ctrl-J as a regular hot key?

If I understand it correctly, I think it should be set up as a regular hot key in this case.

How to redefine default keys from Scintilla editor itself.

They can be redefined using (CmdKeyAssign)[https://www.scintilla.org/ScintillaDoc.html#SCI_ASSIGNCMDKEY]. It's used to assign editor-specific shortcuts. Unfortunately I don't see any way to retrieve the current mapping (short of tracking all assignments including the default ones).

pkulchenko avatar Sep 12 '21 17:09 pkulchenko

The last commit requires OnEditorKey event described in https://github.com/pkulchenko/ZeroBraneStudio/issues/1124 This commit allows to define Ctrl-K M and Ctrl-K m for different actions

moteus avatar Sep 13 '21 15:09 moteus