Skip to content

Commit c08b42d

Browse files
committed
Fix bug #548 - Transpose when empty line crashes
1 parent a17999d commit c08b42d

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

bpython/curtsiesfrontend/manual_readline.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,11 +280,13 @@ 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:
284+
return cursor_offset, line
283285
return (min(len(line), cursor_offset + 1),
284-
line[:cursor_offset-1] +
286+
line[:cursor_offset - 1] +
285287
(line[cursor_offset] if len(line) > cursor_offset else '') +
286288
line[cursor_offset - 1] +
287-
line[cursor_offset+1:])
289+
line[cursor_offset + 1:])
288290

289291

290292
@edit_keys.on('<Esc+t>')

bpython/test/test_manual_readline.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,16 @@ def test_transpose_character_before_cursor(self):
201201
"adf s|asdf",
202202
"adf as|sdf"], transpose_character_before_cursor)
203203

204+
def test_transpose_empty_line(self):
205+
self.assertEquals(transpose_character_before_cursor(0, ''),
206+
(0,''))
207+
208+
def test_transpose_first_character(self):
209+
self.assertEquals(transpose_character_before_cursor(0, 'a'),
210+
transpose_character_before_cursor(0, 'a'))
211+
self.assertEquals(transpose_character_before_cursor(0, 'as'),
212+
transpose_character_before_cursor(0, 'as'))
213+
204214
def test_transpose_word_before_cursor(self):
205215
pass
206216

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