diff options
author | toonn <toonn@toonn.io> | 2021-01-16 20:58:36 +0100 |
---|---|---|
committer | toonn <toonn@toonn.io> | 2021-01-16 21:35:46 +0100 |
commit | 421e2e919bce612c222e6a7d8f62fe98dcded938 (patch) | |
tree | 8db32e57e65922303ca4879c11ad31092d0f889c | |
parent | 4ecb0fc04409848cd1385ce8932000e1c67a3dd1 (diff) |
transpose_subr: Refactor to swap both regions in one concatenation
The calculations for cutting out and repositioning the second now
shifted region was complicated. Simply cutting the two regions out of
the string and swapping them is conceptually simpler.
-rw-r--r-- | ranger/gui/widgets/console.py | 14 |
1 files changed, 4 insertions, 10 deletions
diff --git a/ranger/gui/widgets/console.py b/ranger/gui/widgets/console.py index 816f341a..2ff1943d 100644 --- a/ranger/gui/widgets/console.py +++ b/ranger/gui/widgets/console.py @@ -446,19 +446,13 @@ class Console(Widget): # pylint: disable=too-many-instance-attributes,too-many- self.fm.notify("Tried to transpose invalid regions.", bad=True) return line + line_begin = line[:x[0]] word_x = line[x[0]:x[1]] + line_middle = line[x[1]:y[0]] word_y = line[y[0]:y[1]] - diff = len(word_y) - len(word_x) + line_end = line[y[1]:] - line_begin = line[0:x[0]] - line_end = line[x[1]:] - - line = line_begin + word_y + line_end - - line_begin = line[0:(y[0] + diff)] - line_end = line[(y[1] + diff):] - - line = line_begin + word_x + line_end + line = line_begin + word_y + line_middle + word_x + line_end return line def transpose_chars(self): |