Changeset 249565 in webkit


Ignore:
Timestamp:
Sep 6, 2019 12:06:09 AM (5 years ago)
Author:
commit-queue@webkit.org
Message:

AccessibilityRenderObject::setSelectedTextRange fails to set the selection passed an empty line.
https://bugs.webkit.org/show_bug.cgi?id=201518
<rdar://problem/54835122>

Patch by Andres Gonzalez <Andres Gonzalez> on 2019-09-06
Reviewed by Ryosuke Niwa.

Source/WebCore:

Test: accessibility/set-selected-text-range-after-newline.html

In the case of an empty line, the CharacterIterator range start and end
were not equal, thus we were not advancing the iterator and returning
the iterator range end, which is not correct. With this change we are
always advancing the iterator if its text is just '\n'. This covers all
the cases we fixed before plus empty lines.

  • editing/Editing.cpp:

(WebCore::visiblePositionForIndexUsingCharacterIterator):

LayoutTests:

Extended this test to set the selection range passed an empty line.

  • accessibility/set-selected-text-range-after-newline-expected.txt:
  • accessibility/set-selected-text-range-after-newline.html:
Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r249563 r249565  
     12019-09-06  Andres Gonzalez  <andresg_22@apple.com>
     2
     3        AccessibilityRenderObject::setSelectedTextRange fails to set the selection passed an empty line.
     4        https://bugs.webkit.org/show_bug.cgi?id=201518
     5        <rdar://problem/54835122>
     6
     7        Reviewed by Ryosuke Niwa.
     8
     9        Extended this test to set the selection range passed an empty line.
     10        * accessibility/set-selected-text-range-after-newline-expected.txt:
     11        * accessibility/set-selected-text-range-after-newline.html:
     12
    1132019-09-05  Chris Dumez  <cdumez@apple.com>
    214
  • trunk/LayoutTests/accessibility/set-selected-text-range-after-newline-expected.txt

    r245912 r249565  
    11hello
     2
    23world
    34PASS text.selectedTextRange became '{5, 0}'
    45There must be only one [newline] between hello and world: hello[newline]world
    56PASS text.selectedTextRange became '{6, 0}'
     7There must be two [newline] between hello and world: hello[newline][newline]world
     8PASS text.selectedTextRange became '{7, 0}'
    69The text after the newline should be world: world
    710PASS successfullyParsed is true
  • trunk/LayoutTests/accessibility/set-selected-text-range-after-newline.html

    r245912 r249565  
    1919        text.setSelectedTextRange(5, 0);
    2020        shouldBecomeEqual("text.selectedTextRange", "'{5, 0}'", function() {
     21            // Insert a linebreak between "hello" and "world".
    2122            text.replaceTextInRange("\n", 5, 0);
    2223
     
    2728            text.setSelectedTextRange(6, 0);
    2829            shouldBecomeEqual("text.selectedTextRange", "'{6, 0}'", function() {
    29                 var t = text.stringForRange(6, 5);
     30                // Insert another linebreak before "world".
     31                text.replaceTextInRange("\n", 6, 0);
     32
     33                var t = text.stringForRange(0, 12);
    3034                t = t.replace(/(?:\r\n|\r|\n)/g, '[newline]');
    31                 debug("The text after the newline should be world: " + t);
     35                debug("There must be two [newline] between hello and world: " + t);
    3236
    33                 finishJSTest();
     37                text.setSelectedTextRange(7, 0);
     38                shouldBecomeEqual("text.selectedTextRange", "'{7, 0}'", function() {
     39                    var t = text.stringForRange(7, 5);
     40                    t = t.replace(/(?:\r\n|\r|\n)/g, '[newline]');
     41                    debug("The text after the newline should be world: " + t);
     42
     43                    finishJSTest();
     44                });
    3445            });
    3546        });
  • trunk/Source/WebCore/ChangeLog

    r249560 r249565  
     12019-09-06  Andres Gonzalez  <andresg_22@apple.com>
     2
     3        AccessibilityRenderObject::setSelectedTextRange fails to set the selection passed an empty line.
     4        https://bugs.webkit.org/show_bug.cgi?id=201518
     5        <rdar://problem/54835122>
     6
     7        Reviewed by Ryosuke Niwa.
     8
     9        Test: accessibility/set-selected-text-range-after-newline.html
     10
     11        In the case of an empty line, the CharacterIterator range start and end
     12        were not equal, thus we were not advancing the iterator and returning
     13        the iterator range end, which is not correct. With this change we are
     14        always advancing the iterator if its text is just '\n'. This covers all
     15        the cases we fixed before plus empty lines.
     16
     17        * editing/Editing.cpp:
     18        (WebCore::visiblePositionForIndexUsingCharacterIterator):
     19
    1202019-09-05  Fujii Hironori  <Hironori.Fujii@sony.com>
    221
  • trunk/Source/WebCore/editing/Editing.cpp

    r248552 r249565  
    11231123    it.advance(index - 1);
    11241124
    1125     if (!it.atEnd() && it.text()[0] == '\n') {
     1125    if (!it.atEnd() && it.text().length() == 1 && it.text()[0] == '\n') {
    11261126        // FIXME: workaround for collapsed range (where only start position is correct) emitted for some emitted newlines.
    1127         auto iteratorRange = it.range();
    1128         if (iteratorRange->startPosition() == iteratorRange->endPosition()) {
    1129             it.advance(1);
    1130             if (!it.atEnd())
    1131                 return VisiblePosition(it.range()->startPosition());
    1132         }
     1127        it.advance(1);
     1128        if (!it.atEnd())
     1129            return VisiblePosition(it.range()->startPosition());
    11331130    }
    11341131
Note: See TracChangeset for help on using the changeset viewer.