diff options
Diffstat (limited to 'xfa')
-rw-r--r-- | xfa/fde/cfde_texteditengine.cpp | 17 | ||||
-rw-r--r-- | xfa/fde/cfde_texteditengine_unittest.cpp | 5 |
2 files changed, 12 insertions, 10 deletions
diff --git a/xfa/fde/cfde_texteditengine.cpp b/xfa/fde/cfde_texteditengine.cpp index 989843c7f0..0157b353cf 100644 --- a/xfa/fde/cfde_texteditengine.cpp +++ b/xfa/fde/cfde_texteditengine.cpp @@ -941,13 +941,18 @@ size_t CFDE_TextEditEngine::GetIndexForPoint(const CFX_PointF& point) { size_t pos = std::min( static_cast<size_t>(start_it->nStart + start_it->nCount), text_length_); - // The line is not the last one and it was broken right after a space, the - // cursor should not be placed after the space, but before it. If the - // cursor is moved after the space, it goes to the beginning of the next - // line. + // If the line is not the last one and it was broken right after a breaking + // whitespace (space or line break), the cursor should not be placed after + // the whitespace, but before it. If the cursor is moved after the + // whitespace, it goes to the beginning of the next line. bool is_last_line = (std::next(start_it) == text_piece_info_.end()); - if (!is_last_line && pos > 0 && GetChar(pos - 1) == L' ') - --pos; + if (!is_last_line && pos > 0) { + wchar_t previous_char = GetChar(pos - 1); + if (previous_char == L' ' || previous_char == L'\n' || + previous_char == L'\r') { + --pos; + } + } return pos; } diff --git a/xfa/fde/cfde_texteditengine_unittest.cpp b/xfa/fde/cfde_texteditengine_unittest.cpp index ab8e64078b..123d16ce4b 100644 --- a/xfa/fde/cfde_texteditengine_unittest.cpp +++ b/xfa/fde/cfde_texteditengine_unittest.cpp @@ -445,10 +445,7 @@ TEST_F(CFDE_TextEditEngineTest, GetIndexForPointLineBreaks) { engine()->SetFontSize(10.0f); engine()->Insert(0, L"Hello\nWorld"); EXPECT_EQ(0U, engine()->GetIndexForPoint({0.0f, 0.0f})); - - // TODO(hnakashima): Should be 5U, caret is moving to next line. - EXPECT_EQ(6U, engine()->GetIndexForPoint({999999.0f, 0.0f})); - + EXPECT_EQ(5U, engine()->GetIndexForPoint({999999.0f, 0.0f})); EXPECT_EQ(6U, engine()->GetIndexForPoint({0.0f, 10.0f})); EXPECT_EQ(11U, engine()->GetIndexForPoint({999999.0f, 9999999.0f})); } |