| 47 | } |
| 48 | |
| 49 | func HandleEditInput(m *TuiModel, str, val string) (ret bool) { |
| 50 | selectedInput := &m.TextInput.Model |
| 51 | input := selectedInput.Value() |
| 52 | inputLen := len(input) |
| 53 | |
| 54 | if str == "backspace" { |
| 55 | cursor := selectedInput.Cursor() |
| 56 | runes := []rune(input) |
| 57 | if cursor == inputLen && inputLen > 0 { |
| 58 | selectedInput.SetValue(input[0 : inputLen-1]) |
| 59 | } else if cursor > 0 { |
| 60 | min := Max(selectedInput.Cursor(), 0) |
| 61 | min = Min(min, inputLen-1) |
| 62 | first := runes[:min-1] |
| 63 | last := runes[min:] |
| 64 | selectedInput.SetValue(string(first) + string(last)) |
| 65 | selectedInput.SetCursor(selectedInput.Cursor() - 1) |
| 66 | } |
| 67 | |
| 68 | ret = true |
| 69 | } else if str == "enter" { // writes your selection |
| 70 | EditEnter(m) |
| 71 | ret = true |
| 72 | } |
| 73 | |
| 74 | return ret |
| 75 | } |
| 76 | |
| 77 | func HandleEditMovement(m *TuiModel, str, val string) (ret bool) { |
| 78 | selectedInput := &m.TextInput.Model |