Commented out Chrome-specific code (possibly temporary)

This commit is contained in:
Tom Bogle 2018-01-12 11:52:44 -05:00
parent 78be3af7d3
commit 0d7a519220
5 changed files with 92 additions and 78 deletions

View file

@ -63,12 +63,10 @@ KMInputMethodEventHandler* _eventHandler;
if ([clientAppId isEqual: @"com.apple.Safari"]) {
_eventHandler = [[KMInputMethodSafariClientEventHandler alloc] init];
}
else if ([clientAppId isEqual: @"org.mozilla.firefox"]) {
else if ([clientAppId isEqual: @"org.mozilla.firefox"] ||
[clientAppId isEqual: @"com.google.Chrome"]) {
_eventHandler = [[KMInputMethodBrowserClientEventHandler alloc] init];
}
else if ([clientAppId isEqual: @"com.google.Chrome"]) {
_eventHandler = [[KMInputMethodChromeClientEventHandler alloc] init];
}
else
_eventHandler = [[KMInputMethodEventHandler alloc] initWithClient:clientAppId];
}

View file

@ -23,7 +23,7 @@ NSUInteger _failuresToRetrieveExpectedContext;
- (instancetype)initWithLegacyMode:(BOOL)legacy clientSelectionCanChangeUnexpectedly:(BOOL) flagClientSelectionCanChangeUnexpectedly {
self = [super initWithLegacyMode:legacy clientSelectionCanChangeUnexpectedly: flagClientSelectionCanChangeUnexpectedly];
if (self) {
_couldBeInGoogleDocs = NO;
// _couldBeInGoogleDocs = YES;
_failuresToRetrieveExpectedContext = 0;
}
return self;
@ -48,27 +48,41 @@ NSUInteger _failuresToRetrieveExpectedContext;
{
// Client is failing to provide useful response to attributedSubstringFromRange.
// Word (in MS Live) occasionally does this, but (apparently) Google Docs doesn't.
_couldBeInGoogleDocs = NO;
//_couldBeInGoogleDocs = NO;
[self setInSiteThatDoesNotGiveContext];
}
else if (!clientContext.length ||
[clientContext characterAtIndex:clientContext.length - 1] !=
[self.contextBuffer characterAtIndex:bufferLength - 1]) {
else if (!clientContext.length) {
if ([self AppDelegate].debugMode) {
NSLog(@"Expected context = '%@'", self.contextBuffer);
NSLog(@"Actual clientContext = '%@'", (clientContext == nil ? @"{nil}" : clientContext));
uint32_t codepoint = [clientContext characterAtIndex:clientContext.length - 1];
NSLog(@"Last character in clientContext = '%lu'", (unsigned long)codepoint);
codepoint = [self.contextBuffer characterAtIndex:bufferLength - 1];
NSLog(@"Last character in contextBuffer = '%lu'", (unsigned long)codepoint);
NSLog(@"Actual clientContext was empty");
}
_failuresToRetrieveExpectedContext++;
}
else {
if ([self AppDelegate].debugMode) {
NSLog(@"We got what we were expecting from the client. We can stop checking.");
else
{
unichar lastCodepointExpected = [self.contextBuffer characterAtIndex:bufferLength - 1];
unichar lastCodepointInClient = [clientContext characterAtIndex:clientContext.length - 1];
if (lastCodepointExpected != lastCodepointInClient) {
if ([self AppDelegate].debugMode) {
NSLog(@"Expected context = '%@'", self.contextBuffer);
NSLog(@"Actual clientContext = '%@'", (clientContext == nil ? @"{nil}" : clientContext));
NSLog(@"Last character expected (in contextBuffer) = '%lu'", (unsigned long)lastCodepointExpected);
NSLog(@"Last character in clientContext = '%lu'", (unsigned long)lastCodepointInClient);
}
// MS Word converts/reports plain spaces (32) as non-breaking spaces (160). If we
// get this kind of mismatch, we don't want to count this as a definite match, but
// we also don't want to count it as a failure to match. So just wait for a more
// reliable character to test.
if (lastCodepointInClient != 160 || lastCodepointExpected != 32) {
_failuresToRetrieveExpectedContext++;
}
}
else {
if ([self AppDelegate].debugMode) {
NSLog(@"We got what we were expecting from the client. We can stop checking.");
}
_failuresToRetrieveExpectedContext = NSUIntegerMax;
}
_failuresToRetrieveExpectedContext = NSUIntegerMax;
}
}
else {
@ -86,9 +100,9 @@ NSUInteger _failuresToRetrieveExpectedContext;
- (void)setInSiteThatDoesNotGiveContext {
if ([self AppDelegate].debugMode) {
if (_couldBeInGoogleDocs)
NSLog(@"Detected Google Docs or some other editor that can't provide context.");
else
// if (_couldBeInGoogleDocs)
// NSLog(@"Detected Google Docs or some other editor that can't provide context.");
// else
NSLog(@"Detected some editor that can't provide context (not Google Docs).");
}
_failuresToRetrieveExpectedContext = NSUIntegerMax;

View file

@ -11,7 +11,7 @@
@interface KMInputMethodBrowserClientEventHandler ()
@property (assign) BOOL couldBeInGoogleDocs;
//@property (assign) BOOL couldBeInGoogleDocs;
- (void)setInSiteThatDoesNotGiveContext;

View file

@ -6,12 +6,13 @@
// Created by tom on 1/9/18.
// Copyright © 2018 SIL International. All rights reserved.
//
//
//#ifndef KMInputMethodChromeClientEventHandler_h
//#define KMInputMethodChromeClientEventHandler_h
//#import "KMInputMethodBrowserClientEventHandler.h"
//
//@interface KMInputMethodChromeClientEventHandler : KMInputMethodBrowserClientEventHandler
//@end
//
//#endif /* KMInputMethodChromeClientEventHandler_h */
#ifndef KMInputMethodChromeClientEventHandler_h
#define KMInputMethodChromeClientEventHandler_h
#import "KMInputMethodBrowserClientEventHandler.h"
@interface KMInputMethodChromeClientEventHandler : KMInputMethodBrowserClientEventHandler
@end
#endif /* KMInputMethodChromeClientEventHandler_h */

View file

@ -6,52 +6,53 @@
// Copyright © 2018 SIL International. All rights reserved.
//
#import "KMInputMethodChromeClientEventHandler.h"
#import "KMInputMethodEventHandlerProtected.h"
#import "KMInputMethodBrowserClientEventHandlerProtected.h"
//#import "KMInputMethodChromeClientEventHandler.h"
//#import "KMInputMethodEventHandlerProtected.h"
//#import "KMInputMethodBrowserClientEventHandlerProtected.h"
//
//@implementation KMInputMethodChromeClientEventHandler
//
//// Because Google Docs can't report its context, if we detect that we are in Google Docs, we change to
//// NOT assume that it needs to re-get the context every time around (which means that if the user
//// does mouse-click somewhere else, it could lead to bad behaviour).
//BOOL _insertCharactersIndividually;
//
//- (instancetype)init {
// self = [super init];
// if (self) {
// _insertCharactersIndividually = NO;
// }
// return self;
//}
//
//- (void)setInSiteThatDoesNotGiveContext {
// [super setInSiteThatDoesNotGiveContext];
// if ([self couldBeInGoogleDocs]) {
// // Google docs in Chrome allows only a single character at a time :-(
// _insertCharactersIndividually = YES;
// }
//}
//
//- (void)insertPendingBufferTextIn:(id)client {
//
// NSString* remainingText = @"";
// if (_insertCharactersIndividually) {
// NSUInteger length = [self pendingBuffer].length;
// if (length > 1) {
// if ([self.AppDelegate debugMode])
// NSLog(@"Using special Google Docs in Chrome logic (length = %lu)", length);
// remainingText = [self.pendingBuffer substringFromIndex:1];
// [self.pendingBuffer deleteLastNChars:length - 1];
// }
// }
//
// [super insertPendingBufferTextIn:client];
//
// if ([remainingText length] > 0) {
// // Reset the pending buffer to contain remaining characters and issue call to come back for more...
// [self setPendingBuffer:remainingText];
// [self performSelector:@selector(initiatePendingBufferProcessing:) withObject:client afterDelay:0.1];
// }
//}
//@end
@implementation KMInputMethodChromeClientEventHandler
// Because Google Docs can't report its context, if we detect that we are in Google Docs, we change to
// NOT assume that it needs to re-get the context every time around (which means that if the user
// does mouse-click somewhere else, it could lead to bad behaviour).
BOOL _insertCharactersIndividually;
- (instancetype)init {
self = [super init];
if (self) {
_insertCharactersIndividually = NO;
}
return self;
}
- (void)setInSiteThatDoesNotGiveContext {
[super setInSiteThatDoesNotGiveContext];
if ([self couldBeInGoogleDocs]) {
// Google docs in Chrome allows only a single character at a time :-(
_insertCharactersIndividually = YES;
}
}
- (void)insertPendingBufferTextIn:(id)client {
NSString* remainingText = @"";
if (_insertCharactersIndividually) {
NSUInteger length = [self pendingBuffer].length;
if (length > 1) {
if ([self.AppDelegate debugMode])
NSLog(@"Using special Google Docs in Chrome logic (length = %lu)", length);
remainingText = [self.pendingBuffer substringFromIndex:1];
[self.pendingBuffer deleteLastNChars:length - 1];
}
}
[super insertPendingBufferTextIn:client];
if ([remainingText length] > 0) {
// Reset the pending buffer to contain remaining characters and issue call to come back for more...
[self setPendingBuffer:remainingText];
[self performSelector:@selector(initiatePendingBufferProcessing:) withObject:client afterDelay:0.1];
}
}
@end