diff options
author | hut <hut@lavabit.com> | 2011-04-26 21:05:06 +0200 |
---|---|---|
committer | hut <hut@lavabit.com> | 2011-04-26 21:05:06 +0200 |
commit | 3e2d6f2f3d4e6f8c71db73a26320bf0699671ba1 (patch) | |
tree | bf413f0487ff6f932f124c0ee82a153c096f0be6 /ranger | |
parent | 755e7df1a75b48e068113bd9811c68a84418dc68 (diff) | |
download | ranger-3e2d6f2f3d4e6f8c71db73a26320bf0699671ba1.tar.gz |
widgets.console: fixed delete_word()
Diffstat (limited to 'ranger')
-rw-r--r-- | ranger/gui/widgets/console.py | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/ranger/gui/widgets/console.py b/ranger/gui/widgets/console.py index 9b1b0642..12f685d4 100644 --- a/ranger/gui/widgets/console.py +++ b/ranger/gui/widgets/console.py @@ -259,15 +259,29 @@ class Console(Widget): self.pos += len(self.copy) self.on_line_change() - def delete_word(self): + def delete_word(self, backward=True): if self.line: self.tab_deque = None - i = len(self.line) - 2 - while i >= 0 and re.match(r'[\w\d]', self.line[i], re.U): - i -= 1 - self.copy = self.line[i + 1:] - self.line = self.line[:i + 1] - self.pos = len(self.line) + if backward: + right_part = self.line[self.pos:] + i = self.pos - 2 + while i >= 0 and re.match(r'[\w\d]', self.line[i], re.U): + i -= 1 + self.copy = self.line[i + 1:self.pos] + self.line = self.line[:i + 1] + right_part + self.pos = i + 1 + else: + left_part = self.line[:self.pos] + i = self.pos + 1 + while i < len(self.line) and re.match(r'[\w\d]', self.line[i], re.U): + i += 1 + self.copy = self.line[self.pos:i] + if i >= len(self.line): + self.line = left_part + self.pos = len(self.line) + else: + self.line = left_part + self.line[i:] + self.pos = len(left_part) self.on_line_change() def delete(self, mod): |