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

Bindable action for character insert/typing? #1130

Open
p0358 opened this issue Jun 5, 2018 · 2 comments
Open

Bindable action for character insert/typing? #1130

p0358 opened this issue Jun 5, 2018 · 2 comments

Comments

@p0358
Copy link

p0358 commented Jun 5, 2018

There are bindable actions like

InsertSpace
InsertTab
InsertNewline

but I could not find anything like InsertCharacter that would work for typing anything other than space, tabs and newlines? Is there a suitable event I don't see yet or could something like this be added?

@pbsds
Copy link
Contributor

pbsds commented Apr 19, 2020

Adding to this on this, InsertSpace is listed in help/keybindings.md, but produces an error if bound on v2.0.3

@Gavin-Holt
Copy link

Hi,

Reviewing the open issues with inserting characters, can I suggest a Lua function:

function Insert(Current,item)                
    if type(item)=="string" then
        Current.Cursor:DeleteSelection()
        Current.Buf:Insert(editor_GetTextLoc(Current), item)
    end
end
-- Dependent upon:
function editor_GetTextLoc(Current) 
-- Returns Loc-tuple w/ current marked text or whole line (begin, end)
-- From https://github.com/NicolaiSoeborg/manipulator-plugin/blob/master/manipulator.lua
    local a, b = nil, nil
    if editor.HasSelection(Current) then
        if Current.Cursor.CurSelection[1]:GreaterThan(-Current.Cursor.CurSelection[2]) then
            a, b = Current.Cursor.CurSelection[2], Current.Cursor.CurSelection[1]
        else
            a, b = Current.Cursor.CurSelection[1], Current.Cursor.CurSelection[2]
        end
    else
        local eol = string.len(Current.Buf:Line(Current.Cursor.Loc.Y))
        a, b = Current.Cursor.Loc, buffer.Loc(eol, Current.Cursor.Y)
    end
    return buffer.Loc(a.X, a.Y), buffer.Loc(b.X, b.Y)
end

This can be used with spaces (" "), tabs ("\t"), newline ("\n") or any string.

Lua functions are bound in the usual way - depending upon which file you store them inside.

However, Lua functions will not work with multicursor selections, unlike proper Go actions defined in the source - which execute at each cursor.

Hope this helps and we can close these issues?

Kind Regards Gavin Holt

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

3 participants