2010-10-28 Jia Pu <jpu@apple.com>
Reviewed by Dan Bernstein.
Editing a word with misspell or autocorrection underline should remove the underline when the editing changes the word.
https://bugs.webkit.org/show_bug.cgi?id=48078
<rdar://problem/8579155>
* platform/mac-leopard/Skipped: New tests don't apply to this platform.
* platform/mac-snowleopard/Skipped: Ditto.
* platform/mac-tiger/Skipped: Ditto.
* platform/mac-wk2/Skipped: Ditto.
* platform/mac/editing/spelling/autocorrection-delete-expected.checksum: Updated expected test result.
* platform/mac/editing/spelling/autocorrection-delete-expected.png: Ditto.
* platform/mac/editing/spelling/editing-multiple-words-with-markers-expected.txt: Added.
* platform/mac/editing/spelling/editing-multiple-words-with-markers.html: Added.
* platform/mac/editing/spelling/editing-word-with-marker-1-expected.txt: Added.
* platform/mac/editing/spelling/editing-word-with-marker-1.html: Added.
* platform/mac/editing/spelling/editing-word-with-marker-2-expected.txt: Added.
* platform/mac/editing/spelling/editing-word-with-marker-2.html: Added.
2010-10-28 Jia Pu <jpu@apple.com>
Reviewed by Dan Bernstein.
Editing a word with misspell or autocorrection underline should remove the underline when the editing changes the word.
https://bugs.webkit.org/show_bug.cgi?id=48078
<rdar://problem/8579155>
Tests: platform/mac/editing/spelling/editing-multiple-words-with-markers.html
platform/mac/editing/spelling/editing-word-with-marker-1.html
platform/mac/editing/spelling/editing-word-with-marker-2.html
This patch is part of on-going improvement of autocorrection feature on Mac OS X. When an editing
occurs, if it affects words (by deleting/inserting characters, spliting word, merging words) that
have Spelling and/or CorrectionIndicator markers, we want to remove the markers. If subsequntial
spelling checking finds spelling error in newlly formed words, it will add the markers back in.
* dom/DocumentMarker.h: Changed MarkerType to bit masks to make search multiple types easier.
* dom/DocumentMarkerController.cpp: Refactored two removeMarkers() methods to support remove
markers with specific type from a node.
(WebCore::DocumentMarkerController::removeMarkers): Changed signature to remove marker with specific type.
(WebCore::DocumentMarkerController::removeMarkersFromMarkerMapVectorPair): Refactoring.
(WebCore::DocumentMarkerController::hasMarkers): Convenience method to search markers in range.
* dom/DocumentMarkerController.h: Added new methods and matched new signature of removeMarkers().
* editing/Editor.cpp:
(WebCore::Editor::respondToChangedContents): Remove existing markers if the change formed new word.
(WebCore::Editor::cut): Remove markers on words that will be modified by this editing.
(WebCore::Editor::paste): Ditto.
(WebCore::Editor::pasteAsPlainText): Ditto.
(WebCore::Editor::removeSpellAndCorrectionMarkersFromWordsToBeEdited): Main logic for removing
markers on words affected by editing.
* editing/Editor.h: Added removeSpellAndCorrectionMarkersFromWordsToBeEdited(). Added
REMOVE_MARKERS_UPON_EDITING and SUPPORT_AUTOCORRECTION_PANEL macro to improve readability.
* editing/TypingCommand.cpp:
(WebCore::TypingCommand::insertText): Remove markers on words that will be modified by this editing.
(WebCore::TypingCommand::deleteKeyPressed): Ditto.
(WebCore::TypingCommand::forwardDeleteKeyPressed): Ditto.
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@70826 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/WebCore/editing/TypingCommand.cpp b/WebCore/editing/TypingCommand.cpp
index 60b3f7b..d78708b 100644
--- a/WebCore/editing/TypingCommand.cpp
+++ b/WebCore/editing/TypingCommand.cpp
@@ -131,14 +131,18 @@
void TypingCommand::insertText(Document* document, const String& text, const VisibleSelection& selectionForInsertion, bool selectInsertedText, bool insertedTextIsComposition)
{
+#if REMOVE_MARKERS_UPON_EDITING
+ if (!text.isEmpty())
+ document->frame()->editor()->removeSpellAndCorrectionMarkersFromWordsToBeEdited(isSpaceOrNewline(text.characters()[0]));
+#endif
+
ASSERT(document);
-
+
RefPtr<Frame> frame = document->frame();
ASSERT(frame);
-
+
VisibleSelection currentSelection = frame->selection()->selection();
bool changeSelection = currentSelection != selectionForInsertion;
-
String newText = text;
Node* startNode = selectionForInsertion.start().node();
@@ -419,9 +423,12 @@
void TypingCommand::deleteKeyPressed(TextGranularity granularity, bool killRing)
{
+#if REMOVE_MARKERS_UPON_EDITING
+ document()->frame()->editor()->removeSpellAndCorrectionMarkersFromWordsToBeEdited(false);
+#endif
VisibleSelection selectionToDelete;
VisibleSelection selectionAfterUndo;
-
+
switch (endingSelection().selectionType()) {
case VisibleSelection::RangeSelection:
selectionToDelete = endingSelection();
@@ -515,6 +522,9 @@
void TypingCommand::forwardDeleteKeyPressed(TextGranularity granularity, bool killRing)
{
+#if REMOVE_MARKERS_UPON_EDITING
+ document()->frame()->editor()->removeSpellAndCorrectionMarkersFromWordsToBeEdited(false);
+#endif
VisibleSelection selectionToDelete;
VisibleSelection selectionAfterUndo;