summaryrefslogtreecommitdiff
path: root/xfa/fde/cfde_texteditengine.cpp
diff options
context:
space:
mode:
authorHenrique Nakashima <hnakashima@chromium.org>2018-04-19 21:59:43 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-04-19 21:59:43 +0000
commit901f343328236cdb307c354d56a454c7c62f7ec3 (patch)
tree6044b9727a3b1db8e4910aef13609f97aec2727b /xfa/fde/cfde_texteditengine.cpp
parentc831580e1b4547d5fcbe74864e657c1c4ebffc12 (diff)
downloadpdfium-901f343328236cdb307c354d56a454c7c62f7ec3.tar.xz
Caret moves after clicked char if closer to its right rect boundary.chromium/3401
Bug: chromium:832293 Change-Id: Idd240010a5ec99b836d9cb90c4c2aa3027ff5f67 Reviewed-on: https://pdfium-review.googlesource.com/31013 Commit-Queue: Henrique Nakashima <hnakashima@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org> Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Diffstat (limited to 'xfa/fde/cfde_texteditengine.cpp')
-rw-r--r--xfa/fde/cfde_texteditengine.cpp11
1 files changed, 8 insertions, 3 deletions
diff --git a/xfa/fde/cfde_texteditengine.cpp b/xfa/fde/cfde_texteditengine.cpp
index a423ba6eb4..fd5b10119b 100644
--- a/xfa/fde/cfde_texteditengine.cpp
+++ b/xfa/fde/cfde_texteditengine.cpp
@@ -899,8 +899,6 @@ size_t CFDE_TextEditEngine::GetIndexForPoint(const CFX_PointF& point) {
size_t start_it_idx = start_it->nStart;
for (; start_it <= end_it; ++start_it) {
- // We need to handle clicking off the end of the line. Using Contains()
- // would constrain the detection to the text on the line.
bool piece_contains_point_vertically =
(point.y >= start_it->rtPiece.top &&
point.y < start_it->rtPiece.bottom());
@@ -913,7 +911,14 @@ size_t CFDE_TextEditEngine::GetIndexForPoint(const CFX_PointF& point) {
(point.x >= rects[i].left && point.x < rects[i].right());
if (!character_contains_point_horizontally)
continue;
- size_t pos = start_it->nStart + i;
+
+ // When clicking on the left half of a character, the cursor should be
+ // moved before it. If the click was on the right half of that character,
+ // move the cursor after it.
+ bool closer_to_left =
+ (point.x - rects[i].left < rects[i].right() - point.x);
+ int caret_pos = (closer_to_left ? i : i + 1);
+ size_t pos = start_it->nStart + caret_pos;
if (pos >= text_length_)
return text_length_;