Changeset 146999 in webkit


Ignore:
Timestamp:
Mar 27, 2013 11:26:15 AM (11 years ago)
Author:
sergio@webkit.org
Message:

Inserting a blank (" ") at the end of a line does not insert anything in Overtype mode
https://bugs.webkit.org/show_bug.cgi?id=113413

Reviewed by Ryosuke Niwa.

Source/WebCore:

Perform a "normal" insert instead of a replace when there is
nothing to replace (like at the end of a line) as this case is not
supported by the replacing code path. This will allow us to
properly rebalance whitespaces in those cases.

Updated the editing/execCommand/overtype.html test to check also
this use case.

  • editing/InsertTextCommand.cpp:

(WebCore::InsertTextCommand::setEndingSelectionWithoutValidation):
(WebCore::InsertTextCommand::performTrivialReplace):
(WebCore::InsertTextCommand::performOverwrite):
(WebCore::InsertTextCommand::doApply): use the recently added
setEndingSelectionWithoutValidation() to avoid code duplication.

  • editing/InsertTextCommand.h:

(InsertTextCommand):

LayoutTests:

Updated the test to include the case of inserting a whitespace
both in the middle or at the end of a line.

  • editing/execCommand/overtype-expected.txt:
  • editing/execCommand/overtype.html:
Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r146994 r146999  
     12013-03-27  Sergio Villar Senin  <svillar@igalia.com>
     2
     3        Inserting a blank (" ") at the end of a line does not insert anything in Overtype mode
     4        https://bugs.webkit.org/show_bug.cgi?id=113413
     5
     6        Reviewed by Ryosuke Niwa.
     7
     8        Updated the test to include the case of inserting a whitespace
     9        both in the middle or at the end of a line.
     10
     11        * editing/execCommand/overtype-expected.txt:
     12        * editing/execCommand/overtype.html:
     13
    1142013-03-27  Zan Dobersek  <zdobersek@igalia.com>
    215
  • trunk/LayoutTests/editing/execCommand/overtype-expected.txt

    r146907 r146999  
    1414"
    1515
    16 After overwritting the first two characters:
     16After overwritting the first character:
    1717| "
    1818"
    1919| <b>
    20 |   "FO<#selection-caret>o"
     20|   "F<#selection-caret>oo"
    2121| <a>
    2222|   href="http://www.google.com/"
     
    3131"
    3232| <b>
    33 |   "FO<#selection-caret> "
     33|   "F <#selection-caret>o"
     34| <a>
     35|   href="http://www.google.com/"
     36|   <div>
     37|     id="linkText"
     38|     "bar"
     39| "
     40"
     41
     42After inserting a blank at the line end:
     43| "
     44"
     45| <b>
     46|   "F o <#selection-caret>"
    3447| <a>
    3548|   href="http://www.google.com/"
     
    4457"
    4558| <b>
    46 |   "FOO SOME MORE<#selection-caret>"
     59|   "F o SOME MORE<#selection-caret>"
    4760| <a>
    4861|   href="http://www.google.com/"
     
    5770"
    5871| <b>
    59 |   "FOO SOME MORE"
     72|   "F o SOME MORE"
    6073| <a>
    6174|   href="http://www.google.com/"
     
    7083"
    7184| <b>
    72 |   "FOO SOME MORE"
     85|   "F o SOME MORE"
    7386| <div>
    7487|   id="linkText"
  • trunk/LayoutTests/editing/execCommand/overtype.html

    r146907 r146999  
    3030    internals.toggleOverwriteModeEnabled(document);
    3131
    32     document.execCommand("InsertText", false, 'FO');
    33     Markup.dump(element, 'After overwritting the first two characters');
     32    document.execCommand("InsertText", false, 'F');
     33    Markup.dump(element, 'After overwritting the first character');
    3434
    3535    document.execCommand("InsertText", false, ' ');
    3636    Markup.dump(element, 'After inserting a blank');
    3737
    38     document.execCommand("InsertText", false, 'O SOME MORE');
     38    moveSelectionForwardByCharacterCommand();
     39    document.execCommand("InsertText", false, ' ');
     40    Markup.dump(element, 'After inserting a blank at the line end');
     41
     42    document.execCommand("InsertText", false, 'SOME MORE');
    3943    Markup.dump(element, 'Overwrite at the end of a line performs as a normal Insert');
    4044
  • trunk/Source/WebCore/ChangeLog

    r146995 r146999  
     12013-03-27  Sergio Villar Senin  <svillar@igalia.com>
     2
     3        Inserting a blank (" ") at the end of a line does not insert anything in Overtype mode
     4        https://bugs.webkit.org/show_bug.cgi?id=113413
     5
     6        Reviewed by Ryosuke Niwa.
     7
     8        Perform a "normal" insert instead of a replace when there is
     9        nothing to replace (like at the end of a line) as this case is not
     10        supported by the replacing code path. This will allow us to
     11        properly rebalance whitespaces in those cases.
     12
     13        Updated the editing/execCommand/overtype.html test to check also
     14        this use case.
     15
     16        * editing/InsertTextCommand.cpp:
     17        (WebCore::InsertTextCommand::setEndingSelectionWithoutValidation):
     18        (WebCore::InsertTextCommand::performTrivialReplace):
     19        (WebCore::InsertTextCommand::performOverwrite):
     20        (WebCore::InsertTextCommand::doApply): use the recently added
     21        setEndingSelectionWithoutValidation() to avoid code duplication.
     22        * editing/InsertTextCommand.h:
     23        (InsertTextCommand):
     24
    1252013-03-27  Dean Jackson  <dino@apple.com>
    226
  • trunk/Source/WebCore/editing/InsertTextCommand.cpp

    r146907 r146999  
    7676}
    7777
    78 void InsertTextCommand::setEndingSelectionWithoutValidation(const Position& startPosition, const Position& endPosition, bool selectInsertedText)
     78void InsertTextCommand::setEndingSelectionWithoutValidation(const Position& startPosition, const Position& endPosition)
    7979{
    8080    // We could have inserted a part of composed character sequence,
     
    8585    forcedEndingSelection.setIsDirectional(endingSelection().isDirectional());
    8686    setEndingSelection(forcedEndingSelection);
    87 
    88     if (!selectInsertedText)
    89         setEndingSelection(VisibleSelection(endingSelection().visibleEnd(), endingSelection().isDirectional()));
    9087}
    9188
     
    105102        return false;
    106103
    107     setEndingSelectionWithoutValidation(start, endPosition, selectInsertedText);
     104    setEndingSelectionWithoutValidation(start, endPosition);
     105    if (!selectInsertedText)
     106        setEndingSelection(VisibleSelection(endingSelection().visibleEnd(), endingSelection().isDirectional()));
    108107
    109108    return true;
     
    118117
    119118    unsigned count = std::min(text.length(), textNode->length() - start.offsetInContainerNode());
     119    if (!count)
     120        return false;
     121
    120122    replaceTextInNode(textNode, start.offsetInContainerNode(), count, text);
    121123
    122124    Position endPosition = Position(textNode.release(), start.offsetInContainerNode() + text.length());
    123     setEndingSelectionWithoutValidation(start, endPosition, selectInsertedText);
     125    setEndingSelectionWithoutValidation(start, endPosition);
     126    if (!selectInsertedText)
     127        setEndingSelection(VisibleSelection(endingSelection().visibleEnd(), endingSelection().isDirectional()));
    124128
    125129    return true;
     
    217221    }
    218222
    219     // We could have inserted a part of composed character sequence,
    220     // so we are basically treating ending selection as a range to avoid validation.
    221     // <http://bugs.webkit.org/show_bug.cgi?id=15781>
    222     VisibleSelection forcedEndingSelection;
    223     forcedEndingSelection.setWithoutValidation(startPosition, endPosition);
    224     forcedEndingSelection.setIsDirectional(endingSelection().isDirectional());
    225     setEndingSelection(forcedEndingSelection);
     223    setEndingSelectionWithoutValidation(startPosition, endPosition);
    226224
    227225    // Handle the case where there is a typing style.
  • trunk/Source/WebCore/editing/InsertTextCommand.h

    r146907 r146999  
    7474    bool performTrivialReplace(const String&, bool selectInsertedText);
    7575    bool performOverwrite(const String&, bool selectInsertedText);
    76     void setEndingSelectionWithoutValidation(const Position& startPosition, const Position& endPosition, bool selectInsertedText);
     76    void setEndingSelectionWithoutValidation(const Position& startPosition, const Position& endPosition);
    7777
    7878    friend class TypingCommand;
Note: See TracChangeset for help on using the changeset viewer.