Revision: 23885
          http://sourceforge.net/p/bibdesk/svn/23885
Author:   hofman
Date:     2019-06-20 14:43:47 +0000 (Thu, 20 Jun 2019)
Log Message:
-----------
make our own text editor for type select helper rather than reusing the field 
editor, so we can properly hand it over if needed

Modified Paths:
--------------
    trunk/bibdesk/BDSKTypeSelectHelper.m

Modified: trunk/bibdesk/BDSKTypeSelectHelper.m
===================================================================
--- trunk/bibdesk/BDSKTypeSelectHelper.m        2019-06-20 14:04:21 UTC (rev 
23884)
+++ trunk/bibdesk/BDSKTypeSelectHelper.m        2019-06-20 14:43:47 UTC (rev 
23885)
@@ -64,6 +64,7 @@
 - (void)stopObserving;
 - (NSTimeInterval)timeoutInterval;
 - (NSUInteger)indexOfMatchedItemAfterIndex:(NSUInteger)selectedIndex;
+- (NSTextView *)editor;
 
 @end
 
@@ -157,7 +158,7 @@
 - (void)searchWithEvent:(NSEvent *)keyEvent;
 {
     NSWindow *window = [NSApp keyWindow];
-    NSText *fieldEditor = [window fieldEditor:YES forObject:self];
+    NSText *editor = [self editor];
     
     if (processing == NO) {
         [self stopObserving];
@@ -165,14 +166,30 @@
         [[NSNotificationCenter defaultCenter] addObserver:self 
selector:@selector(typeSelectSearchTimeout:) name:NSWindowWillCloseNotification 
object:window];
         [window addObserver:self forKeyPath:@"firstResponder" options:0 
context:&BDSKTypeSelectHelperObservationContext];
         observedWindow = [window retain];
-        [fieldEditor setDelegate:self];
-        [fieldEditor setString:@""];
+        if ([editor delegate])
+            [(BDSKTypeSelectHelper *)[editor delegate] 
typeSelectSearchTimeout:nil];
+        [editor setDelegate:self];
+        if ([(id<NSTextInputClient>)editor hasMarkedText]) {
+            // we pass a dummy key event to the field editor to clear any 
hanging dead keys (marked text)
+            NSEvent *dummyKeyEvent = [NSEvent keyEventWithType:NSKeyDown
+                                                 location:NSZeroPoint
+                                            modifierFlags:0
+                                                timestamp:0
+                                             windowNumber:0
+                                                  context:nil
+                                               characters:@""
+                              charactersIgnoringModifiers:@""
+                                                isARepeat:NO
+                                                  keyCode:0];
+            [editor interpretKeyEvents:[NSArray 
arrayWithObject:dummyKeyEvent]];
+        }
+        [editor setString:@""];
     }
     
     // Append the new character to the search string
-    [fieldEditor interpretKeyEvents:[NSArray arrayWithObject:keyEvent]];
+    [editor interpretKeyEvents:[NSArray arrayWithObject:keyEvent]];
     [searchString release];
-    searchString = [[fieldEditor string] retain];
+    searchString = [[editor string] retain];
     
     if ([delegate 
respondsToSelector:@selector(typeSelectHelper:updateSearchString:)])
         [delegate typeSelectHelper:self updateSearchString:searchString];
@@ -245,6 +262,15 @@
 
 @implementation BDSKTypeSelectHelper (BDSKPrivate)
 
+- (NSTextView *)editor {
+    static NSTextView *editor = nil;
+    if (editor == nil) {
+        editor = [[NSTextView alloc] init];
+        [editor setFieldEditor:YES];
+    }
+    return editor;
+}
+
 - (NSArray *)searchCache;
 {
     if (searchCache == nil)
@@ -273,24 +299,9 @@
     [self stopTimer];
     processing = NO;
     
-    NSTextView *fieldEditor = (NSTextView *)[[NSApp keyWindow] fieldEditor:YES 
forObject:self];
-    if ([fieldEditor delegate] == self) {
-        if ([fieldEditor hasMarkedText]) {
-            // we pass a dummy key event to the field editor to clear any 
hanging dead keys (marked text)
-            NSEvent *keyEvent = [NSEvent keyEventWithType:NSKeyDown
-                                                 location:NSZeroPoint
-                                            modifierFlags:0
-                                                timestamp:0
-                                             windowNumber:0
-                                                  context:nil
-                                               characters:@""
-                              charactersIgnoringModifiers:@""
-                                                isARepeat:NO
-                                                  keyCode:0];
-            [fieldEditor interpretKeyEvents:[NSArray 
arrayWithObject:keyEvent]];
-        }
-        [fieldEditor setDelegate:nil];
-    }
+    NSTextView *editor = [self editor];
+    if ([editor delegate] == self)
+        [editor setDelegate:nil];
 }
 
 // See 
http://www.mactech.com/articles/mactech/Vol.18/18.10/1810TableTechniques/index.html

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.



_______________________________________________
Bibdesk-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit

Reply via email to