Changeset 105473 in webkit


Ignore:
Timestamp:
Jan 19, 2012 6:51:04 PM (12 years ago)
Author:
commit-queue@webkit.org
Message:

Fix inconsistent text selection behavior with option-shift-left/right/up/down.
https://bugs.webkit.org/show_bug.cgi?id=75652

Patch by Pablo Flouret <pablof@motorola.com> on 2012-01-19
Reviewed by Enrica Casucci.

On Mac, selecting backwards by word, line or paragraph from the middle
of some text, and then going forward leaves the caret back in the middle
with no selection, instead of directly selecting to the other end of the
word/line/paragraph (Unix/Windows behavior). Fix this by adding a new
editing behavior to control whether the selection should go across the
initial position of the caret directly or not in situations like the one
outlined above.

Source/WebCore:

Test: editing/selection/selection-extend-should-not-move-across-caret-on-mac.html

  • editing/EditingBehavior.h:

(WebCore::EditingBehavior::shouldExtendSelectionByWordOrLineAcrossCaret):

  • editing/FrameSelection.cpp:

(WebCore::FrameSelection::modify):

LayoutTests:

  • editing/selection/selection-extend-should-not-move-across-caret-on-mac-expected.txt: Added.
  • editing/selection/selection-extend-should-not-move-across-caret-on-mac.html: Added.
Location:
trunk
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r105471 r105473  
     12012-01-19  Pablo Flouret  <pablof@motorola.com>
     2
     3        Fix inconsistent text selection behavior with option-shift-left/right/up/down.
     4        https://bugs.webkit.org/show_bug.cgi?id=75652
     5
     6        Reviewed by Enrica Casucci.
     7
     8        On Mac, selecting backwards by word, line or paragraph from the middle
     9        of some text, and then going forward leaves the caret back in the middle
     10        with no selection, instead of directly selecting to the other end of the
     11        word/line/paragraph (Unix/Windows behavior). Fix this by adding a new
     12        editing behavior to control whether the selection should go across the
     13        initial position of the caret directly or not in situations like the one
     14        outlined above.
     15
     16        * editing/selection/selection-extend-should-not-move-across-caret-on-mac-expected.txt: Added.
     17        * editing/selection/selection-extend-should-not-move-across-caret-on-mac.html: Added.
     18
    1192012-01-19  Simon Fraser  <simon.fraser@apple.com>
    220
  • trunk/Source/WebCore/ChangeLog

    r105471 r105473  
     12012-01-19  Pablo Flouret  <pablof@motorola.com>
     2
     3        Fix inconsistent text selection behavior with option-shift-left/right/up/down.
     4        https://bugs.webkit.org/show_bug.cgi?id=75652
     5
     6        Reviewed by Enrica Casucci.
     7
     8        On Mac, selecting backwards by word, line or paragraph from the middle
     9        of some text, and then going forward leaves the caret back in the middle
     10        with no selection, instead of directly selecting to the other end of the
     11        word/line/paragraph (Unix/Windows behavior). Fix this by adding a new
     12        editing behavior to control whether the selection should go across the
     13        initial position of the caret directly or not in situations like the one
     14        outlined above.
     15
     16        Test: editing/selection/selection-extend-should-not-move-across-caret-on-mac.html
     17
     18        * editing/EditingBehavior.h:
     19        (WebCore::EditingBehavior::shouldExtendSelectionByWordOrLineAcrossCaret):
     20        * editing/FrameSelection.cpp:
     21        (WebCore::FrameSelection::modify):
     22
    1232012-01-19  Simon Fraser  <simon.fraser@apple.com>
    224
  • trunk/Source/WebCore/editing/EditingBehavior.h

    r102252 r105473  
    6868    bool shouldNavigateBackOnBackspace() const { return m_type != EditingUnixBehavior; }
    6969
     70    // On Mac, selecting backwards by word/line from the middle of a word/line, and then going
     71    // forward leaves the caret back in the middle with no selection, instead of directly selecting
     72    // to the other end of the line/word (Unix/Windows behavior).
     73    bool shouldExtendSelectionByWordOrLineAcrossCaret() const { return m_type != EditingMacBehavior; }
     74
    7075private:
    7176    EditingBehaviorType m_type;
  • trunk/Source/WebCore/editing/FrameSelection.cpp

    r105441 r105473  
    937937        break;
    938938    case AlterationExtend:
     939        if (!m_selection.isCaret()
     940            && (granularity == WordGranularity || granularity == ParagraphGranularity || granularity == LineGranularity)
     941            && m_frame && !m_frame->editor()->behavior().shouldExtendSelectionByWordOrLineAcrossCaret()) {
     942            // Don't let the selection go across the base position directly. Needed to match mac
     943            // behavior when, for instance, word-selecting backwards starting with the caret in
     944            // the middle of a word and then word-selecting forward, leaving the caret in the
     945            // same place where it was, instead of directly selecting to the end of the word.
     946            VisibleSelection newSelection = m_selection;
     947            newSelection.setExtent(position);
     948            if (m_selection.isBaseFirst() != newSelection.isBaseFirst())
     949                position = m_selection.base();
     950        }
     951
    939952        // Standard Mac behavior when extending to a boundary is grow the selection rather than leaving the
    940953        // base in place and moving the extent. Matches NSTextView.
Note: See TracChangeset for help on using the changeset viewer.