ipython/ipython — pull request #5296 by ivanov (2014-03-08 02:01:31+00:00)
Title: unify keyboard shortcut and codemirror interaction

Ok, this is in a state where it can use some review. I haven't yet verified that this provides everything one needs to integrate with CodeMirror's vim mode, but this makes the situation a lot better.

So to start with, the relevant code was repeated in both CodeCell and TextCell, both of which are extensions of Cell, so this just unifies the logic in Cell.

TextCell had logic here to check if the cell was rendered or not, but I don't believe it is possible to end up triggering such a code path. (Should that be required, I can always just add back these methods to TextCell, performing the .rendered==True check, and calling the Cell)

Prior to this PR, code mirror at_top would only return true on if the cursor was at the first character of the top line. Now, pressing up arrow on any character on the top line will take you to the cell above.

The same applies for the bottom line. Pressing down arrow would only go to the next cell if the cursor was at a location *after* the last character (something that is only possible to achieve in vim mode if the last line is empty, for example). Now, down arrow on any character of the last line will go to the next cell.

I've also added a use_shortcut method to ShortcutManager, which allows us to a remove a bunch of special-casing of key events like up and down arrow, escape, shift/ctrl/alt-enter.

For example, This PR makes it possible to, for example, remove our special-casing of up arrow at the top of the cell, preventing it from going to the cell above. This can be done via this javascript:

IPython.keyboard_manager.edit_shortcuts.remove_shortcut('up')

Previously, the up arrow functionality at the top of a cell was welded into the code base as an if statement.