File tree Expand file tree Collapse file tree 1 file changed +13
-14
lines changed
Expand file tree Collapse file tree 1 file changed +13
-14
lines changed Original file line number Diff line number Diff line change @@ -87,9 +87,6 @@ func (r *runeBuffer) Len() int {
8787
8888func (r * runeBuffer ) MoveToLineStart () {
8989 r .Refresh (func () {
90- if r .idx == 0 {
91- return
92- }
9390 r .idx = 0
9491 })
9592}
@@ -248,21 +245,23 @@ func (r *runeBuffer) Kill() {
248245
249246func (r * runeBuffer ) Transpose () {
250247 r .Refresh (func () {
251- if len (r .buf ) == 1 {
252- r .idx ++
253- }
254-
255- if len (r .buf ) < 2 {
248+ if r .idx == 0 {
249+ // match the GNU Readline behavior, Ctrl-T at the start of the line
250+ // is a no-op:
256251 return
257252 }
258253
259- if r .idx == 0 {
260- r .idx = 1
261- } else if r .idx >= len (r .buf ) {
262- r .idx = len (r .buf ) - 1
254+ // OK, we have at least one character behind us:
255+ if r .idx < len (r .buf ) {
256+ // swap the character in front of us with the one behind us
257+ r .buf [r .idx ], r .buf [r .idx - 1 ] = r .buf [r .idx - 1 ], r .buf [r .idx ]
258+ // advance the cursor
259+ r .idx ++
260+ } else if r .idx == len (r .buf ) && len (r .buf ) >= 2 {
261+ // swap the two characters behind us
262+ r .buf [r .idx - 2 ], r .buf [r .idx - 1 ] = r .buf [r .idx - 1 ], r .buf [r .idx - 2 ]
263+ // leave the cursor in place since there's nowhere to go
263264 }
264- r .buf [r .idx ], r .buf [r .idx - 1 ] = r .buf [r .idx - 1 ], r .buf [r .idx ]
265- r .idx ++
266265 })
267266}
268267
You can’t perform that action at this time.
0 commit comments