about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--ranger/api/keys.py22
-rw-r--r--ranger/core/actions.py23
-rw-r--r--test/tc_direction.py7
3 files changed, 41 insertions, 11 deletions
diff --git a/ranger/api/keys.py b/ranger/api/keys.py
index d7a688b9..92a0269c 100644
--- a/ranger/api/keys.py
+++ b/ranger/api/keys.py
@@ -34,10 +34,11 @@ class Wrapper(object):
 			def function(command_argument):
 				args, kws = real_args, real_keywords
 				number = command_argument.n
+				direction = command_argument.direction
 				obj = getattr(command_argument, self.__firstattr__)
 				fnc = getattr(obj, attr)
-				if number is not None:
-					args, kws = replace_narg(number, fnc, args, kws)
+				if number is not None or direction is not None:
+					args, kws = replace_narg(number, direction, fnc, args, kws)
 				return fnc(*args, **kws)
 			return function
 		return wrapper
@@ -63,6 +64,7 @@ fm = Wrapper('fm')
 wdg = Wrapper('wdg')
 
 
+DIRARG_KEYWORD = 'dirarg'
 NARG_KEYWORD = 'narg'
 
 def narg(number_, function_, *args_, **keywords_):
@@ -78,7 +80,7 @@ def narg(number_, function_, *args_, **keywords_):
 	args, keywords = replace_narg(number_, function_, args_, keywords_)
 	return function_(*args, **keywords)
 
-def replace_narg(number, function, args, keywords):
+def replace_narg(number, direction, function, args, keywords):
 	"""
 	This function returns (args, keywords) with one little change:
 	if <function> has a named argument called "narg", args and keywords
@@ -93,10 +95,10 @@ def replace_narg(number, function, args, keywords):
 	=> (1, 666), {}
 	"""
 	argspec = getargspec(function).args
-	if NARG_KEYWORD in argspec:
+	args = list(args)
+	if number is not None and NARG_KEYWORD in argspec:
 		try:
 			# is narg in args?
-			args = list(args)
 			index = argspec.index(NARG_KEYWORD)
 			if ismethod(function):
 				index -= 1  # because of 'self'
@@ -105,4 +107,14 @@ def replace_narg(number, function, args, keywords):
 			# is narg in keywords?
 			keywords = dict(keywords)
 			keywords[NARG_KEYWORD] = number
+	if direction is not None and DIRARG_KEYWORD in argspec:
+		try:
+			index = argspec.index(DIRARG_KEYWORD)
+			if ismethod(function):
+				index -= 1  # because of 'self'
+			args[index] = direction
+		except (ValueError, IndexError):
+			# is narg in keywords?
+			keywords = dict(keywords)
+			keywords[DIRARG_KEYWORD] = direction
 	return args, keywords
diff --git a/ranger/core/actions.py b/ranger/core/actions.py
index ac6cfc95..929dec31 100644
--- a/ranger/core/actions.py
+++ b/ranger/core/actions.py
@@ -542,16 +542,27 @@ class Actions(FileManagerAware, EnvironmentAware, SettingsAware):
 		self.env.cut = False
 		self.ui.browser.main_column.request_redraw()
 
-	def copy(self):
+	def copy(self, narg=None, dirarg=None):
 		"""Copy the selected items"""
-
-		selected = self.env.get_selection()
-		self.env.copy = set(f for f in selected if f in self.env.cwd.files)
+		cwd = self.env.cwd
+		direction = Direction(dirarg or {})
+		if direction.vertical():
+			pos, selected = direction.select(
+					override=narg, lst=cwd.files, current=currentpos,
+					pagesize=self.env.termsize[0])
+		else:
+			pos = currentpos + (narg or 0)
+			selected = (f for f in self.env.get_selection() if f in cwd.files)
+		self.env.copy = set(selected)
+		self.env.copy.add(self.env.cwd.pointed_obj)
 		self.env.cut = False
+		self.env.cwd.pointer = pos
+		self.env.cwd.correct_pointer()
+		self.env.copy.add(self.env.cwd.pointed_obj)
 		self.ui.browser.main_column.request_redraw()
 
-	def cut(self):
-		self.copy()
+	def cut(self, narg=None, dirarg=None):
+		self.copy(narg=narg, dirarg=dirarg)
 		self.env.cut = True
 		self.ui.browser.main_column.request_redraw()
 
diff --git a/test/tc_direction.py b/test/tc_direction.py
index 18f9eb4c..124a7001 100644
--- a/test/tc_direction.py
+++ b/test/tc_direction.py
@@ -76,6 +76,13 @@ class TestDirections(unittest.TestCase):
 		d2 = Direction(absolute=True)
 		self.assertEqual(5, d2.move(direction=9, override=5))
 
+	def test_select(self):
+		d = Direction(down=3)
+		lst = list(range(100))
+		self.assertEqual((6, [3,4,5]), d.select(current=3, pagesize=10, override=None, lst=lst))
+		d = Direction(down=3, pages=True)
+		self.assertEqual((9, [3,4,5,6,7,8]), d.select(current=3, pagesize=2, override=None, lst=lst))
+
 if __name__ == '__main__':
 	unittest.main()