func (t *TextField) keyboard(k ui.Key) { if k.Shift() { c0 := t.Caret[0] defer func() { // keep c0 rooted when holding shift t.Caret[0] = c0 }() } switch k.Trim() { case ui.Backspace: t.backspace() case ui.Delete: t.forwardDelete() case ui.Left: t.moveBackward(shift) case ui.Right: t.moveForward(shift) default: t.emacs(k) } }
func (t *TextField) emacs(key ui.Key) { switch key.TrimShift() { case "^e": t.Caret[0] = len(t.Text) t.Caret[1] = len(t.Text) case "^a": t.Caret[0] = 0 t.Caret[1] = 0 case "^b": t.moveBackward(key.Shift()) case "^f": t.moveForward(key.Shift()) } }