Title: [195547] trunk/Source
Revision
195547
Author
[email protected]
Date
2016-01-25 12:29:53 -0800 (Mon, 25 Jan 2016)

Log Message

Handle soft spaces after accepted candidates
https://bugs.webkit.org/show_bug.cgi?id=153331
-and corresponding-
rdar://problem/23958418

Reviewed by Darin Adler.

Source/WebCore:

Candidates now come with built-in spaces, so we should not insert a space for 
them.
* editing/Editor.cpp:
(WebCore::Editor::handleAcceptedCandidate):

New SPI to properly handle these soft spaces.
* platform/spi/mac/NSSpellCheckerSPI.h:

Source/WebKit2:

New member variable m_softSpaceRange keeps track to the NSRange of a soft 
space if the last text that was inserted has a soft space at the end.
* UIProcess/Cocoa/WebViewImpl.h:
* UIProcess/Cocoa/WebViewImpl.mm:
(WebKit::WebViewImpl::WebViewImpl):

The space at the end of candidates is a soft space. If that space exists, 
cache the range of the space in m_softSpaceRange.
(WebKit::WebViewImpl::handleAcceptedCandidate):

When new text is inserted, find out if it is being inserted right after a 
soft space. If it is, then [NSSpellChecker deletesAutospaceBeforeString] will 
tell us if the space needs to be removed. If that is the case, then set the 
replacementString to the soft space.
(WebKit::WebViewImpl::insertText):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (195546 => 195547)


--- trunk/Source/WebCore/ChangeLog	2016-01-25 20:25:08 UTC (rev 195546)
+++ trunk/Source/WebCore/ChangeLog	2016-01-25 20:29:53 UTC (rev 195547)
@@ -1,3 +1,20 @@
+2016-01-25  Beth Dakin  <[email protected]>
+
+        Handle soft spaces after accepted candidates
+        https://bugs.webkit.org/show_bug.cgi?id=153331
+        -and corresponding-
+        rdar://problem/23958418
+
+        Reviewed by Darin Adler.
+
+        Candidates now come with built-in spaces, so we should not insert a space for 
+        them.
+        * editing/Editor.cpp:
+        (WebCore::Editor::handleAcceptedCandidate):
+
+        New SPI to properly handle these soft spaces.
+        * platform/spi/mac/NSSpellCheckerSPI.h:
+
 2016-01-25  Alex Christensen  <[email protected]>
 
         [Win] Copy forwarding headers before building a project

Modified: trunk/Source/WebCore/editing/Editor.cpp (195546 => 195547)


--- trunk/Source/WebCore/editing/Editor.cpp	2016-01-25 20:25:08 UTC (rev 195546)
+++ trunk/Source/WebCore/editing/Editor.cpp	2016-01-25 20:29:53 UTC (rev 195547)
@@ -3562,7 +3562,10 @@
         m_frame.selection().setSelectedRange(candidateRange.get(), UPSTREAM, true);
 
     insertText(acceptedCandidate.replacement, 0);
-    insertText(String(" "), 0);
+
+    // Some candidates come with a space built in, and we do not need to add another space in that case.
+    if (!acceptedCandidate.replacement.endsWith(' '))
+        insertText(ASCIILiteral(" "), 0);
 }
 
 bool Editor::unifiedTextCheckerEnabled() const

Modified: trunk/Source/WebCore/platform/spi/mac/NSSpellCheckerSPI.h (195546 => 195547)


--- trunk/Source/WebCore/platform/spi/mac/NSSpellCheckerSPI.h	2016-01-25 20:25:08 UTC (rev 195546)
+++ trunk/Source/WebCore/platform/spi/mac/NSSpellCheckerSPI.h	2016-01-25 20:29:53 UTC (rev 195547)
@@ -31,6 +31,7 @@
 
 @interface NSSpellChecker ()
 - (NSInteger)requestCandidatesForSelectedRange:(NSRange)selectedRange inString:(NSString *)stringToCheck types:(NSTextCheckingTypes)checkingTypes options:(NSDictionary<NSString *, id> *)options inSpellDocumentWithTag:(NSInteger)tag completionHandler:(void (^)(NSInteger sequenceNumber, NSArray<NSTextCheckingResult *> *candidates))completionHandler;
+- (BOOL)deletesAutospaceBeforeString:(NSString *)string language:(NSString *)language;
 @end
 
 #endif // PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 102000

Modified: trunk/Source/WebKit2/ChangeLog (195546 => 195547)


--- trunk/Source/WebKit2/ChangeLog	2016-01-25 20:25:08 UTC (rev 195546)
+++ trunk/Source/WebKit2/ChangeLog	2016-01-25 20:29:53 UTC (rev 195547)
@@ -1,3 +1,28 @@
+2016-01-25  Beth Dakin  <[email protected]>
+
+        Handle soft spaces after accepted candidates
+        https://bugs.webkit.org/show_bug.cgi?id=153331
+        -and corresponding-
+        rdar://problem/23958418
+
+        Reviewed by Darin Adler.
+
+        New member variable m_softSpaceRange keeps track to the NSRange of a soft 
+        space if the last text that was inserted has a soft space at the end.
+        * UIProcess/Cocoa/WebViewImpl.h:
+        * UIProcess/Cocoa/WebViewImpl.mm:
+        (WebKit::WebViewImpl::WebViewImpl):
+
+        The space at the end of candidates is a soft space. If that space exists, 
+        cache the range of the space in m_softSpaceRange.
+        (WebKit::WebViewImpl::handleAcceptedCandidate):
+
+        When new text is inserted, find out if it is being inserted right after a 
+        soft space. If it is, then [NSSpellChecker deletesAutospaceBeforeString] will 
+        tell us if the space needs to be removed. If that is the case, then set the 
+        replacementString to the soft space.
+        (WebKit::WebViewImpl::insertText):
+
 2016-01-25  Daniel Bates  <[email protected]>
 
         WebKitTestRunner: Credential cache is not cleared between tests

Modified: trunk/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.h (195546 => 195547)


--- trunk/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.h	2016-01-25 20:25:08 UTC (rev 195546)
+++ trunk/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.h	2016-01-25 20:29:53 UTC (rev 195547)
@@ -637,6 +637,7 @@
 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200
     String m_lastStringForCandidateRequest;
 #endif
+    NSRange m_softSpaceRange { NSNotFound, 0 };
 };
     
 } // namespace WebKit

Modified: trunk/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.mm (195546 => 195547)


--- trunk/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.mm	2016-01-25 20:25:08 UTC (rev 195546)
+++ trunk/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.mm	2016-01-25 20:29:53 UTC (rev 195547)
@@ -2210,6 +2210,14 @@
     if (m_lastStringForCandidateRequest != postLayoutData.stringForCandidateRequest)
         return;
 
+    NSRange range = [acceptedCandidate range];
+    if (acceptedCandidate.replacementString && [acceptedCandidate.replacementString length] > 0) {
+        NSRange replacedRange = NSMakeRange(range.location, [acceptedCandidate.replacementString length]);
+        NSRange softSpaceRange = NSMakeRange(NSMaxRange(replacedRange) - 1, 1);
+        if ([acceptedCandidate.replacementString hasSuffix:@" "])
+            m_softSpaceRange = softSpaceRange;
+    }
+
     m_page->handleAcceptedCandidate(textCheckingResultFromNSTextCheckingResult(acceptedCandidate));
 }
 #endif // __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200
@@ -3511,13 +3519,22 @@
     } else
         text = string;
 
+    BOOL needToRemoveSoftSpace = NO;
+#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200
+    if (m_softSpaceRange.location != NSNotFound && (replacementRange.location == NSMaxRange(m_softSpaceRange) || replacementRange.location == NSNotFound) && replacementRange.length == 0 && [[NSSpellChecker sharedSpellChecker] deletesAutospaceBeforeString:text language:nil]) {
+        replacementRange = m_softSpaceRange;
+        needToRemoveSoftSpace = YES;
+    }
+#endif
+    m_softSpaceRange = NSMakeRange(NSNotFound, 0);
+
     // insertText can be called for several reasons:
     // - If it's from normal key event processing (including key bindings), we save the action to perform it later.
     // - If it's from an input method, then we should insert the text now.
     // - If it's sent outside of keyboard event processing (e.g. from Character Viewer, or when confirming an inline input area with a mouse),
     // then we also execute it immediately, as there will be no other chance.
     Vector<WebCore::KeypressCommand>* keypressCommands = m_collectedKeypressCommands;
-    if (keypressCommands) {
+    if (keypressCommands && !needToRemoveSoftSpace) {
         ASSERT(replacementRange.location == NSNotFound);
         WebCore::KeypressCommand command("insertText:", text);
         keypressCommands->append(command);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to