[IPython-dev] Shortcut to convert cell between code and markdown while remaining in edit mode?
Maximilian Albert
maximilian.albert at gmail.com
Sun Apr 20 19:01:32 EDT 2014
Hi Min,
many thanks for the quick reply. I was aware that keyboard shortcut
customization was on the agenda, but hadn't realised that it had hit master
(or even a released version) yet. That's great news! :)
Unfortunately, adding the code you posted to the file
.ipython/profile_nbserver/static/custom/custom.js didn't make any
difference - it seems like the code is simply ignored (I am starting the
notebook using --profile=nbserver, so it should be the correct file,
right?).
However, I can paste the snippet into a running notebook using the
%%javascript magic. If I do this then the keyboard shortcut is indeed
defined and I can use it. But the behaviour is slightly strange in that
once I press Ctrl-y I seem to be "stuck" in the cell I'm editing and can't
leave it using Shift+Enter alone (I have to click with the mouse in a
different cell to get out). However, the following works as expected (not
the additional lines "IPython.notebook.command_mode();"):
==>
IPython.keyboard_manager.edit_shortcuts.add_shortcut('ctrl-y', {
help : 'toggle markdown/code',
handler : function (event) {
var cell = IPython.notebook.get_selected_cell();
if (cell.cell_type == 'code') {
IPython.notebook.command_mode();
IPython.notebook.to_markdown();
IPython.notebook.edit_mode();
} else if (cell.cell_type == 'markdown') {
IPython.notebook.command_mode();
IPython.notebook.to_code();
IPython.notebook.edit_mode();
}
return false;
}
});
<==
The only minor drawback is that this also resets the cursor back to the
beginning of the cell (as James noticed in his other email). I guess
whatever the fix is would work in both cases?
Many thanks again!
Max
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20140421/7c1fbcfe/attachment.html>
More information about the IPython-dev
mailing list