From 1cb9a4ffb9dae87fdf5162a9b24fa24bb881bf25 Mon Sep 17 00:00:00 2001 From: Bjorn Winckler Date: Thu, 30 Dec 2010 15:31:22 +0100 Subject: [PATCH] Fix file open problem in full screen with Spaces This fixes a problem when a full screen window was on another Space and files were set to open in the topmost window. Previously, this caused a new window to open on the current Space instead of opening the file in the full screen window on the other Space. --- src/MacVim/MMAppController.m | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) 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; }