Changeset 69548 in webkit
- Timestamp:
- Oct 11, 2010 6:21:14 PM (14 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r69546 r69548 1 2010-10-11 Jia Pu <jpu@apple.com> 2 3 Reviewed by Adele Peterson. 4 5 Should commit pending autocorrection before next round of text checking. 6 https://bugs.webkit.org/show_bug.cgi?id=46986 7 <rdar://problem/8424535> 8 9 1. Apply pending autocorrection before calling markAllMisspellingsAndBadGrammarInRanges(). 10 2. Remove unneccessary calls to dismissCorrectionPanel(), since the panel is dismissed when 11 selection changes, which occurs after every typing command. 12 13 * editing/Editor.cpp: 14 (WebCore::Editor::markMisspellingsAfterTypingToPosition): Apply pending autocorrection. 15 (WebCore::Editor::markAllMisspellingsAndBadGrammarInRanges): Store current correction replacement 16 in m_correctionReplacementString. 17 (WebCore::Editor::startCorrectionPanelTimer): Remove call to dismissCorrectionPanel(). 18 * editing/Editor.h: Add m_correctionReplacementString to store proposed autocorrection string. 19 1 20 2010-10-11 Oliver Hunt <oliver@apple.com> 2 21 -
trunk/WebCore/editing/Editor.cpp
r68902 r69548 2405 2405 { 2406 2406 #if PLATFORM(MAC) && !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD) 2407 #if !defined(BUILDING_ON_SNOW_LEOPARD) 2408 // Apply pending autocorrection before next round of spell checking. 2409 bool didApplyCorrection = false; 2410 if (m_rangeToBeReplacedByCorrection) { 2411 ExceptionCode ec = 0; 2412 RefPtr<Range> paragraphRangeContainingCorrection = m_rangeToBeReplacedByCorrection->cloneRange(ec); 2413 if (!ec) { 2414 setStart(paragraphRangeContainingCorrection.get(), startOfParagraph(m_rangeToBeReplacedByCorrection->startPosition())); 2415 setEnd(paragraphRangeContainingCorrection.get(), endOfParagraph(m_rangeToBeReplacedByCorrection->endPosition())); 2416 // After we replace the word at range m_rangeToBeReplacedByCorrection, we need to add 2417 // autocorrection underline at that range. However, once the replacement took place, the 2418 // value of m_rangeToBeReplacedByCorrection is not valid anymore. So before we carry out 2419 // the replacement, we need to store the start position of m_rangeToBeReplacedByCorrection 2420 // relative to the start position of the containing paragraph. We use correctionStartOffsetInParagraph 2421 // to store this value. In order to obtain this offset, we need to first create a range 2422 // which spans from the start of paragraph to the start position of m_rangeToBeReplacedByCorrection. 2423 RefPtr<Range> correctionStartOffsetInParagraphAsRange = Range::create(paragraphRangeContainingCorrection->startContainer(ec)->document(), paragraphRangeContainingCorrection->startPosition(), paragraphRangeContainingCorrection->startPosition()); 2424 if (!ec) { 2425 Position startPositionOfRangeToBeReplaced = m_rangeToBeReplacedByCorrection->startPosition(); 2426 correctionStartOffsetInParagraphAsRange->setEnd(startPositionOfRangeToBeReplaced.containerNode(), startPositionOfRangeToBeReplaced.computeOffsetInContainerNode(), ec); 2427 if (!ec) { 2428 // Take note of the location of autocorrection so that we can add marker after the replacement took place. 2429 int correctionStartOffsetInParagraph = TextIterator::rangeLength(correctionStartOffsetInParagraphAsRange.get()); 2430 Position caretPosition = m_frame->selection()->selection().end(); 2431 RefPtr<Range> rangeToBeReplaced = m_rangeToBeReplacedByCorrection->cloneRange(ec); 2432 VisibleSelection selectionToReplace(rangeToBeReplaced.get(), DOWNSTREAM); 2433 if (m_frame->selection()->shouldChangeSelection(selectionToReplace)) { 2434 m_frame->selection()->setSelection(selectionToReplace); 2435 replaceSelectionWithText(m_correctionReplacementString, false, false); 2436 caretPosition.moveToOffset(caretPosition.offsetInContainerNode() + m_correctionReplacementString.length() - m_stringToBeReplacedByCorrection.length()); 2437 RefPtr<Range> replacementRange = TextIterator::subrange(paragraphRangeContainingCorrection.get(), correctionStartOffsetInParagraph, m_correctionReplacementString.length()); 2438 replacementRange->startContainer()->document()->markers()->addMarker(replacementRange.get(), DocumentMarker::Replacement, m_correctionReplacementString); 2439 replacementRange->startContainer()->document()->markers()->addMarker(replacementRange.get(), DocumentMarker::CorrectionIndicator); 2440 m_frame->selection()->moveTo(caretPosition, false); 2441 didApplyCorrection = true; 2442 } 2443 } 2444 } 2445 } 2446 m_rangeToBeReplacedByCorrection.release(); 2447 } 2448 #endif 2449 2407 2450 TextCheckingOptions textCheckingOptions = 0; 2408 2451 if (isContinuousSpellCheckingEnabled()) … … 2755 2798 m_rangeToBeReplacedByCorrection = rangeToReplace; 2756 2799 m_stringToBeReplacedByCorrection = replacedString; 2800 m_correctionReplacementString = result->replacement; 2757 2801 client()->showCorrectionPanel(totalBoundingBox, m_stringToBeReplacedByCorrection, result->replacement, this); 2758 2802 doReplacement = false; … … 2766 2810 selectionOffset += replacementLength - resultLength; 2767 2811 if (result->type == TextCheckingTypeCorrection) { 2768 #if PLATFORM(MAC) && !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD) && !defined(BUILDING_ON_SNOW_LEOPARD)2769 if (client())2770 client()->dismissCorrectionPanel(true);2771 #endif2772 2812 // Add a marker so that corrections can easily be undone and won't be re-corrected. 2773 2813 RefPtr<Range> replacedRange = TextIterator::subrange(paragraphRange.get(), resultLocation, replacementLength); … … 2858 2898 #if PLATFORM(MAC) && !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD) && !defined(BUILDING_ON_SNOW_LEOPARD) 2859 2899 static const double correctionPanelTimerInterval = 0.3; 2860 if (client())2861 client()->dismissCorrectionPanel(true);2862 2900 if (isAutomaticSpellingCorrectionEnabled()) 2863 2901 m_correctionPanelTimer.startOneShot(correctionPanelTimerInterval); -
trunk/WebCore/editing/Editor.h
r68670 r69548 380 380 RefPtr<Range> m_rangeToBeReplacedByCorrection; 381 381 String m_stringToBeReplacedByCorrection; 382 String m_correctionReplacementString; 382 383 Timer<Editor> m_correctionPanelTimer; 383 384 VisibleSelection m_mark;
Note: See TracChangeset
for help on using the changeset viewer.