diff --git a/layout/generic/nsTextFrameThebes.cpp b/layout/generic/nsTextFrameThebes.cpp index 4965256d444b..069933d5345d 100644 --- a/layout/generic/nsTextFrameThebes.cpp +++ b/layout/generic/nsTextFrameThebes.cpp @@ -4489,6 +4489,19 @@ private: PRPackedBool mHaveWordBreak; }; +static PRBool +IsAcceptableCaretPosition(const gfxSkipCharsIterator& aIter, gfxTextRun* aTextRun, + nsIFrame* aFrame) +{ + if (aIter.IsOriginalCharSkipped()) + return PR_FALSE; + PRUint32 index = aIter.GetSkippedOffset(); + if (!aTextRun->IsClusterStart(index)) + return PR_FALSE; + return !(aFrame->GetStyleText()->WhiteSpaceIsSignificant() && + aTextRun->GetChar(index) == '\n'); +} + PRBool nsTextFrame::PeekOffsetCharacter(PRBool aForward, PRInt32* aOffset) { @@ -4515,8 +4528,7 @@ nsTextFrame::PeekOffsetCharacter(PRBool aForward, PRInt32* aOffset) for (i = PR_MIN(trimmed.GetEnd(), startOffset) - 1; i >= trimmed.mStart; --i) { iter.SetOriginalOffset(i); - if (!iter.IsOriginalCharSkipped() && - mTextRun->IsClusterStart(iter.GetSkippedOffset())) { + if (IsAcceptableCaretPosition(iter, mTextRun, this)) { *aOffset = i - mContentOffset; return PR_TRUE; } @@ -4530,8 +4542,7 @@ nsTextFrame::PeekOffsetCharacter(PRBool aForward, PRInt32* aOffset) // but we really have no choice right now. We need to do a deeper // fix/restructuring of PeekOffsetCharacter if (i == trimmed.GetEnd() || - (!iter.IsOriginalCharSkipped() && - mTextRun->IsClusterStart(iter.GetSkippedOffset()))) { + IsAcceptableCaretPosition(iter, mTextRun, this)) { *aOffset = i - mContentOffset; return PR_TRUE; } diff --git a/layout/generic/test/test_character_movement.html b/layout/generic/test/test_character_movement.html index 3fb39169e05f..b29e81936014 100644 --- a/layout/generic/test/test_character_movement.html +++ b/layout/generic/test/test_character_movement.html @@ -65,6 +65,19 @@ function test() { testLeft(editor.firstChild, 1); testLeft(editor.firstChild, 0); + editor.innerHTML = "
aa\nbb
"; + sel.collapse(editor.firstChild.firstChild, 0); + testRight(editor.firstChild.firstChild, 1); + // at the 'bb' but HINTLEFT so appears at the end of the first line + testRight(editor.firstChild.firstChild, 3); + testRight(editor.firstChild.firstChild, 3); + testRight(editor.firstChild.firstChild, 4); + testLeft(editor.firstChild.firstChild, 3); + // at the 'bb' but HINTLEFT so appears at the end of the first line + testLeft(editor.firstChild.firstChild, 3); + testLeft(editor.firstChild.firstChild, 1); + testLeft(editor.firstChild.firstChild, 0); + SimpleTest.finish(); }