Skip to content

Fix bug #548 - Transpose when empty line crashes #558

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 26, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions bpython/curtsiesfrontend/manual_readline.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,11 +280,13 @@ def yank_prev_killed_text(cursor_offset, line, cut_buffer):

@edit_keys.on(config='transpose_chars_key')
def transpose_character_before_cursor(cursor_offset, line):
if cursor_offset == 0:
return cursor_offset, line
return (min(len(line), cursor_offset + 1),
line[:cursor_offset-1] +
line[:cursor_offset - 1] +
(line[cursor_offset] if len(line) > cursor_offset else '') +
line[cursor_offset - 1] +
line[cursor_offset+1:])
line[cursor_offset + 1:])


@edit_keys.on('<Esc+t>')
Expand Down
10 changes: 10 additions & 0 deletions bpython/test/test_manual_readline.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,16 @@ def test_transpose_character_before_cursor(self):
"adf s|asdf",
"adf as|sdf"], transpose_character_before_cursor)

def test_transpose_empty_line(self):
self.assertEquals(transpose_character_before_cursor(0, ''),
(0,''))

def test_transpose_first_character(self):
self.assertEquals(transpose_character_before_cursor(0, 'a'),
transpose_character_before_cursor(0, 'a'))
self.assertEquals(transpose_character_before_cursor(0, 'as'),
transpose_character_before_cursor(0, 'as'))

def test_transpose_word_before_cursor(self):
pass

Expand Down