Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add. HotKeys plugin #93

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

Add. HotKeys plugin #93

wants to merge 6 commits into from

Conversation

moteus
Copy link

@moteus moteus commented Sep 11, 2021

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
Copy link
Author

moteus commented Sep 12, 2021

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.

@pkulchenko
Copy link
Owner

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).

@moteus
Copy link
Author

moteus commented Sep 13, 2021

The last commit requires OnEditorKey event described in pkulchenko/ZeroBraneStudio#1124
This commit allows to define Ctrl-K M and Ctrl-K m for different actions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants