This commit is contained in:
Damien Elmes 2012-01-30 22:26:43 +09:00
commit 90b50ddd6c

View file

@ -123,20 +123,19 @@ function saveField(type) {
clearChangeTimer(); clearChangeTimer();
}; };
function wrappedExceptForWhitespace(text, front, back) {
var match = text.match(/^(\s*)([^]*?)(\s*)$/);
return match[1] + front + match[2] + back + match[3];
};
function wrap(front, back) { function wrap(front, back) {
setFormat('removeFormat', null, true); setFormat('removeFormat', null, true);
var s = window.getSelection(); var s = window.getSelection();
var r = s.getRangeAt(0); var r = s.getRangeAt(0);
var content = r.extractContents(); var content = r.cloneContents();
var span = document.createElement("span") var span = document.createElement("span")
span.appendChild(content); span.appendChild(content);
s.removeAllRanges(); var new_ = wrappedExceptForWhitespace(span.innerHTML, front, back);
s.addRange(r);
var new_ = front + span.innerHTML + back;
var f = currentField.innerHTML;
if (f.length && f[f.length-1] === " ") {
new_ = " " + new_;
}
setFormat('inserthtml', new_); setFormat('inserthtml', new_);
}; };