Changeset 148306 in webkit


Ignore:
Timestamp:
Apr 12, 2013 3:46:01 PM (11 years ago)
Author:
rniwa@webkit.org
Message:

[Mac] REGRESSION: Auto substitution strips new lines
https://bugs.webkit.org/show_bug.cgi?id=114537

Reviewed by Enrica Casucci.

Source/WebCore:

The bug was caused by SpellingCorrectionCommand's use of InsertTextCommand. This command can't insert
new lines and there's even an assertion for it. Use TypingCommand::insertText instead.

Since TypingCommand::insertText calls appliedEditing on its own, we need to avoid calling that again in
CompositeEditCommand::apply after SpellingCorrectionCommand::doApply. Replaced the check in apply to use
callsAppliedEditingInDoApply instead of isTypingCommand, and added callsAppliedEditingInDoApply to both
TypingCommand and SpellingCorrectionCommand to return true (it returns false by default).

Test: platform/mac/editing/spelling/autocorrection-with-multi-line-text.html

  • editing/CompositeEditCommand.cpp:

(WebCore::CompositeEditCommand::apply): Use TypingCommand::insertText instead of InsertTextCommand
(WebCore::CompositeEditCommand::callsAppliedEditingInDoApply): Added. Returns false.

  • editing/CompositeEditCommand.h:

(CompositeEditCommand):

  • editing/SpellingCorrectionCommand.cpp:

(WebCore::SpellingCorrectionCommand::doApply):
(WebCore::SpellingCorrectionCommand::callsAppliedEditingInDoApply): Added. Returns true.

  • editing/SpellingCorrectionCommand.h:

(SpellingCorrectionCommand):

  • editing/TypingCommand.cpp:

(WebCore::TypingCommand::callsAppliedEditingInDoApply): Added. Returns true.

  • editing/TypingCommand.h:

(TypingCommand):

Tools:

Add a rule to replace "helloleworld" by "hello\nworld" for testing purpose.

  • DumpRenderTree/mac/DumpRenderTree.mm:

(resetDefaultsToConsistentValues):

LayoutTests:

Added a regression test. Unfortunately, we can't setup text substituion in DumpRenderTree
so use NSSpellChecker to exercise the relevant code path.

  • platform/mac/editing/spelling/autocorrection-with-multi-line-text-expected.txt: Added.
  • platform/mac/editing/spelling/autocorrection-with-multi-line-text.html: Added.
Location:
trunk
Files:
2 added
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r148289 r148306  
     12013-04-12  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        [Mac] REGRESSION: Auto substitution strips new lines
     4        https://bugs.webkit.org/show_bug.cgi?id=114537
     5
     6        Reviewed by Enrica Casucci.
     7
     8        Added a regression test. Unfortunately, we can't setup text substituion in DumpRenderTree
     9        so use NSSpellChecker to exercise the relevant code path.
     10
     11        * platform/mac/editing/spelling/autocorrection-with-multi-line-text-expected.txt: Added.
     12        * platform/mac/editing/spelling/autocorrection-with-multi-line-text.html: Added.
     13
    1142013-04-12  Commit Queue  <rniwa@webkit.org>
    215
  • trunk/Source/WebCore/ChangeLog

    r148305 r148306  
     12013-04-12  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        [Mac] REGRESSION: Auto substitution strips new lines
     4        https://bugs.webkit.org/show_bug.cgi?id=114537
     5
     6        Reviewed by Enrica Casucci.
     7
     8        The bug was caused by SpellingCorrectionCommand's use of InsertTextCommand. This command can't insert
     9        new lines and there's even an assertion for it. Use TypingCommand::insertText instead.
     10
     11        Since TypingCommand::insertText calls appliedEditing on its own, we need to avoid calling that again in
     12        CompositeEditCommand::apply after SpellingCorrectionCommand::doApply. Replaced the check in apply to use
     13        callsAppliedEditingInDoApply instead of isTypingCommand, and added callsAppliedEditingInDoApply to both
     14        TypingCommand and SpellingCorrectionCommand to return true (it returns false by default).
     15
     16        Test: platform/mac/editing/spelling/autocorrection-with-multi-line-text.html
     17
     18        * editing/CompositeEditCommand.cpp:
     19        (WebCore::CompositeEditCommand::apply): Use TypingCommand::insertText instead of InsertTextCommand
     20        (WebCore::CompositeEditCommand::callsAppliedEditingInDoApply): Added. Returns false.
     21        * editing/CompositeEditCommand.h:
     22        (CompositeEditCommand):
     23        * editing/SpellingCorrectionCommand.cpp:
     24        (WebCore::SpellingCorrectionCommand::doApply):
     25        (WebCore::SpellingCorrectionCommand::callsAppliedEditingInDoApply): Added. Returns true.
     26        * editing/SpellingCorrectionCommand.h:
     27        (SpellingCorrectionCommand):
     28        * editing/TypingCommand.cpp:
     29        (WebCore::TypingCommand::callsAppliedEditingInDoApply): Added. Returns true.
     30        * editing/TypingCommand.h:
     31        (TypingCommand):
     32
    1332013-04-12  Brendan Long  <b.long@cablelabs.com>
    234
  • trunk/Source/WebCore/editing/CompositeEditCommand.cpp

    r146907 r148306  
    217217    // Only need to call appliedEditing for top-level commands,
    218218    // and TypingCommands do it on their own (see TypingCommand::typingAddedToOpenCommand).
    219     if (!isTypingCommand())
     219    if (!callsAppliedEditingInDoApply())
    220220        frame->editor()->appliedEditing(this);
    221221    setShouldRetainAutocorrectionIndicator(false);
     
    243243
    244244bool CompositeEditCommand::isTypingCommand() const
     245{
     246    return false;
     247}
     248
     249bool CompositeEditCommand::callsAppliedEditingInDoApply() const
    245250{
    246251    return false;
  • trunk/Source/WebCore/editing/CompositeEditCommand.h

    r133820 r148306  
    8383    virtual bool isCreateLinkCommand() const;
    8484    virtual bool isTypingCommand() const;
     85    virtual bool callsAppliedEditingInDoApply() const;
    8586    virtual bool isDictationCommand() const { return false; }
    8687    virtual bool preservesTypingStyle() const;
  • trunk/Source/WebCore/editing/SpellingCorrectionCommand.cpp

    r122176 r148306  
    3131#include "DocumentFragment.h"
    3232#include "Frame.h"
    33 #include "InsertTextCommand.h"
    3433#include "SetSelectionCommand.h"
    3534#include "TextIterator.h"
     35#include "TypingCommand.h"
    3636#include "markup.h"
    3737
     
    102102    applyCommandToComposite(SpellingCorrectionRecordUndoCommand::create(document(), m_corrected, m_correction));
    103103#endif
    104     applyCommandToComposite(InsertTextCommand::create(document(), m_correction));
     104    TypingCommand::insertText(document(), m_correction, TypingCommand::PreventSpellChecking);
    105105}
    106106
     
    110110}
    111111
     112bool SpellingCorrectionCommand::callsAppliedEditingInDoApply() const
     113{
     114    return true;
     115}
     116
    112117} // namespace WebCore
  • trunk/Source/WebCore/editing/SpellingCorrectionCommand.h

    r80023 r148306  
    4242    virtual void doApply();
    4343    virtual bool shouldRetainAutocorrectionIndicator() const;
     44    virtual bool callsAppliedEditingInDoApply() const;
    4445
    4546    RefPtr<Range> m_rangeToBeCorrected;
  • trunk/Source/WebCore/editing/TypingCommand.cpp

    r145871 r148306  
    646646}
    647647
     648bool TypingCommand::callsAppliedEditingInDoApply() const
     649{
     650    return true;
     651}
     652
    648653} // namespace WebCore
  • trunk/Source/WebCore/editing/TypingCommand.h

    r114220 r148306  
    101101    virtual EditAction editingAction() const;
    102102    virtual bool isTypingCommand() const;
     103    virtual bool callsAppliedEditingInDoApply() const;
    103104    virtual bool preservesTypingStyle() const { return m_preservesTypingStyle; }
    104105    virtual bool shouldRetainAutocorrectionIndicator() const
  • trunk/Tools/ChangeLog

    r148299 r148306  
     12013-04-12  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        [Mac] REGRESSION: Auto substitution strips new lines
     4        https://bugs.webkit.org/show_bug.cgi?id=114537
     5
     6        Reviewed by Enrica Casucci.
     7
     8        Add a rule to replace "helloleworld" by "hello\nworld" for testing purpose.
     9
     10        * DumpRenderTree/mac/DumpRenderTree.mm:
     11        (resetDefaultsToConsistentValues):
     12
    1132013-04-09  Roger Fong  <roger_fong@apple.com>
    214
  • trunk/Tools/DumpRenderTree/mac/DumpRenderTree.mm

    r148282 r148306  
    607607        @"would", @"wouldn",
    608608        @"welcome", @"wellcome",
    609         @"uppercase", @"upper case",
     609        @"hello\nworld", @"hellolfworld",
    610610        nil] forKey:@"NSTestCorrectionDictionary"];
    611611#endif
Note: See TracChangeset for help on using the changeset viewer.