-
-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PR: Add key binding Ctrl+[
#89
base: master
Are you sure you want to change the base?
Conversation
@ryohei22, please rebase on top of our latest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR and sorry for the late review.
I'm only available for reviews on weekends.
I have a simple code suggestion for you.
# Standard library imports
import sys
Please add the above sentence above the "# Third party imports" syntax.
sc2 = QShortcut( | ||
QKeySequence(Qt.META + Qt.Key_BracketLeft), | ||
editor.editorsplitter, | ||
self.vim_cmd.commandline.setFocus) | ||
sc2.setContext(Qt.WidgetWithChildrenShortcut) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sc2 = QShortcut( | |
QKeySequence(Qt.META + Qt.Key_BracketLeft), | |
editor.editorsplitter, | |
self.vim_cmd.commandline.setFocus) | |
sc2.setContext(Qt.WidgetWithChildrenShortcut) | |
modifier = "Meta" if sys.platform == "darwin" else "Ctrl" | |
sc2 = QShortcut( | |
QKeySequence(f"{modifier}+["), | |
vim_cmd.editor_widget.editorsplitter, | |
vim_cmd.commandline.setFocus) | |
sc2.setContext(Qt.WidgetWithChildrenShortcut) |
However, the above code does not work in the window and linux environments. I think Spyder's Codeeditor skips the CTRL key. if key in [Qt.Key_Control, Qt.Key_Shift, Qt.Key_Alt,
Qt.Key_Meta, Qt.KeypadModifier]:
# The user pressed only a modifier key.
if ctrl:
pos = self.mapFromGlobal(QCursor.pos())
pos = self.calculate_real_position_from_global(pos)
if self._handle_goto_uri_event(pos):
event.accept()
return
if self._handle_goto_definition_event(pos):
event.accept()
return
return Removing the duplicate CTRL+[ shortcut and commenting out the code above will make Ctrl+[ work in spyder-vim. |
Perhaps the best solution to deal with this would be to show a dialog the first time this plugin is loaded that asks users if they want to unset all conflicting shortcuts so that Spyder-Vim can work as expected (I'm sure this won't be the only one).
That's not a proper solution. Perhaps we need to add an editor extension here to deal with keyPressEvent's (which would override what's done in CodeEditor), or find a way to propagate the |
@ccordoba12 I think this PR is to add CTRL+[on Mac only, and CTRL+[for windows and linux should be considered in another PR. |
So, in the end, is it okay to just include @ok97465 's suggestion? |
The thing is these changes wouldn't work on Windows and Linux, as @ok97465 pointed out. So perhaps it'd be better to investigate how to port this plugin to use an Editor extension, so that it has full control over the key presses on it. Otherwise, you'd keep finding conflicts between the Spyder default keyboard shortcuts and the Vim ones. |
Description of the change
Added key binding
ctrl + [
to enter normal mode instead of esc key.Issue(s) Resolved
Part of #85
Comments
I didn't check how it works with Windows.