[Webkit-unassigned] [Bug 24953] Add automatic spell correction support in WebKit

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Tue Apr 7 22:13:12 PDT 2009


https://bugs.webkit.org/show_bug.cgi?id=24953





------- Comment #3 from justin.garcia at apple.com  2009-04-07 22:13 PDT -------
-static String findFirstMisspellingInRange(EditorClient* client, Range*
searchRange, int& firstMisspellingOffset, bool markAll)
+static String findFirstMisspellingInRange(EditorClient* client, Range*
searchRange, int& firstMisspellingOffset, bool markAll, int&
firstMisspellingCharCount)
 {

Why do we need to introduce firstMisspellingCharCount?  Can't callers just
check the length of the returned string?


+            Frame* frame = document()->frame();
+            if (frame)
+              frame->editor()->markMisspellingsAfterTypingToPosition(p1,
firstMisspelledCharOffset, firstMisspelledCharCount);
+
+            // Autocorrect the misspelled word.
+            if (firstMisspelledCharCount > 0 && frame) {

Not sure what the surrounding code does but can frame really be null here?  If
it really can and we need to check it it would be nice if you used early
returns in the event that the frame is null, to avoid so many levels of if
nesting.


+                WebCore::VisibleSelection selection =
VisibleSelection(startOfWord(p1, LeftWordIfOnBoundary), endOfWord(p1,
RightWordIfOnBoundary));

You're already inside the WebCore namespace, you don't need the WebCore::


+                // Find the exact selection of the misspelled word.
+                WebCore::VisibleSelection selection =
VisibleSelection(startOfWord(p1, LeftWordIfOnBoundary), endOfWord(p1,
RightWordIfOnBoundary));
+                RefPtr<Range> searchRange(selection.toNormalizedRange());
+                RefPtr<Range> misspellingRange =
TextIterator::subrange(searchRange.get(), firstMisspelledCharOffset,
firstMisspelledCharCount);
+                
+                // Get the misspelled word.
+                const String misspelledWord =
plainText(misspellingRange.get());

This is work that we've already done when we call
markMisspellingsAfterTypingToPosition.  Inside findFirstMisspellingInRange we
have a) the characters for the misspelled word and b) the misspelling range.


frame->editor()->client()->getAutoCorrectSuggestionForMisspelledWord(misspelledWord,
autocorrectedString);

Why not have this function return the autocorrected string?


+                   
frame->editor()->replaceSelectionWithText(autocorrectedString, true, true);

I don't think you want to select the autocorrected word.  The idea I think is
that autocorrect should not be disruptive, the user should be able to continue
typing without stopping.


-- 
Configure bugmail: https://bugs.webkit.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.



More information about the webkit-unassigned mailing list