New issue
Advanced search Search tips

Issue 919146 link

Starred by 1 user

Issue metadata

Status: Fixed
Owner:
Closed: Jan 9
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: ----
Pri: 2
Type: Bug

Blocking:
issue 894651



Sign in to add a comment

Caret affinity is lost during mouse dragging

Project Member Reported by xiaoche...@chromium.org, Jan 4

Issue description

Chrome Version: 73.0.3642.0 (Official Build) dev (64-bit)
OS: Linux

What steps will reproduce the problem?
(1) Create a contenteditable div with content "abc-def" where line wrap happens after '-'
(2) Mouse down at the right side of '-' and hold the mouse button
(3) Without releasing, move the mouse by a little bit, but don't enter any text or the second line

What is the expected result?

After (2), caret should be at "abc-|"
After (3), caret should be still be at "abc-|"

What happens instead?

After (3), caret is moved to the second line at "|def" as long as the mouse moves by a tiny bit
 
Root cause: caret affinity is lost when handling the mouse drag

In SelectionController::UpdateSelectionForMouseDrag:

// TextAffinity is lost in adjusted_position 
const PositionInFlatTree& adjusted_position =
    AdjustPositionRespectUserSelectAll(target, visible_selection.Start(),
                                       visible_selection.End(),
                                       target_position.DeepEquivalent());
const SelectionInFlatTree& adjusted_selection =
    should_extend_selection
        ? ExtendSelectionAsDirectional(adjusted_position,
                                       visible_selection.AsSelection(),
                                       Selection().Granularity())
        : SelectionInFlatTree::Builder().Collapse(adjusted_position).Build();

Test case attached. Also available at http://jsfiddle.net/b6x0nyjs/
repro.html
297 bytes View Download
A related bug: After setting caret at the end of first line, shift+click also moves caret to the next line.
Seems that both bugs have the same root cause.
Project Member

Comment 5 by bugdroid1@chromium.org, Jan 8

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/9c1ee116579e4a3f36ddc93bc258cfce98d5fa9a

commit 9c1ee116579e4a3f36ddc93bc258cfce98d5fa9a
Author: Xiaocheng Hu <xiaochengh@chromium.org>
Date: Tue Jan 08 23:31:53 2019

Don't lose target position affinity in mouse drag

When handling a mouse drag, if the result selection remains a caret, we
should preserve the text affinity to ensure that the caret shows up in
the correct line. This patch makes the implementation follow that.

Bug:  919146 
Change-Id: I12b40818acfc96fe1aa871cbeb40b6f45ac8a048
Reviewed-on: https://chromium-review.googlesource.com/c/1396438
Commit-Queue: Xiaocheng Hu <xiaochengh@chromium.org>
Reviewed-by: Yoshifumi Inoue <yosin@chromium.org>
Reviewed-by: Yoichi Osato <yoichio@chromium.org>
Cr-Commit-Position: refs/heads/master@{#620930}
[modify] https://crrev.com/9c1ee116579e4a3f36ddc93bc258cfce98d5fa9a/third_party/blink/renderer/core/editing/selection_controller.cc
[add] https://crrev.com/9c1ee116579e4a3f36ddc93bc258cfce98d5fa9a/third_party/blink/web_tests/editing/caret/caret_affinity_mouse_perturbation.html

Status: Fixed (was: Assigned)

Sign in to add a comment