about summary refs log tree commit diff stats
path: root/ranger
diff options
context:
space:
mode:
authortoonn <toonn@toonn.io>2021-01-16 21:29:40 +0100
committertoonn <toonn@toonn.io>2021-01-16 21:35:46 +0100
commitf130f7c7e4f3e5eeed90bf1a01d69882cccb0321 (patch)
tree888be2667a683c1f8397364cffa0ebd1e928610c /ranger
parentb897f845848fa84a0b2d5b76949d18bff312af4d (diff)
downloadranger-f130f7c7e4f3e5eeed90bf1a01d69882cccb0321.tar.gz
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.
Diffstat (limited to 'ranger')
-rw-r--r--ranger/gui/widgets/console.py5
1 files changed, 4 insertions, 1 deletions
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