when wrap called with empty selection, postion caret in middle

This commit is contained in:
Damien Elmes 2012-05-06 14:53:33 +09:00
parent e7911652ef
commit ff28fdd189

View file

@ -48,7 +48,6 @@ body { margin: 5px; }
var currentField = null;
var changeTimer = null;
var insertHTMLOK = %s;
var savedSel = null;
var dropTarget = null;
String.prototype.format = function() {
@ -185,6 +184,14 @@ function wrap(front, back) {
r.insertNode(document.createTextNode(new_));
saveField('key');
}
if (!span.innerHTML) {
// run with an empty selection; move cursor back past postfix
r = s.getRangeAt(0);
r.setStart(r.startContainer, r.startOffset - back.length);
r.collapse(true);
s.removeAllRanges();
s.addRange(r);
}
};
function setFields(fields, focusTo) {