Reworking Keymaps

This commit is contained in:
2025-10-26 08:47:07 -05:00
parent cf47b5a4e4
commit d63e3a414a
30 changed files with 384 additions and 715 deletions

View File

@@ -45,7 +45,7 @@ type Form struct {
hasSubmit bool
hasCancel bool
keyMap, customKeyMap KeyMap
keyMap *KeyMap
}
var _ Widget = (*Form)(nil)
@@ -64,7 +64,6 @@ func (w *Form) Init(id string, style tcell.Style) {
w.submit = NewButton(fmt.Sprintf("%s-submit", id), style)
w.cancel = NewButton(fmt.Sprintf("%s-cancel", id), style)
w.keyMap = BlankKeyMap()
w.customKeyMap = BlankKeyMap()
}
func (w *Form) Id() string { return w.id }
@@ -92,22 +91,8 @@ func (w *Form) HandleResize(ev *tcell.EventResize) {
}
}
func (w *Form) SetKeyMap(km KeyMap, def bool) {
if def {
w.keyMap = km
} else {
w.customKeyMap = km
}
}
func (w *Form) AddToKeyMap(km KeyMap) { w.customKeyMap.Merge(km) }
func (w *Form) RemoveFromKeyMap(km KeyMap) {
for k := range km.Keys {
w.customKeyMap.Remove(k)
}
for r := range km.Runes {
w.customKeyMap.RemoveRune(r)
}
}
func (w *Form) GetKeyMap() *KeyMap { return w.keyMap }
func (w *Form) SetKeyMap(km *KeyMap) { w.keyMap = km }
func (w *Form) HandleKey(ev *tcell.EventKey) bool {
if !w.active {
@@ -129,9 +114,7 @@ func (w *Form) HandleKey(ev *tcell.EventKey) bool {
w.updateWidgets()
return w.cursor > pre
}
b1 := w.keyMap.Handle(ev)
b2 := w.customKeyMap.Handle(ev)
return b1 || b2
return w.keyMap.Handle(ev)
}
func (w *Form) HandleTime(ev *tcell.EventTime) {}
func (w *Form) Draw(screen tcell.Screen) {