diff --git a/src/MacVim/MMAppController.m b/src/MacVim/MMAppController.m index 8eadcf13c3..dea6e81b05 100644 --- a/src/MacVim/MMAppController.m +++ b/src/MacVim/MMAppController.m @@ -1390,7 +1390,16 @@ fsEventCallback(ConstFSEventStreamRef streamRef, - (MMVimController *)topmostVimController { - // Find the topmost visible window which has an associated vim controller. + // Find the topmost visible window which has an associated vim controller + // as follows: + // + // 1. Search through ordered windows as determined by NSApp. Unfortunately + // this method can fail, e.g. if a full screen window is on another + // "Space" (in this case NSApp returns no windows at all), so we have to + // fall back on ... + // 2. Search through all Vim controllers and return the first visible + // window. + NSEnumerator *e = [[NSApp orderedWindows] objectEnumerator]; id window; while ((window = [e nextObject]) && [window isVisible]) { @@ -1402,6 +1411,14 @@ fsEventCallback(ConstFSEventStreamRef streamRef, } } + unsigned i, count = [vimControllers count]; + for (i = 0; i < count; ++i) { + MMVimController *vc = [vimControllers objectAtIndex:i]; + if ([[[vc windowController] window] isVisible]) { + return vc; + } + } + return nil; }