summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--ranger/gui/mouse_event.py9
-rw-r--r--ranger/gui/widgets/browserview.py7
-rw-r--r--ranger/gui/widgets/pager.py7
3 files changed, 15 insertions, 8 deletions
diff --git a/ranger/gui/mouse_event.py b/ranger/gui/mouse_event.py
index d588fd8e..f3955825 100644
--- a/ranger/gui/mouse_event.py
+++ b/ranger/gui/mouse_event.py
@@ -41,6 +41,15 @@ class MouseEvent(object):
 		except:
 			return False
 
+	def mouse_wheel_direction(self):
+		if self.bstate & curses.BUTTON4_PRESSED:
+			return -1
+		elif self.bstate & curses.BUTTON2_PRESSED \
+				or self.bstate > curses.ALL_MOUSE_EVENTS:
+			return 1
+		else:
+			return 0
+
 	def ctrl(self):
 		return self.bstate & curses.BUTTON_CTRL
 
diff --git a/ranger/gui/widgets/browserview.py b/ranger/gui/widgets/browserview.py
index 1a7ab4e6..163fd503 100644
--- a/ranger/gui/widgets/browserview.py
+++ b/ranger/gui/widgets/browserview.py
@@ -233,10 +233,9 @@ class BrowserView(Widget, DisplayableContainer):
 
 	def click(self, event):
 		n = event.ctrl() and 5 or 1
-		if event.pressed(4):
-			self.main_column.scroll(relative = -n)
-		elif event.pressed(2) or event.key_invalid():
-			self.main_column.scroll(relative = n)
+		direction = event.mouse_wheel_direction()
+		if direction:
+			self.main_column.scroll(direction)
 		else:
 			DisplayableContainer.click(self, event)
 
diff --git a/ranger/gui/widgets/pager.py b/ranger/gui/widgets/pager.py
index 08702f3f..2fc8ecda 100644
--- a/ranger/gui/widgets/pager.py
+++ b/ranger/gui/widgets/pager.py
@@ -205,10 +205,9 @@ class Pager(Widget):
 
 	def click(self, event):
 		n = event.ctrl() and 1 or 3
-		if event.pressed(4):
-			self.move(relative = -n)
-		elif event.pressed(2) or event.key_invalid():
-			self.move(relative = n)
+		direction = event.mouse_wheel_direction()
+		if direction:
+			self.move(relative=direction)
 		return True
 
 	def _get_line(self, n, attempt_to_read=True):