From f130f7c7e4f3e5eeed90bf1a01d69882cccb0321 Mon Sep 17 00:00:00 2001 From: toonn Date: Sat, 16 Jan 2021 21:29:40 +0100 Subject: transpose_words: Fix transposing last two words Transpose last two words even if on the first letter of last word. This behavior is consistent with readline and emacs. The previous code move one word back if it was anywhere in the last word but that meant the third and second to last words were transposed if the cursor was on the first character of the last word. --- ranger/gui/widgets/console.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ranger/gui/widgets/console.py b/ranger/gui/widgets/console.py index 876081f8..64537062 100644 --- a/ranger/gui/widgets/console.py +++ b/ranger/gui/widgets/console.py @@ -477,7 +477,10 @@ class Console(Widget): # pylint: disable=too-many-instance-attributes,too-many- self.pos = self.move_by_word(self.line, self.pos, 1) # If in/after last word, interchange last two words - if re.match(r'[\w\d]*\s*$', self.line[self.pos:], re.UNICODE): + if (re.match(r'[\w\d]*\s*$', self.line[self.pos:], re.UNICODE) + and (re.match(r'[\w\d]', self.line[self.pos - 1], re.UNICODE) + if self.pos -1 >= 0 else True) + ): self.pos = self.move_by_word(self.line, self.pos, -1) # Util function to increment position until out of word/whitespace -- cgit 1.4.1-2-gfad0