summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Totzke <patricktotzke@gmail.com>2014-08-02 17:36:59 +0200
committerPatrick Totzke <patricktotzke@gmail.com>2014-08-02 17:36:59 +0200
commit2a93e66df116af737c2c0da1b9132542a803c1fb (patch)
treebeaa637ce990d77c1d4a4b376b9c4461bed5b44d
parentd9d957b4045752f631779d83b8afa688d4b18893 (diff)
parent9d0b3a8335741aeff6f93d7333581a56b8de81be (diff)
Merge branch '0.3.5-feature-promptmovements-706'
-rw-r--r--alot/widgets/globals.py54
-rw-r--r--docs/source/configuration/key_bindings.rst15
2 files changed, 69 insertions, 0 deletions
diff --git a/alot/widgets/globals.py b/alot/widgets/globals.py
index 62929303..ada73788 100644
--- a/alot/widgets/globals.py
+++ b/alot/widgets/globals.py
@@ -6,6 +6,8 @@
This contains alot-specific :class:`urwid.Widget` used in more than one mode.
"""
import urwid
+import re
+import operator
from alot.helper import string_decode
from alot.settings import settings
@@ -87,7 +89,14 @@ class CompleteEdit(urwid.Edit):
:tab: calls the completer and tabs forward in the result list
:shift tab: tabs backward in the result list
:up/down: move in the local input history
+ :ctrl f/b: moves curser one character to the right/left
+ :meta f/b shift right/left: moves the cursor one word to the right/left
:ctrl a/e: moves curser to the beginning/end of the input
+ :ctrl d: deletes the character under the cursor
+ :meta d: deletes everything from the cursor to the end of the next word
+ :meta delete/backspace ctrl w: deletes everything from the cursor to the beginning of the current word
+ :ctrl k: deletes everything from the cursor to the end of the input
+ :ctrl u: deletes everything from the cursor to the beginning of the input
"""
def __init__(self, completer, on_exit,
on_error=None,
@@ -162,11 +171,56 @@ class CompleteEdit(urwid.Edit):
self.set_edit_pos(0)
elif key == 'ctrl e':
self.set_edit_pos(len(self.edit_text))
+ elif key == 'ctrl f':
+ self.set_edit_pos(min(self.edit_pos+1, len(self.edit_text)))
+ elif key == 'ctrl b':
+ self.set_edit_pos(max(self.edit_pos-1, 0))
+ elif key == 'ctrl k':
+ self.edit_text = self.edit_text[:self.edit_pos]
+ elif key == 'ctrl u':
+ self.edit_text = self.edit_text[self.edit_pos:]
+ self.set_edit_pos(0)
+ elif key == 'ctrl d':
+ self.edit_text = (self.edit_text[:self.edit_pos] +
+ self.edit_text[self.edit_pos+1:])
+ elif key in ('meta f', 'shift right'):
+ self.move_to_next_word(forward=True)
+ elif key in ('meta b', 'shift left'):
+ self.move_to_next_word(forward=False)
+ elif key == 'meta d':
+ start_pos = self.edit_pos
+ end_pos = self.move_to_next_word(forward=True)
+ if end_pos != None:
+ self.edit_text = (self.edit_text[:start_pos] +
+ self.edit_text[end_pos:])
+ self.set_edit_pos(start_pos)
+ elif key in ('meta delete', 'meta backspace', 'ctrl w'):
+ end_pos = self.edit_pos
+ start_pos = self.move_to_next_word(forward=False)
+ if start_pos != None:
+ self.edit_text = (self.edit_text[:start_pos] +
+ self.edit_text[end_pos:])
+ self.set_edit_pos(start_pos)
else:
result = urwid.Edit.keypress(self, size, key)
self.completions = None
return result
+ def move_to_next_word(self, forward=True):
+ if forward:
+ match_iterator = re.finditer(r'(\b\W+|$)', self.edit_text,
+ flags=re.UNICODE)
+ match_positions = [m.start() for m in match_iterator]
+ op = operator.gt
+ else:
+ match_iterator = re.finditer(r'(\w+\b|^)', self.edit_text,
+ flags=re.UNICODE)
+ match_positions = reversed([m.start() for m in match_iterator])
+ op = operator.lt
+ for pos in match_positions:
+ if op(pos, self.edit_pos):
+ self.set_edit_pos(pos)
+ return pos
class HeadersList(urwid.WidgetWrap):
""" renders a pile of header values as key/value list """
diff --git a/docs/source/configuration/key_bindings.rst b/docs/source/configuration/key_bindings.rst
index 40d5b500..ea8f9358 100644
--- a/docs/source/configuration/key_bindings.rst
+++ b/docs/source/configuration/key_bindings.rst
@@ -39,6 +39,21 @@ User-defined bindings are combined with the default bindings listed below.
.. literalinclude:: ../../../alot/defaults/default.bindings
:language: ini
+In prompts the following hardcoded bindings are available.
+
+=========================== ========
+Key Function
+=========================== ========
+Ctrl-f/b Moves the curser one character to the right/left
+Alt-f/b Shift-right/left Moves the cursor one word to the right/left
+Ctrl-a/e Moves the curser to the beginning/end of the line
+Ctrl-d Deletes the character under the cursor
+Alt-d Deletes everything from the cursor to the end of the current or next word
+Alt-Delete/Backspace Ctrl-w Deletes everything from the cursor to the beginning of the current or previous word
+Ctrl-k Deletes everything from the cursor to the end of the line
+Ctrl-u Deletes everything from the cursor to the beginning of the line
+=========================== ========
+
Overwriting defaults
--------------------