<div dir="ltr">I think the loss of cursor position when hitting `esc`+`m`+`enter` is a bug.  I'm able to reproduce it and I've opened an issue for it here: <a href="https://github.com/ipython/ipython/issues/5688">https://github.com/ipython/ipython/issues/5688</a> .<div>
<br></div><div>Cheers,</div><div>Jon</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Apr 21, 2014 at 3:06 AM, Maximilian Albert <span dir="ltr"><<a href="mailto:maximilian.albert@gmail.com" target="_blank">maximilian.albert@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>Briliant! This works prefectly, and together with <span title="Zoltán Vörös">Zoltán's suggestion of clearing the cache (which I must admit I could have thought of...) completely solves my problem. Thanks a lot to everybody for the quick and very helpful replies! :)<br>

<br></span></div><span title="Zoltán Vörös">Best wishes,<br>Max<br></span></div><div class="gmail_extra"><br><br><div class="gmail_quote">2014-04-21 9:08 GMT+01:00 Juergen Hasch <span dir="ltr"><<a href="mailto:python@elbonia.de" target="_blank">python@elbonia.de</a>></span>:<div>
<div class="h5"><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
The reason you see this behavior is because<br>
a) custom.js gets executed before there is an IPython.keyboard_manager<br>
b) switching between code and markdown cells actually creates a new cell<br>
<br>
This should do:<br>
<br>
$([IPython.events]).on('app_initialized.NotebookApp', function(){<br>
<div><br>
    IPython.keyboard_manager.edit_shortcuts.add_shortcut('ctrl-y', {<br>
        help : 'toggle markdown/code',<br>
        handler : function (event) {<br>
            var cell = IPython.notebook.get_selected_cell();<br>
            if (cell.cell_type == 'code') {<br>
</div>                var cur = cell.code_mirror.getCursor();<br>
                IPython.notebook.command_mode();<br>
                IPython.notebook.to_markdown();<br>
                IPython.notebook.edit_mode();<br>
                cell = IPython.notebook.get_selected_cell();<br>
                cell.code_mirror.setCursor(cur);<br>
<div>            } else if (cell.cell_type == 'markdown') {<br>
</div>                var cur = cell.code_mirror.getCursor();<br>
                IPython.notebook.command_mode();<br>
                IPython.notebook.to_code();<br>
                IPython.notebook.edit_mode();<br>
                cell = IPython.notebook.get_selected_cell();<br>
                cell.code_mirror.setCursor(cur);<br>
            }<br>
            return false;<br>
        }<br>
    });<br>
<br>
});<br>
<br>
<br>
Am <a href="tel:21.04.2014%2001" value="+12104201401" target="_blank">21.04.2014 01</a>:01, schrieb Maximilian Albert:<br>
<div><div>> Hi Min,<br>
><br>
> many thanks for the quick reply. I was aware that keyboard shortcut customization was on the agenda, but hadn't realised<br>
> that it had hit master (or even a released version) yet. That's great news! :)<br>
><br>
> Unfortunately, adding the code you posted to the file .ipython/profile_nbserver/static/custom/custom.js didn't make any<br>
> difference - it seems like the code is simply ignored (I am starting the notebook using --profile=nbserver, so it should<br>
> be the correct file, right?).<br>
><br>
> However, I can paste the snippet into a running notebook using the %%javascript magic. If I do this then the keyboard<br>
> 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<br>
> 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<br>
> different cell to get out). However, the following works as expected (not the additional lines<br>
> "IPython.notebook.command_mode();"):<br>
><br>
> ==><br>
> IPython.keyboard_manager.edit_shortcuts.add_shortcut('ctrl-y', {<br>
>     help : 'toggle markdown/code',<br>
>     handler : function (event) {<br>
>         var cell = IPython.notebook.get_selected_cell();<br>
>         if (cell.cell_type == 'code') {<br>
>             IPython.notebook.command_mode();<br>
>             IPython.notebook.to_markdown();<br>
>             IPython.notebook.edit_mode();<br>
>         } else if (cell.cell_type == 'markdown') {<br>
>             IPython.notebook.command_mode();<br>
>             IPython.notebook.to_code();<br>
>             IPython.notebook.edit_mode();<br>
>         }<br>
>         return false;<br>
>     }<br>
> });<br>
> <==<br>
><br>
> The only minor drawback is that this also resets the cursor back to the beginning of the cell (as James noticed in his<br>
> other email). I guess whatever the fix is would work in both cases?<br>
><br>
> Many thanks again!<br>
> Max<br>
><br>
><br>
</div></div><div><div>> _______________________________________________<br>
> IPython-dev mailing list<br>
> <a href="mailto:IPython-dev@scipy.org" target="_blank">IPython-dev@scipy.org</a><br>
> <a href="http://mail.scipy.org/mailman/listinfo/ipython-dev" target="_blank">http://mail.scipy.org/mailman/listinfo/ipython-dev</a><br>
><br>
<br>
_______________________________________________<br>
IPython-dev mailing list<br>
<a href="mailto:IPython-dev@scipy.org" target="_blank">IPython-dev@scipy.org</a><br>
<a href="http://mail.scipy.org/mailman/listinfo/ipython-dev" target="_blank">http://mail.scipy.org/mailman/listinfo/ipython-dev</a><br>
</div></div></blockquote></div></div></div><br></div>
<br>_______________________________________________<br>
IPython-dev mailing list<br>
<a href="mailto:IPython-dev@scipy.org">IPython-dev@scipy.org</a><br>
<a href="http://mail.scipy.org/mailman/listinfo/ipython-dev" target="_blank">http://mail.scipy.org/mailman/listinfo/ipython-dev</a><br>
<br></blockquote></div><br></div>