Index: third_party/WebKit/Source/core/editing/spellcheck/IdleSpellCheckCallback.cpp |
diff --git a/third_party/WebKit/Source/core/editing/spellcheck/IdleSpellCheckCallback.cpp b/third_party/WebKit/Source/core/editing/spellcheck/IdleSpellCheckCallback.cpp |
index 41211b259bc2165bbe308c0610578816aa8d4a08..18cc6797d2b34ce1290e6fa417a29fee0804ee52 100644 |
--- a/third_party/WebKit/Source/core/editing/spellcheck/IdleSpellCheckCallback.cpp |
+++ b/third_party/WebKit/Source/core/editing/spellcheck/IdleSpellCheckCallback.cpp |
@@ -34,6 +34,13 @@ const int kInvalidHandle = -1; |
const int kDummyHandleForForcedInvocation = -2; |
const double kForcedInvocationDeadlineSeconds = 10; |
+Position CorrectedReferencePosition(const Position& position, |
+ const Document& document) { |
+ if (!position.IsConnected() || position.GetDocument() != document) |
+ return Position(); |
+ return CreateVisiblePosition(position).DeepEquivalent(); |
+} |
+ |
} // namespace |
IdleSpellCheckCallback::~IdleSpellCheckCallback() {} |
@@ -155,7 +162,13 @@ void IdleSpellCheckCallback::HotModeInvocation(IdleDeadline* deadline) { |
std::max(step->SequenceNumber(), last_processed_undo_step_sequence_); |
if (deadline->timeRemaining() == 0) |
break; |
- requester.CheckSpellingAt(step->EndingSelection().Extent()); |
+ // The reference position stored in undo stack can be invalid, disconnected |
+ // or have been moved to another document, in which case it should be |
+ // corrected. |
+ const Position& stored_position = step->EndingSelection().Extent(); |
+ const Position& corrected_position = |
+ CorrectedReferencePosition(stored_position, *GetFrame().GetDocument()); |
+ requester.CheckSpellingAt(corrected_position); |
} |
} |