(m *TuiModel, str string)
| 303 | } |
| 304 | |
| 305 | func HandleFormatMode(m *TuiModel, str string) { |
| 306 | var ( |
| 307 | val string |
| 308 | replacement string |
| 309 | ) |
| 310 | |
| 311 | inputReturn := HandleFormatInput(m, str) |
| 312 | |
| 313 | if HandleFormatMovement(m, str) { |
| 314 | return |
| 315 | } |
| 316 | |
| 317 | for _, v := range InputBlacklist { |
| 318 | if strings.Contains(str, v) { |
| 319 | return |
| 320 | } |
| 321 | } |
| 322 | |
| 323 | lineNumberOffset := GetOffsetForLineNumber(m.Format.CursorY) |
| 324 | |
| 325 | pString := m.Format.EditSlices[m.Format.CursorY] |
| 326 | delta := 1 |
| 327 | if str != "backspace" { |
| 328 | // update UI |
| 329 | if *pString != "" { |
| 330 | min := Max(m.Format.CursorX+lineNumberOffset+1, 0) |
| 331 | min = Min(min, len(*pString)) |
| 332 | first := (*pString)[:min] |
| 333 | last := (*pString)[min:] |
| 334 | val = first + str + last |
| 335 | } else { |
| 336 | val = *pString + str |
| 337 | } |
| 338 | } else { |
| 339 | delta = -1 |
| 340 | val = *pString |
| 341 | } |
| 342 | |
| 343 | // if json special rules |
| 344 | replacement = m.Data().EditTextBuffer |
| 345 | cursor := m.Format.RunningOffsets[m.Viewport.YOffset+m.Format.CursorY] |
| 346 | |
| 347 | fIndex := Max(cursor, 0) |
| 348 | lIndex := m.Viewport.YOffset + m.Format.CursorY + 1 |
| 349 | |
| 350 | defer func() { |
| 351 | if recover() != nil { |
| 352 | println("whoopsy!") // bug happened once, debug... |
| 353 | } |
| 354 | }() |
| 355 | |
| 356 | first := replacement[:fIndex] |
| 357 | middle := val[lineNumberOffset+1:] |
| 358 | last := replacement[Min(m.Format.RunningOffsets[lIndex], len(replacement)):] |
| 359 | |
| 360 | if (first != "" || last != "") && last != "\n" { |
| 361 | middle += "\n" |
| 362 | } |
no test coverage detected