forked from mirrors/gecko-dev
Bug 1649121: part 20) Move GetNewCaretPointAfterInsertingHTML to HTMLWithContextInserter. r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D82385
This commit is contained in:
parent
b1c3499828
commit
1360293f83
2 changed files with 13 additions and 9 deletions
|
|
@ -4613,9 +4613,6 @@ class HTMLEditor final : public TextEditor,
|
||||||
*/
|
*/
|
||||||
bool OurWindowHasFocus() const;
|
bool OurWindowHasFocus() const;
|
||||||
|
|
||||||
EditorDOMPoint GetNewCaretPointAfterInsertingHTML(
|
|
||||||
const EditorDOMPoint& lastInsertedPoint) const;
|
|
||||||
|
|
||||||
class HTMLWithContextInserter;
|
class HTMLWithContextInserter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -217,17 +217,22 @@ class MOZ_STACK_CLASS HTMLEditor::HTMLWithContextInserter final {
|
||||||
bool aClearStyle);
|
bool aClearStyle);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
EditorDOMPoint GetNewCaretPointAfterInsertingHTML(
|
||||||
|
const EditorDOMPoint& aLastInsertedPoint) const;
|
||||||
|
|
||||||
HTMLEditor& mHTMLEditor;
|
HTMLEditor& mHTMLEditor;
|
||||||
};
|
};
|
||||||
|
|
||||||
EditorDOMPoint HTMLEditor::GetNewCaretPointAfterInsertingHTML(
|
EditorDOMPoint
|
||||||
|
HTMLEditor::HTMLWithContextInserter::GetNewCaretPointAfterInsertingHTML(
|
||||||
const EditorDOMPoint& aLastInsertedPoint) const {
|
const EditorDOMPoint& aLastInsertedPoint) const {
|
||||||
EditorDOMPoint pointToPutCaret;
|
EditorDOMPoint pointToPutCaret;
|
||||||
|
|
||||||
// but don't cross tables
|
// but don't cross tables
|
||||||
nsIContent* containerContent = nullptr;
|
nsIContent* containerContent = nullptr;
|
||||||
if (!HTMLEditUtils::IsTable(aLastInsertedPoint.GetChild())) {
|
if (!HTMLEditUtils::IsTable(aLastInsertedPoint.GetChild())) {
|
||||||
containerContent = GetLastEditableLeaf(*aLastInsertedPoint.GetChild());
|
containerContent =
|
||||||
|
mHTMLEditor.GetLastEditableLeaf(*aLastInsertedPoint.GetChild());
|
||||||
if (containerContent) {
|
if (containerContent) {
|
||||||
Element* mostDistantInclusiveAncestorTableElement = nullptr;
|
Element* mostDistantInclusiveAncestorTableElement = nullptr;
|
||||||
for (Element* maybeTableElement =
|
for (Element* maybeTableElement =
|
||||||
|
|
@ -269,13 +274,15 @@ EditorDOMPoint HTMLEditor::GetNewCaretPointAfterInsertingHTML(
|
||||||
|
|
||||||
// Make sure we don't end up with selection collapsed after an invisible
|
// Make sure we don't end up with selection collapsed after an invisible
|
||||||
// `<br>` element.
|
// `<br>` element.
|
||||||
WSRunScanner wsRunScannerAtCaret(this, pointToPutCaret);
|
WSRunScanner wsRunScannerAtCaret(&mHTMLEditor, pointToPutCaret);
|
||||||
if (wsRunScannerAtCaret
|
if (wsRunScannerAtCaret
|
||||||
.ScanPreviousVisibleNodeOrBlockBoundaryFrom(pointToPutCaret)
|
.ScanPreviousVisibleNodeOrBlockBoundaryFrom(pointToPutCaret)
|
||||||
.ReachedBRElement() &&
|
.ReachedBRElement() &&
|
||||||
!IsVisibleBRElement(wsRunScannerAtCaret.GetStartReasonContent())) {
|
!mHTMLEditor.IsVisibleBRElement(
|
||||||
|
wsRunScannerAtCaret.GetStartReasonContent())) {
|
||||||
WSRunScanner wsRunScannerAtStartReason(
|
WSRunScanner wsRunScannerAtStartReason(
|
||||||
this, EditorDOMPoint(wsRunScannerAtCaret.GetStartReasonContent()));
|
&mHTMLEditor,
|
||||||
|
EditorDOMPoint(wsRunScannerAtCaret.GetStartReasonContent()));
|
||||||
WSScanResult backwardScanFromPointToCaretResult =
|
WSScanResult backwardScanFromPointToCaretResult =
|
||||||
wsRunScannerAtStartReason.ScanPreviousVisibleNodeOrBlockBoundaryFrom(
|
wsRunScannerAtStartReason.ScanPreviousVisibleNodeOrBlockBoundaryFrom(
|
||||||
pointToPutCaret);
|
pointToPutCaret);
|
||||||
|
|
@ -791,7 +798,7 @@ nsresult HTMLEditor::HTMLWithContextInserter::Run(
|
||||||
}
|
}
|
||||||
|
|
||||||
const EditorDOMPoint pointToPutCaret =
|
const EditorDOMPoint pointToPutCaret =
|
||||||
mHTMLEditor.GetNewCaretPointAfterInsertingHTML(lastInsertedPoint);
|
GetNewCaretPointAfterInsertingHTML(lastInsertedPoint);
|
||||||
// Now collapse the selection to the end of what we just inserted.
|
// Now collapse the selection to the end of what we just inserted.
|
||||||
rv = MOZ_KnownLive(mHTMLEditor).CollapseSelectionTo(pointToPutCaret);
|
rv = MOZ_KnownLive(mHTMLEditor).CollapseSelectionTo(pointToPutCaret);
|
||||||
if (NS_WARN_IF(rv == NS_ERROR_EDITOR_DESTROYED)) {
|
if (NS_WARN_IF(rv == NS_ERROR_EDITOR_DESTROYED)) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue