(m *TuiModel, newlineOrTab string)
| 218 | } |
| 219 | |
| 220 | func InsertCharacter(m *TuiModel, newlineOrTab string) { |
| 221 | yOffset := Max(m.Viewport.YOffset, 0) |
| 222 | cursor := m.Format.RunningOffsets[m.Format.CursorY+yOffset] + m.Format.CursorX |
| 223 | runes := []rune(m.Data().EditTextBuffer) |
| 224 | |
| 225 | min := Max(cursor, 0) |
| 226 | min = Min(min, len(m.Data().EditTextBuffer)) |
| 227 | first := runes[:min] |
| 228 | last := runes[min:] |
| 229 | f := string(first) |
| 230 | l := string(last) |
| 231 | m.Data().EditTextBuffer = f + newlineOrTab + l |
| 232 | if len(last) == 0 { // for whatever reason, if you don't double up on newlines if appending to end, it gets removed |
| 233 | m.Data().EditTextBuffer += newlineOrTab |
| 234 | } |
| 235 | numLines := 0 |
| 236 | for _, v := range m.Format.Text { |
| 237 | if v != "" { // ignore padding |
| 238 | numLines++ |
| 239 | } |
| 240 | } |
| 241 | if yOffset+m.Viewport.Height == numLines && newlineOrTab == "\n" { |
| 242 | m.Viewport.YOffset++ |
| 243 | } else if newlineOrTab == "\n" { |
| 244 | m.Format.CursorY++ |
| 245 | } |
| 246 | |
| 247 | m.Format.Text = GetFormattedTextBuffer(m) |
| 248 | m.SetViewSlices() |
| 249 | if newlineOrTab == "\n" { |
| 250 | m.Format.CursorX = 0 |
| 251 | } else { |
| 252 | m.Format.CursorX++ |
| 253 | } |
| 254 | } |
| 255 | |
| 256 | func HandleFormatInput(m *TuiModel, str string) bool { |
| 257 | switch str { |
no test coverage detected