зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1606232 - Make `nsIHTMLEditor::GetSelectedElement()` check whether the found element is followed by `<br>` element deeper r=m_kato
Current `nsIHTMLEditor::GetSelectedElement()` just checks whether the found element is followed by `<br>` element or not. However, following element may start with `<br>` element and if there is end of the range, `PostContentIterator` does not list up the `<br>` element. Therefore, it should check whether the found element is followed by `<br>` element which is starts the next sibling element too. Differential Revision: https://phabricator.services.mozilla.com/D60385 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
6975d37d43
Коммит
6ea35a12b9
|
@ -2605,9 +2605,20 @@ already_AddRefed<Element> HTMLEditor::GetSelectedElement(const nsAtom* aTagName,
|
||||||
// - <p><b>[def</b>}<br></p>
|
// - <p><b>[def</b>}<br></p>
|
||||||
// Note that we don't need special handling for <a href> because double
|
// Note that we don't need special handling for <a href> because double
|
||||||
// clicking it selects the element and we use the first path to handle it.
|
// clicking it selects the element and we use the first path to handle it.
|
||||||
if (lastElementInRange->GetNextSibling() &&
|
// Additionally, we have this case too:
|
||||||
lastElementInRange->GetNextSibling()->IsHTMLElement(nsGkAtoms::br)) {
|
// - <p><b>[def</b><b>}<br></b></p>
|
||||||
return nullptr;
|
// In these cases, the <br> element is not listed up by PostContentIterator.
|
||||||
|
// So, we should return nullptr if next sibling is a `<br>` element or
|
||||||
|
// next sibling starts with `<br>` element.
|
||||||
|
if (nsIContent* nextSibling = lastElementInRange->GetNextSibling()) {
|
||||||
|
if (nextSibling->IsHTMLElement(nsGkAtoms::br)) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
nsIContent* firstEditableLeaf = GetLeftmostChild(nextSibling);
|
||||||
|
if (firstEditableLeaf &&
|
||||||
|
firstEditableLeaf->IsHTMLElement(nsGkAtoms::br)) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!aTagName) {
|
if (!aTagName) {
|
||||||
|
|
|
@ -779,6 +779,27 @@ SimpleTest.waitForFocus(async function() {
|
||||||
null,
|
null,
|
||||||
"#9-1 nsIHTMLEditor::getSelectedElement(\"anchor\") should return null when Selection starts from a text node in <b> element and ends before the following <br> element");
|
"#9-1 nsIHTMLEditor::getSelectedElement(\"anchor\") should return null when Selection starts from a text node in <b> element and ends before the following <br> element");
|
||||||
|
|
||||||
|
editor.innerHTML = "<p><b>b1</b><b><br></b><b>b2</b></p>";
|
||||||
|
editor.focus();
|
||||||
|
|
||||||
|
// <p><b>[b1</b><b>}<br></b><b>b2</b></p>
|
||||||
|
// This is usual case of double-clicking in the first <b> element.
|
||||||
|
range = document.createRange();
|
||||||
|
range.setStart(editor.firstChild.firstChild.firstChild, 0);
|
||||||
|
range.setEnd(editor.firstChild.firstChild.nextSibling, 0);
|
||||||
|
selection.removeAllRanges();
|
||||||
|
selection.addRange(range);
|
||||||
|
|
||||||
|
is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("")),
|
||||||
|
null,
|
||||||
|
"#10-1 nsIHTMLEditor::getSelectedElement(\"\") should return null when Selection starts from a text node in <b> element and ends before the following <br> element in another <b> element");
|
||||||
|
is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("href")),
|
||||||
|
null,
|
||||||
|
"#10-1 nsIHTMLEditor::getSelectedElement(\"href\") should return null when Selection starts from a text node in <b> element and ends before the following <br> element in another <b> element");
|
||||||
|
is(SpecialPowers.unwrap(getHTMLEditor().getSelectedElement("anchor")),
|
||||||
|
null,
|
||||||
|
"#10-1 nsIHTMLEditor::getSelectedElement(\"anchor\") should return null when Selection starts from a text node in <b> element and ends before the following <br> element in another <b> element");
|
||||||
|
|
||||||
SimpleTest.finish();
|
SimpleTest.finish();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче