MCPcopy
hub / github.com/mathaou/termdbms / handleOverflow

Method handleOverflow

tuiutil/textinput.go:347–388  ·  view source on GitHub ↗

If a max width is defined, perform some logic to treat the visible area as a horizontally scrolling Viewport.

()

Source from the content-addressed store, hash-verified

345// If a max width is defined, perform some logic to treat the visible area
346// as a horizontally scrolling Viewport.
347func (m *TextInputModel) handleOverflow() {
348 if m.Width <= 0 || rw.StringWidth(string(m.value)) <= m.Width {
349 m.Offset = 0
350 m.OffsetRight = len(m.value)
351 return
352 }
353
354 // Correct right Offset if we've deleted characters
355 m.OffsetRight = min(m.OffsetRight, len(m.value))
356
357 if m.pos < m.Offset {
358 m.Offset = m.pos
359
360 w := 0
361 i := 0
362 runes := m.value[m.Offset:]
363
364 for i < len(runes) && w <= m.Width {
365 w += rw.RuneWidth(runes[i])
366 if w <= m.Width+1 {
367 i++
368 }
369 }
370
371 m.OffsetRight = m.Offset + i
372 } else if m.pos >= m.OffsetRight {
373 m.OffsetRight = m.pos
374
375 w := 0
376 runes := m.value[:m.OffsetRight]
377 i := len(runes) - 1
378
379 for i > 0 && w < m.Width {
380 w += rw.RuneWidth(runes[i])
381 if w <= m.Width {
382 i--
383 }
384 }
385
386 m.Offset = m.OffsetRight - (len(runes) - 1 - i)
387 }
388}
389
390// deleteBeforeCursor deletes all text before the cursor. Returns whether or
391// not the cursor blink should be reset.

Callers 3

SetValueMethod · 0.95
setCursorMethod · 0.95
UpdateMethod · 0.95

Calls 1

minFunction · 0.85

Tested by

no test coverage detected