Permalink
Browse files

Add delete_backward_word method to SelectorCommand.

  • Loading branch information...
1 parent 8a2427c commit ba13e0e47c40523a2d7b54c2abbc88c89fac420f @anekos committed Apr 30, 2012
Showing with 11 additions and 0 deletions.
  1. +1 −0 percol/__init__.py
  2. +10 −0 percol/command.py
View
@@ -202,6 +202,7 @@ def search_and_refresh_display():
# text
"C-h" : lambda percol: percol.command.delete_backward_char(),
"<backspace>" : lambda percol: percol.command.delete_backward_char(),
+ "C-w" : lambda percol: percol.command.delete_backward_word(),
"C-u" : lambda percol: percol.command.clear_query(),
"<dc>" : lambda percol: percol.command.delete_forward_char(),
# caret
View
@@ -98,6 +98,16 @@ def delete_backward_char(self):
self.backward_char()
self.delete_forward_char()
+ def delete_backward_word(self):
+ from re import search
+ caret = self.model.caret
+ if caret > 0:
+ q = self.model.query
+ qc = q[:caret]
+ m = search(r'\S+', qc[::-1])
+ self.model.query = qc[:-m.end()] + q[caret:]
+ self.model.set_caret(caret - m.end())
+
def delete_forward_char(self):
caret = self.model.caret
self.model.query = self.model.query[:caret] + self.model.query[caret + 1:]

0 comments on commit ba13e0e

Please sign in to comment.