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.py16
2 files changed, 28 insertions, 10 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..7b8d192d 100644
--- a/ranger/core/actions.py
+++ b/ranger/core/actions.py
@@ -542,16 +542,22 @@ 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()
+		direction = Direction(dirarg or {})
+		selected = direction.select(
+				override=narg,
+				lst=self.env.cwd.files,
+				current=self.env.cwd.pointer,
+				pagesize=self.env.termsize[0])
+
+		selected = selected or self.env.get_selection()
 		self.env.copy = set(f for f in selected if f in self.env.cwd.files)
 		self.env.cut = False
 		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()