insertAtCursor inserts the given text at current cursor position.
(str string)
| 1068 | |
| 1069 | // insertAtCursor inserts the given text at current cursor position. |
| 1070 | func (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 | |
| 1086 | func (tf *TextField) contextMenu(m *Scene) { |
| 1087 | NewFuncButton(m).SetFunc(tf.copy).SetIcon(icons.Copy).SetKey(keymap.Copy).SetState(tf.NoEcho || !tf.hasSelection(), states.Disabled) |
no test coverage detected