ContextUtils: Simplified setSelection() using nsIPlaintextEditor#insertText().

This commit is contained in:
satyr 2010-05-09 23:40:51 +09:00
Родитель 25b3c3b9ed
Коммит 927c50b9e8
1 изменённых файлов: 3 добавлений и 13 удалений

Просмотреть файл

@ -116,19 +116,9 @@ function setSelection(context, content, options) {
rng.selectNode(focusedElement);
plainText = rng.createContextualFragment(content).textContent;
}
let {value, scrollTop, scrollLeft, selectionStart} = focusedElement;
let {contentViewer} = (
focusedWindow.top.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIWebNavigation).QueryInterface(Ci.nsIDocShell));
contentViewer.hide();
focusedElement.value = (
value.slice(0, selectionStart) + plainText +
value.slice(focusedElement.selectionEnd));
focusedElement.selectionStart = selectionStart;
focusedElement.selectionEnd = selectionStart + plainText.length;
focusedElement.scrollTop = scrollTop;
focusedElement.scrollLeft = scrollLeft;
contentViewer.show();
focusedElement.QueryInterface(Ci.nsIDOMNSEditableElement)
.editor.QueryInterface(Ci.nsIPlaintextEditor).insertText(plainText);
focusedElement.selectionStart -= plainText.length;
return true;
}