forked from mirrors/gecko-dev
Bug 1518002 - Update selection cache when initializing editor. r=masayuki
GitLab's comment calls scrollTop on input event handler. The scollTop may cause reflow. When causing reflow, editor is destroyed and initialized again. Then nsTextEditorState will set current value to editor. But this is failure. By bug 1465702, selection is cached in edit action. When initializing editor, selection controller is updated, so selection into cache becomes invalid. It means that all selection methods will return error since document is different. So we should update selection cache when initializing editor. Also, I cannot create test case for this situation since we have to cause reflow in input and/or composition event. Do you have any idea? Differential Revision: https://phabricator.services.mozilla.com/D16944 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
1ebdb39774
commit
c7936919a5
2 changed files with 23 additions and 0 deletions
|
|
@ -263,6 +263,19 @@ nsresult EditorBase::Init(Document& aDocument, Element* aRoot,
|
||||||
MOZ_ASSERT(selectionController,
|
MOZ_ASSERT(selectionController,
|
||||||
"Selection controller should be available at this point");
|
"Selection controller should be available at this point");
|
||||||
|
|
||||||
|
if (mEditActionData) {
|
||||||
|
// During edit action, selection is cached. But this selection is invalid
|
||||||
|
// now since selection controller is updated, so we have to update this
|
||||||
|
// cache.
|
||||||
|
Selection* selection = selectionController->GetSelection(
|
||||||
|
nsISelectionController::SELECTION_NORMAL);
|
||||||
|
NS_WARNING_ASSERTION(selection,
|
||||||
|
"We cannot update selection cache in the edit action");
|
||||||
|
if (selection) {
|
||||||
|
mEditActionData->UpdateSelectionCache(*selection);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// set up root element if we are passed one.
|
// set up root element if we are passed one.
|
||||||
if (aRoot) {
|
if (aRoot) {
|
||||||
mRootElement = aRoot;
|
mRootElement = aRoot;
|
||||||
|
|
|
||||||
|
|
@ -732,6 +732,16 @@ class EditorBase : public nsIEditor,
|
||||||
return mParentData ? mParentData->RangeUpdaterRef() : mRangeUpdater;
|
return mParentData ? mParentData->RangeUpdaterRef() : mRangeUpdater;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UpdateSelectionCache(Selection& aSelection) {
|
||||||
|
AutoEditActionDataSetter* actionData = this;
|
||||||
|
while (actionData) {
|
||||||
|
if (actionData->mSelection) {
|
||||||
|
actionData->mSelection = &aSelection;
|
||||||
|
}
|
||||||
|
actionData = actionData->mParentData;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
EditorBase& mEditorBase;
|
EditorBase& mEditorBase;
|
||||||
RefPtr<Selection> mSelection;
|
RefPtr<Selection> mSelection;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue