@@ -112,29 +112,21 @@ func (e *Editor) MoveCursorRight(left, right, selection []rune) {
112
112
e .setAndFixText (newText )
113
113
}
114
114
115
- func (e * Editor ) MoveCursorToIndex (left , right , selection [] rune , index int ) {
116
- var newText string = string ( left ) + string ( selection ) + string ( right )
115
+ func (e * Editor ) MoveCursorToIndex (text string , index int ) {
116
+ // Bound the index to the string length
117
117
if index < 0 {
118
118
index = 0
119
- } else if index >= len (newText ) {
120
- index = len (newText ) - 1
119
+ } else if index >= len (text ) {
120
+ index = len (text ) - 1
121
121
}
122
122
123
- if index < len (left ) {
124
- newText = leftRegion + string (left [:index ]) + selRegion + string (left [index ]) + rightRegion + string (left [index + 1 :]) + string (right ) + endRegion
125
- } else {
126
- indexSelection := index - len (left )
127
- if indexSelection < len (selection ) {
128
- newText = leftRegion + string (left ) + string (left [:indexSelection ]) + selRegion + string (selection [indexSelection ]) + rightRegion + string (selection [indexSelection + 1 :]) + string (right ) + endRegion
129
- } else {
130
- indexRight := index - len (left ) - len (selection )
131
- if indexRight < len (right ) {
132
- newText = leftRegion + string (left ) + string (selection ) + string (right [:indexRight ]) + selRegion + string (right [indexRight ]) + rightRegion + string (right [indexRight + 1 :]) + endRegion
133
- }
134
- }
123
+ left := string (text [:index ])
124
+ right := string (text [index :])
125
+ if len (right ) == 1 {
126
+ right = " " + selectionChar
127
+ left += " "
135
128
}
136
-
137
- e .setAndFixText (newText )
129
+ e .setAndFixText (leftRegion + left + selRegion + string (right [0 ]) + rightRegion + right [1 :] + endRegion )
138
130
}
139
131
140
132
func (e * Editor ) SelectWordLeft (left , right , selection []rune ) {
0 commit comments