Repository: spyder-ide/spyder

Issue:
[Enhancement] Support XButton1 and XButton2
## Enhancement Description

My Mouse has two extra buttons, Forward and backward (for example in a browser).
The related Keyboard-Events are XButton1 (Back) and XButton2 (Forward).

I'd expect them to issue the same event as the ALT+Left or ALT+Right Key-Combination does.
This would improve source code browsing a lot.

Thanks!
[Enhancement] Support XButton1 and XButton2
## Enhancement Description

My Mouse has two extra buttons, Forward and backward (for example in a browser).
The related Keyboard-Events are XButton1 (Back) and XButton2 (Forward).

I'd expect them to issue the same event as the ALT+Left or ALT+Right Key-Combination does.
This would improve source code browsing a lot.

Thanks!


Discussion:
Hi @maurerle,

Have you tried to add this combination under `Preferences > Shortcuts`, you can bind those keys to do whatever you want. Please try it and let me know how it goes.
Hi, this didn't work out.
The MouseButtons are currently not recognized by Spyder

A Code Example of the requested functionality can be seen here in a Python QT Browser:
https://github.com/qutebrowser/qutebrowser/blob/4c479bb4ab9a25276ea9045c99b690dc925dd345/qutebrowser/browser/eventfilter.py#L247

Those should be an alias for "next cursor position" respectivley "previous cursor positon"
I think this would be great! I would also love to use my extra mouse buttons for prev/next cursor position
@skjerns, this doesn't seem hard to implement. Do you want to give it a try? 
Hi @maurerle,

Have you tried to add this combination under `Preferences > Shortcuts`, you can bind those keys to do whatever you want. Please try it and let me know how it goes.
Hi, this didn't work out.
The MouseButtons are currently not recognized by Spyder

A Code Example of the requested functionality can be seen here in a Python QT Browser:
https://github.com/qutebrowser/qutebrowser/blob/4c479bb4ab9a25276ea9045c99b690dc925dd345/qutebrowser/browser/eventfilter.py#L247

Those should be an alias for "next cursor position" respectivley "previous cursor positon"
I think this would be great! I would also love to use my extra mouse buttons for prev/next cursor position
@skjerns, this doesn't seem hard to implement. Do you want to give it a try? 

Resolving patch:
diff --git a/spyder/plugins/editor/widgets/base.py b/spyder/plugins/editor/widgets/base.py
--- a/spyder/plugins/editor/widgets/base.py
+++ b/spyder/plugins/editor/widgets/base.py
@@ -44,6 +44,8 @@ class TextEditBaseWidget(QPlainTextEdit, BaseEditMixin):
     focus_changed = Signal()
     sig_insert_completion = Signal(str)
     sig_eol_chars_changed = Signal(str)
+    sig_prev_cursor = Signal()
+    sig_next_cursor = Signal()
 
     def __init__(self, parent=None):
         QPlainTextEdit.__init__(self, parent)
@@ -1058,6 +1060,13 @@ def stdkey_end(self, shift, ctrl):
     # ----Qt Events
     def mousePressEvent(self, event):
         """Reimplement Qt method"""
+
+        # mouse buttons for forward and backward navigation
+        if event.button() == Qt.XButton1:
+            self.sig_prev_cursor.emit()
+        elif event.button() == Qt.XButton2:
+            self.sig_next_cursor.emit()
+
         if sys.platform.startswith('linux') and event.button() == Qt.MidButton:
             self.calltip_widget.hide()
             self.setFocus()
diff --git a/spyder/plugins/editor/widgets/editor.py b/spyder/plugins/editor/widgets/editor.py
--- a/spyder/plugins/editor/widgets/editor.py
+++ b/spyder/plugins/editor/widgets/editor.py
@@ -2556,6 +2556,8 @@ def perform_completion_request(lang, method, params):
         editor.zoom_reset.connect(lambda: self.zoom_reset.emit())
         editor.sig_eol_chars_changed.connect(
             lambda eol_chars: self.refresh_eol_chars(eol_chars))
+        editor.sig_next_cursor.connect(self.sig_next_cursor.emit)
+        editor.sig_prev_cursor.connect(self.sig_prev_cursor.emit)
 
         self.find_widget.set_editor(editor)
 


Test patch: