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

Function InsertCharacter

viewer/mode.go:220–254  ·  view source on GitHub ↗
(m *TuiModel, newlineOrTab string)

Source from the content-addressed store, hash-verified

218}
219
220func 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
256func HandleFormatInput(m *TuiModel, str string) bool {
257 switch str {

Callers 1

HandleFormatInputFunction · 0.85

Calls 5

MaxFunction · 0.85
MinFunction · 0.85
GetFormattedTextBufferFunction · 0.85
DataMethod · 0.80
SetViewSlicesMethod · 0.80

Tested by

no test coverage detected