http://jsfiddle.net/ZjYT2/2/
You can't prevent loosing the focus of the editable div, otherwise the panorama can't work, but you can store the caret position and restore it later (a simple focus
would make the caret to go to the beginning instead of the original position).
Unfortunately, in a contentEditable enabled div, the method to obtain the current selection is much more complicated than just read/set the selectStart
value (used by textareas). The best way is to use an external library for that: https://code.google.com/p/rangy/
var $keyIn = $('#keyIn');
var savedSel;
$keyIn.bind('keydown mouseup', function(){
savedSel = rangy.saveSelection();
})
$('#map').bind('mouseup', function(){
rangy.restoreSelection(savedSel);
savedSel = rangy.saveSelection();
$keyIn.focus();
});
The problem with the "k" and "m" keys still happens but only in Chrome