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

Binding "tab" key #83

Open
manake opened this issue Apr 22, 2020 · 2 comments
Open

Binding "tab" key #83

manake opened this issue Apr 22, 2020 · 2 comments

Comments

@manake
Copy link

manake commented Apr 22, 2020

I see here https://www.scintilla.org/ScintillaDoc.html#KeyBindings that tab is available as SCK_TAB but it can't be assigned to a shortcut npp.AddShortcut or using this:

function func1(ch)
    if (ch == "	") then
        print("Doesn't work (this message is never shown).");
    end

    print("Typed a regular character like a, b, c, d, e, etc... works.")
end

npp.AddEventHandler("OnChar", func1)

If I assign it manually in Notepad++'s settings then it works but the default action of [tab] becomes disabled (so I can't make indentation then).

Is there a way to detect [tab] so that I could insert text after it's pressed with editor:AddText("text");?

@dail8859
Copy link
Owner

It depends exactly what you are needing to do.

At the lowest level (Scintilla) the SCK_TAB key is bound to the SCI_TAB command. I can't say for sure why it wouldn't trigger the "OnChar" event, but I would guess this is expected behavior from Scintilla. You'd probably have better luck using the "OnModification" event to see when a tab character is added, by that may not be as clean as you need.

At the Notepad++ level, "npp.AddShortcut" is used but it does not directly translate these shortcuts to Scintilla shortcuts (plus there are some limitations as to what can be assigned for some reason). If you assign a shortcut key to tab then yes it will override the Notepad++ behavior.

From the sound of it you are wanting Notepad++ to still do all of its work, and then add something extra. What I've had to do in some of my other plugins is hook the keyboard input with C code to let Notepad++ handle it like "normal" and then add some extra logic after it is done.

@dail8859
Copy link
Owner

I've thought about adding that functionality to this plugin to be able to hook the keyboard input from Lua which would allow users to do something before, after, block, alter, etc keypresses. Would not be useful to alot of users but could still be useful if implemented correctly.

The other option would be to compile a C module to hook the keyboard that uses the Lua library distributed with this plugin. I know it is possible but haven't done it myself in a while.

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

No branches or pull requests

2 participants