Some work

This commit is contained in:
2025-10-03 13:35:05 -05:00
parent 4b647d9d41
commit f1e705bba5
4 changed files with 41 additions and 12 deletions

View File

@@ -35,6 +35,8 @@ type Field struct {
label string
value string
overwriteMode bool
cursor int
visible bool
active bool
@@ -93,6 +95,10 @@ func (w *Field) HandleKey(ev *tcell.EventKey) bool {
return false
}
if wh.IsBS(*ev) {
if w.overwriteMode {
w.cursor--
return true
}
return w.handleBackspace(ev)
}
if ok := w.keyMap.Handle(ev); ok {
@@ -102,7 +108,16 @@ func (w *Field) HandleKey(ev *tcell.EventKey) bool {
return false
}
if ev.Key() == tcell.KeyRune {
w.SetValue(fmt.Sprintf("%s%s%s", w.value[:w.cursor], string(ev.Rune()), w.value[w.cursor:]))
var val string
if w.overwriteMode {
val = fmt.Sprintf("%s%s", w.value[:w.cursor], string(ev.Rune()))
if len(w.value) > w.cursor+1 {
val = fmt.Sprintf("%s%s", val, w.value[w.cursor+1:])
}
} else {
val = fmt.Sprintf("%s%s%s", w.value[:w.cursor], string(ev.Rune()), w.value[w.cursor:])
}
w.SetValue(val)
w.cursor++
return true
}
@@ -252,3 +267,4 @@ func (w *Field) SetFilter(f func(ev tcell.EventKey) bool) {
return f(ev)
}
}
func (w *Field) SetOverwrite(b bool) { w.overwriteMode = b }