MCPcopy Create free account
hub / github.com/cogentcore/core / InsertAtCursor

Method InsertAtCursor

texteditor/select.go:359–375  ·  view source on GitHub ↗

InsertAtCursor inserts given text at current cursor position

(txt []byte)

Source from the content-addressed store, hash-verified

357
358// InsertAtCursor inserts given text at current cursor position
359func (ed *Editor) InsertAtCursor(txt []byte) {
360 if ed.HasSelection() {
361 tbe := ed.deleteSelection()
362 ed.CursorPos = tbe.AdjustPos(ed.CursorPos, text.AdjustPosDelStart) // move to start if in reg
363 }
364 tbe := ed.Buffer.insertText(ed.CursorPos, txt, EditSignal)
365 if tbe == nil {
366 return
367 }
368 pos := tbe.Reg.End
369 if len(txt) == 1 && txt[0] == '\n' {
370 pos.Ch = 0 // sometimes it doesn't go to the start..
371 }
372 ed.SetCursorShow(pos)
373 ed.setCursorColumn(ed.CursorPos)
374 ed.NeedsRender()
375}
376
377///////////////////////////////////////////////////////////
378// Rectangular regions

Callers 5

keyInputMethod · 0.95
keyInputInsertBracketMethod · 0.95
keyInputInsertRuneMethod · 0.95
pasteHistoryMethod · 0.95
PasteMethod · 0.95

Calls 7

HasSelectionMethod · 0.95
deleteSelectionMethod · 0.95
SetCursorShowMethod · 0.95
setCursorColumnMethod · 0.95
AdjustPosMethod · 0.80
NeedsRenderMethod · 0.80
insertTextMethod · 0.45

Tested by

no test coverage detected