From 421e2e919bce612c222e6a7d8f62fe98dcded938 Mon Sep 17 00:00:00 2001 From: toonn Date: Sat, 16 Jan 2021 20:58:36 +0100 Subject: 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. --- ranger/gui/widgets/console.py | 14 ++++---------- 1 file 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): -- cgit v1.2.3