Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Qt editing keybindings #496

Closed
wants to merge 1 commit into from

3 participants

@mspacek

Add Ctrl+Backspace and Ctrl+Del keybindings to delete to start and end of current word. This is what most people (or at least I) expect in a normal text widget. For some reason, Alt+Backspace and Alt+D are the current keybindings for this, which I find a bit strange. Anyone know why? I've left those as they are.

Also, on my local branch, I use Ctrl+D to quickly close the window, ala a normal terminal. Not sure how others would feel about this. Currently, Ctrl+D is bound to QtCore.Qt.Key_Delete.

I don't suppose keybindings will be user configurable in the near future, will they?

@epatters

The bindings we have currently were chosen specifically because they are the standard bash keybindings. Since the Qt console is first and foremost a console widget, we would like to keep those as the defaults.

That said, having user configurable keybindings would be a great enhancement. Unfortunately, I don't think that's likely to be done in the near future. At least, I don't have the spare cycles for it.

You are, of course, welcome to take a stab at this yourself. If you'd like some guidance, just ask. Otherwise, feel free to open a feature request issue, and hopefully it will get picked up eventually.

@mspacek

Hm, I don't exactly have lots of spare time, but I think I could actually see myself getting this done fairly quickly. I'm pretty comfortable with Qt and its keybindings from working on my own code.

I would need some guidance though. I guess this would require giving official names to each action, and some kind of dictionary mapping config key names into proper Qt key names. Maybe someone can propose a couple of keybinding examples, like how to designate in a config file (*.py ?) the key command for delete_previous_word, to establish a convention that I could simply extend to all the existing actions.

@fperez
Owner

It seems to me the right way to do this is to wait for #492 to get merged (almost ready). At that point, the Qt console will have a proper config file support, and it will be much easier to experiment.

This is, for example, the format used by LyX:

\bind "C-e" "line-end"
\bind "C-a" "line-begin"
\bind "C-d" "char-delete-forward"
\bind "C-i" "font-emph"
\bind "C-S-t" "buffer-update pdf2"

which follows how Emacs describes keybindings as well.

I don't think the \bind syntax looks particularly nice, but the key descriptions seem fine, and it's just a matter for us of sorting out how to describe actions.

But it seems to me that this should become a separate issue, since your pull request here can be reviewed/merged on its own merits as an existing improvement. So I suggest we clear this PR as-is, and if you're interested in tackling this one, perhaps open an issue for the design discussion, from which you can then link to a PR once you have code ready.

You're also welcome to ping for more feedback on the -dev list, as always (sometimes people don't respond to open issues right away).

@mspacek

OK, I've opened up issue #502 for configuring qt key bindings.

@fperez
Owner

Since #502 will be far more work than simply adding these few lines that will likely make the console more usable for many folks who don't come from Emacs, I'm in favor of merging this for now, so that the 0.11 experience out of the box is as good as possible. Later we'll work on a more generic framework for this.

@epatters

That's fine by me.

@fperez
Owner

Thanks, @epatters! I'll then go ahead and merge this one now.

@fperez
Owner

Merged; rebased to avoid a long merge handle for just one commit. Thanks for the code!

@fperez fperez closed this
@mspacek

Great, thanks for the merge!

@damianavila damianavila referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 1, 2011
  1. @mspacek
This page is out of date. Refresh to see the latest.
Showing with 6 additions and 0 deletions.
  1. +6 −0 IPython/frontend/qt/console/console_widget.py
View
6 IPython/frontend/qt/console/console_widget.py
@@ -988,6 +988,12 @@ def _event_filter_console_keypress(self, event):
intercepted = True
elif key in (QtCore.Qt.Key_Backspace, QtCore.Qt.Key_Delete):
+ if key == QtCore.Qt.Key_Backspace:
+ cursor = self._get_word_start_cursor(position)
+ else: # key == QtCore.Qt.Key_Delete
+ cursor = self._get_word_end_cursor(position)
+ cursor.setPosition(position, QtGui.QTextCursor.KeepAnchor)
+ self._kill_ring.kill_cursor(cursor)
intercepted = True
elif key in (QtCore.Qt.Key_Plus, QtCore.Qt.Key_Equal):
Something went wrong with that request. Please try again.