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

Key binding doesn't seem to be working for runes #60

Open
juliaschell opened this issue Jun 1, 2020 · 4 comments
Open

Key binding doesn't seem to be working for runes #60

juliaschell opened this issue Jun 1, 2020 · 4 comments
Labels
bug Something isn't working

Comments

@juliaschell
Copy link

juliaschell commented Jun 1, 2020

I was using jroimartin/gocui for a while and recently migrated to this fork.

When I type in one field of my gui, I intend to update another field according to what I wrote. I use a keybinding for this, effectively for each alphanumeric character I type.
for _, c := range "{};=<>()[]'\"/\\-+:abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" { g.SetKeybinding("Title", c, gocui.ModNone, create_update_titleBuff(c)) }

create_update_titleBuff writes the appropriate characters to each field I'm looking to edit

This no longer seems to be working. There is no error when setting the keybinding, but the create_update_titleBuff() does not seem to actually be called -- the other functionality within that function isn't happening. Instead, it appears as if I'm just typing into the Title field.

@juliaschell juliaschell added the bug Something isn't working label Jun 1, 2020
@glvr182
Copy link
Member

glvr182 commented Jun 1, 2020

hmmm SetKeybinding requires a handler function SetKeybinding(viewname string, key interface{}, mod Modifier, handler func(*Gui, *View) error) error. So are you sure your code compiles?

Also is your code public? Might be able to have a look at it

@juliaschell
Copy link
Author

juliaschell commented Jun 1, 2020

Unfortunately my code is not public so I cannot share.

Yes the create_update_titleBuff(c) is my handler function. The code for that func is of the form

func create_update_titleBuff(c rune) func(g *gocui.Gui, v *gocui.View) error { 

	return func(g *gocui.Gui, v *gocui.View) error { 

                 /// update a few different views 

                 titleV, _ := g.View("Title")	

	         titleV.EditWrite(rune('a'))

	}
}

With that code, I would expect my Title field to show 'aaaaaaa' as I type, but instead it just displays what I typed as if there were no key bindings at all and it was just a normal editable field

@glvr182
Copy link
Member

glvr182 commented Jun 7, 2020

The issue is in

// matchView returns if the keybinding matches the current view.
func (kb *keybinding) matchView(v *View) bool {
	// if the user is typing in a field, ignore char keys
	if v == nil || (v.Editable && kb.ch != 0) {
		return false
	}
	return kb.viewName == v.name
}

Essentially this was designed to ignore keybinds when typing in an editable view. I'm thinking about making a bool called ignoreKB or something like that that defaults to true(ignore when editable) that you can set to false(do not ignore when editable) for your implementation. This way most people won't notice anything but you can implement your idea

@glvr182
Copy link
Member

glvr182 commented Jun 7, 2020

Can you test my PR #62
You can do so by changing from awesome-gocui/gocui to glvr182/gocui OR just add the patch to your own code (module/vendor folder)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants