about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--ranger/container/keymap.py10
-rw-r--r--test/tc_newkeys.py30
2 files changed, 39 insertions, 1 deletions
diff --git a/ranger/container/keymap.py b/ranger/container/keymap.py
index 70faa0d0..23f26448 100644
--- a/ranger/container/keymap.py
+++ b/ranger/container/keymap.py
@@ -18,6 +18,7 @@ from inspect import isfunction, getargspec
 from ranger.ext.tree import Tree
 
 MAX_ALIAS_RECURSION = 20
+PASSIVE_ACTION = 9003
 DIRKEY = 9001
 ANYKEY = 9002
 FUNC = 'func'
@@ -207,8 +208,8 @@ class KeyBuffer(object):
 		return True
 
 	def _do_eval_command(self, key):
+		assert isinstance(self.tree_pointer, dict), self.tree_pointer
 		try:
-			assert isinstance(self.tree_pointer, dict), self.tree_pointer
 			self.tree_pointer = self.tree_pointer[key]
 		except TypeError:
 			print(self.tree_pointer)
@@ -230,6 +231,11 @@ class KeyBuffer(object):
 				self.failure = True
 				return None
 		else:
+			if isinstance(self.tree_pointer, dict):
+				try:
+					self.command = self.tree_pointer[PASSIVE_ACTION]
+				except (KeyError, TypeError):
+					self.command = None
 			self._try_to_finish()
 
 	def _try_to_finish(self, rec=MAX_ALIAS_RECURSION):
@@ -274,10 +280,12 @@ class KeyBuffer(object):
 				return self.command
 			if self.failure:
 				break
+		return self.command
 
 key_map = {
 	'dir': DIRKEY,
 	'any': ANYKEY,
+	'psv': PASSIVE_ACTION,
 	'cr': ord("\n"),
 	'enter': ord("\n"),
 	'space': ord(" "),
diff --git a/test/tc_newkeys.py b/test/tc_newkeys.py
index 0922029e..697bfdcb 100644
--- a/test/tc_newkeys.py
+++ b/test/tc_newkeys.py
@@ -38,6 +38,36 @@ class PressTestCase(TestCase):
 
 class Test(PressTestCase):
 	"""The test cases"""
+	def test_passive_action(self):
+		km = KeyMap()
+		directions = KeyMap()
+		kb = KeyBuffer(km, directions)
+		def n(value):
+			"""return n or value"""
+			def fnc(arg=None):
+				if arg is None or arg.n is None:
+					return value
+				return arg.n
+			return fnc
+
+		km.add(n(5), 'ppp')
+		km.add(n(8), 'pp<psv>')
+		km.add(n(2), 'pp<dir>')
+		directions.add('j', dir=Direction(down=1))
+
+		press = self._mkpress(kb, km)
+		self.assertEqual(5, press('ppp'))
+		self.assertEqual(3, press('3ppp'))
+
+		self.assertEqual(2, press('ppj'))
+
+		kb.clear()
+		match = kb.simulate_press('pp')
+		args = CommandArgs(0, 0, kb)
+		self.assert_(match)
+		self.assert_(match.function)
+		self.assertEqual(8, match.function(args))
+
 	def test_translate_keys(self):
 		def test(string, *args):
 			if not args: