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

Method insertAtCursor

core/textfield.go:1070–1084  ·  view source on GitHub ↗

insertAtCursor inserts the given text at current cursor position.

(str string)

Source from the content-addressed store, hash-verified

1068
1069// insertAtCursor inserts the given text at current cursor position.
1070func (tf *TextField) insertAtCursor(str string) {
1071 if tf.hasSelection() {
1072 tf.cut()
1073 }
1074 tf.edited = true
1075 rs := []rune(str)
1076 rsl := len(rs)
1077 nt := append(tf.editText, rs...) // first append to end
1078 copy(nt[tf.cursorPos+rsl:], nt[tf.cursorPos:]) // move stuff to end
1079 copy(nt[tf.cursorPos:], rs) // copy into position
1080 tf.editText = nt
1081 tf.endPos += rsl
1082 tf.cursorForward(rsl)
1083 tf.NeedsRender()
1084}
1085
1086func (tf *TextField) contextMenu(m *Scene) {
1087 NewFuncButton(m).SetFunc(tf.copy).SetIcon(icons.Copy).SetKey(keymap.Copy).SetState(tf.NoEcho || !tf.hasSelection(), states.Disabled)

Callers 3

pasteMethod · 0.95
completeTextMethod · 0.95
handleKeyEventsMethod · 0.95

Calls 4

hasSelectionMethod · 0.95
cutMethod · 0.95
cursorForwardMethod · 0.95
NeedsRenderMethod · 0.80

Tested by

no test coverage detected