diff options
author | Jonathan Slenders <jonathan@slenders.be> | 2016-08-15 19:39:58 +0200 |
---|---|---|
committer | Jonathan Slenders <jonathan@slenders.be> | 2016-08-21 21:05:54 +0200 |
commit | 316e28702c155ec636e8197acc65878b341ba9a9 (patch) | |
tree | db27781bfd4f4a7fe530730ad57e1c6386379388 | |
parent | 192e8e6690a05f01a519fd1bd310cc6853fa00e4 (diff) |
Support negative arguments for next/previous word ending/beginning.
-rw-r--r-- | prompt_toolkit/document.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/prompt_toolkit/document.py b/prompt_toolkit/document.py index 6e7c8564..470ba27e 100644 --- a/prompt_toolkit/document.py +++ b/prompt_toolkit/document.py @@ -480,6 +480,9 @@ class Document(object): Return an index relative to the cursor position pointing to the start of the next word. Return `None` if nothing was found. """ + if count < 0: + return self.find_previous_word_beginning(count=-count, WORD=WORD) + regex = _FIND_BIG_WORD_RE if WORD else _FIND_WORD_RE iterator = regex.finditer(self.text_after_cursor) @@ -499,6 +502,9 @@ class Document(object): Return an index relative to the cursor position pointing to the end of the next word. Return `None` if nothing was found. """ + if count < 0: + return self.find_previous_word_ending(count=-count, WORD=WORD) + if include_current_position: text = self.text_after_cursor else: @@ -525,6 +531,9 @@ class Document(object): Return an index relative to the cursor position pointing to the start of the previous word. Return `None` if nothing was found. """ + if count < 0: + return self.find_next_word_beginning(count=-count, WORD=WORD) + regex = _FIND_BIG_WORD_RE if WORD else _FIND_WORD_RE iterator = regex.finditer(self.text_before_cursor[::-1]) @@ -540,6 +549,9 @@ class Document(object): Return an index relative to the cursor position pointing to the end of the previous word. Return `None` if nothing was found. """ + if count < 0: + return self.find_next_word_ending(count=-count, WORD=WORD) + text_before_cursor = self.text_after_cursor[:1] + self.text_before_cursor[::-1] regex = _FIND_BIG_WORD_RE if WORD else _FIND_WORD_RE |