add a hack to prevent double newlines when deleting formatting

prior to this change, if you entered an empty field, turned on bold,
typed some text, and then backspaced over the text, it would expand
to two lines and the formatting would not go away
This commit is contained in:
Damien Elmes 2013-05-23 12:31:49 +09:00
parent 34b7eaf4c9
commit ecf9776f90

View File

@ -95,6 +95,13 @@ function onKeyUp(elem) {
if (!elem.lastChild || elem.lastChild.nodeName.toLowerCase() != "br") { if (!elem.lastChild || elem.lastChild.nodeName.toLowerCase() != "br") {
elem.appendChild(document.createElement("br")); elem.appendChild(document.createElement("br"));
} }
var old = elem.innerHTML;
var new_ = old.replace(/<([biu])><br><\\/\\1>/g, "");
if (old != new_) {
elem.innerHTML = new_;
// this may have caused the cursor to disappear
caretToEnd();
}
} }
function sendState() { function sendState() {