Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(889)

Unified Diff: Source/core/editing/InsertListCommand.cpp

Issue 111463002: Ensure selection is reset after changing the list type of existing list items including the last. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Computing indexForEndOfSelection only once Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « LayoutTests/editing/execCommand/selection-after-insert-list-expected.txt ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/editing/InsertListCommand.cpp
diff --git a/Source/core/editing/InsertListCommand.cpp b/Source/core/editing/InsertListCommand.cpp
index 9a702580ad22e7e12cdf1bc43c399f54d70fcb84..aff29397f9c64f84b03cb735cd0a84f0d028195d 100644
--- a/Source/core/editing/InsertListCommand.cpp
+++ b/Source/core/editing/InsertListCommand.cpp
@@ -134,6 +134,8 @@ void InsertListCommand::doApply()
VisiblePosition startOfLastParagraph = startOfParagraph(endOfSelection, CanSkipOverEditingBoundary);
if (startOfParagraph(startOfSelection, CanSkipOverEditingBoundary) != startOfLastParagraph) {
+ RefPtr<ContainerNode> scope;
+ int indexForEndOfSelection = indexForVisiblePosition(endOfSelection, scope);
bool forceCreateList = !selectionHasListOfType(selection, listTag);
RefPtr<Range> currentSelection = endingSelection().firstRange();
@@ -153,8 +155,6 @@ void InsertListCommand::doApply()
// FIXME: This is an inefficient way to keep selection alive because indexForVisiblePosition walks from
// the beginning of the document to the endOfSelection everytime this code is executed.
// But not using index is hard because there are so many ways we can lose selection inside doApplyForSingleParagraph.
- RefPtr<ContainerNode> scope;
- int indexForEndOfSelection = indexForVisiblePosition(endOfSelection, scope);
doApplyForSingleParagraph(forceCreateList, listTag, currentSelection.get());
if (endOfSelection.isNull() || endOfSelection.isOrphan() || startOfLastParagraph.isNull() || startOfLastParagraph.isOrphan()) {
endOfSelection = visiblePositionForIndex(indexForEndOfSelection, scope.get());
@@ -178,7 +178,11 @@ void InsertListCommand::doApply()
setEndingSelection(endOfSelection);
doApplyForSingleParagraph(forceCreateList, listTag, currentSelection.get());
// Fetch the end of the selection, for the reason mentioned above.
- endOfSelection = endingSelection().visibleEnd();
+ if (endOfSelection.isNull() || endOfSelection.isOrphan()) {
+ endOfSelection = visiblePositionForIndex(indexForEndOfSelection, scope.get());
+ if (endOfSelection.isNull())
+ return;
+ }
setEndingSelection(VisibleSelection(startOfSelection, endOfSelection, endingSelection().isDirectional()));
return;
}
« no previous file with comments | « LayoutTests/editing/execCommand/selection-after-insert-list-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698