зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1713334 - Part 5: Allow caret to be at the end of text node r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D117024
This commit is contained in:
Родитель
ca55613fb3
Коммит
2acf39c5b0
|
@ -263,60 +263,19 @@ nsresult TextEditor::EnsureCaretNotAtEndOfTextNode() {
|
|||
// This is usually performed in InitEditorContentAndSelection(), however,
|
||||
// if the editor is reframed, this may be called by
|
||||
// OnEndHandlingTopLevelEditSubAction().
|
||||
if (!SelectionRef().RangeCount()) {
|
||||
DebugOnly<nsresult> rvIgnored = CollapseSelectionToEnd();
|
||||
if (NS_WARN_IF(Destroyed())) {
|
||||
return NS_ERROR_EDITOR_DESTROYED;
|
||||
}
|
||||
NS_WARNING_ASSERTION(
|
||||
NS_SUCCEEDED(rvIgnored),
|
||||
"EditorBase::CollapseSelectionToEnd() failed, but ignored");
|
||||
}
|
||||
|
||||
// If we are at the end of the <textarea> element, we need to set the
|
||||
// selection to stick to the padding <br> element for empty last line at the
|
||||
// end of the <textarea>.
|
||||
EditorRawDOMPoint selectionStartPoint(
|
||||
EditorBase::GetStartPoint(SelectionRef()));
|
||||
if (NS_WARN_IF(!selectionStartPoint.IsSet())) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
// Nothing to do if we're not at the end of the text node.
|
||||
if (!selectionStartPoint.IsInTextNode() ||
|
||||
!selectionStartPoint.IsEndOfContainer()) {
|
||||
if (SelectionRef().RangeCount()) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
Element* anonymousDivElement = GetRoot();
|
||||
if (NS_WARN_IF(!anonymousDivElement)) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
nsINode* parentNode = selectionStartPoint.GetContainer()->GetParentNode();
|
||||
if (parentNode != anonymousDivElement) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsIContent* nextContent =
|
||||
selectionStartPoint.GetContainer()->GetNextSibling();
|
||||
if (!nextContent ||
|
||||
!EditorUtils::IsPaddingBRElementForEmptyLastLine(*nextContent)) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
EditorRawDOMPoint afterStartContainer(
|
||||
EditorRawDOMPoint::After(*selectionStartPoint.GetContainer()));
|
||||
if (NS_WARN_IF(!afterStartContainer.IsSet())) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
IgnoredErrorResult ignoredError;
|
||||
SelectionRef().CollapseInLimiter(afterStartContainer, ignoredError);
|
||||
DebugOnly<nsresult> rvIgnored = CollapseSelectionToEnd();
|
||||
if (NS_WARN_IF(Destroyed())) {
|
||||
return NS_ERROR_EDITOR_DESTROYED;
|
||||
}
|
||||
NS_WARNING_ASSERTION(!ignoredError.Failed(),
|
||||
"Selection::CollapseInLimiter() failed");
|
||||
return ignoredError.StealNSResult();
|
||||
NS_WARNING_ASSERTION(
|
||||
NS_SUCCEEDED(rvIgnored),
|
||||
"EditorBase::CollapseSelectionToEnd() failed, but ignored");
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void TextEditor::HandleNewLinesInStringForSingleLineEditor(
|
||||
|
|
|
@ -198,5 +198,15 @@
|
|||
await data.assert_empty_spin();
|
||||
assert_equals(collector.events.length, 4);
|
||||
}, `Calling setRangeText() repeatedly on ${name}`);
|
||||
|
||||
promise_test(async () => {
|
||||
await data.initialize();
|
||||
|
||||
target.value = "";
|
||||
target.setRangeText("foo");
|
||||
|
||||
await data.assert_empty_spin();
|
||||
assert_equals(collector.events.length, 0);
|
||||
}, `Calling setRangeText() on empty ${name}`);
|
||||
}
|
||||
</script>
|
||||
|
|
|
@ -1946,7 +1946,7 @@ function runCompositionTest()
|
|||
|
||||
if (!checkContent("\u30E9\u30FC\u30E1\u30F3\u6700",
|
||||
"runCompositionTest", "#6-3") ||
|
||||
!checkSelection(4, "\u6700", "runCompositionTest", "#6-3")) {
|
||||
!checkSelection(4, "", "runCompositionTest", "#6-3")) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче