Skip to content

Commit 3abb483

Browse files
committed
Transpose characters if cursor is at the end of the line. Mimics emacs behavior.
1 parent c08b42d commit 3abb483

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

bpython/curtsiesfrontend/manual_readline.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,10 @@ def yank_prev_killed_text(cursor_offset, line, cut_buffer):
280280

281281
@edit_keys.on(config='transpose_chars_key')
282282
def transpose_character_before_cursor(cursor_offset, line):
283-
if cursor_offset == 0:
283+
if cursor_offset < 2:
284284
return cursor_offset, line
285+
if cursor_offset == len(line):
286+
return cursor_offset, line[:-2] + line[-1] + line[-2]
285287
return (min(len(line), cursor_offset + 1),
286288
line[:cursor_offset - 1] +
287289
(line[cursor_offset] if len(line) > cursor_offset else '') +

bpython/test/test_manual_readline.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,15 @@ def test_transpose_empty_line(self):
207207

208208
def test_transpose_first_character(self):
209209
self.assertEquals(transpose_character_before_cursor(0, 'a'),
210-
transpose_character_before_cursor(0, 'a'))
210+
(0, 'a'))
211211
self.assertEquals(transpose_character_before_cursor(0, 'as'),
212-
transpose_character_before_cursor(0, 'as'))
212+
(0, 'as'))
213+
214+
def test_transpose_end_of_line(self):
215+
self.assertEquals(transpose_character_before_cursor(1, 'a'),
216+
(1, 'a'))
217+
self.assertEquals(transpose_character_before_cursor(2, 'as'),
218+
(2, 'sa'))
213219

214220
def test_transpose_word_before_cursor(self):
215221
pass

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy