Skip to content

Commit fe895e0

Browse files
committed
Fix up the previous MacVim's guioptions 'k' implementation
Fix the following: * Zoom button: There was an error in refactoring leading to the handler calling the wrong function. * Toolbar addition/removal: This now respects the 'k' option. Toolbar is different from scrollbar and tabs because when you add/remove a toolbar in Cocoa it automatically resizes the window for you, so the implementation needs to manually un-resize the window and re-calculates the Vim view's 'lines' and 'columns' to fit.
1 parent 0e4db3d commit fe895e0

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

src/MacVim/MMWindowController.m

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,7 @@ - (void)zoomWithRows:(int)rows columns:(int)cols state:(int)state
443443
[self setTextDimensionsWithRows:rows
444444
columns:cols
445445
isLive:NO
446+
keepGUISize:NO
446447
keepOnScreen:YES];
447448

448449
// NOTE: If state==0 then the window should be put in the non-zoomed
@@ -662,6 +663,10 @@ - (void)showToolbar:(BOOL)on size:(int)size mode:(int)mode
662663
// showing its hide animation every time a new window is opened. (See
663664
// processInputQueueDidFinish for the reason why we need to delay toggling
664665
// the toolbar when the window is visible.)
666+
//
667+
// Also, the delayed updateToolbar will have the correct shouldKeepGUISize
668+
// set when it's called, which is important for that function to respect
669+
// guioptions 'k'.
665670
if (![decoratedWindow isVisible])
666671
[self updateToolbar];
667672
}
@@ -1055,7 +1060,14 @@ - (void)windowDidResize:(id)sender
10551060
// may resize automatically) we simply set the view to fill the entire
10561061
// window. The vim view takes care of notifying Vim if the number of
10571062
// (rows,columns) changed.
1058-
[vimView setFrameSize:[self contentSize]];
1063+
if (shouldKeepGUISize) {
1064+
// This happens when code manually call setFrame: when we are performing
1065+
// an operation that wants to preserve GUI size (e.g. in updateToolbar:).
1066+
// Respect the wish, and pass that along.
1067+
[vimView setFrameSizeKeepGUISize:[self contentSize]];
1068+
} else {
1069+
[vimView setFrameSize:[self contentSize]];
1070+
}
10591071
}
10601072

10611073
- (void)windowDidChangeBackingProperties:(NSNotification *)notification
@@ -1607,7 +1619,32 @@ - (void)updateToolbar
16071619

16081620
// Positive flag shows toolbar, negative hides it.
16091621
BOOL on = updateToolbarFlag > 0 ? YES : NO;
1622+
1623+
NSRect origWindowFrame = [decoratedWindow frame];
1624+
BOOL origHasToolbar = decoratedWindow.toolbar != nil;
1625+
16101626
[decoratedWindow setToolbar:(on ? toolbar : nil)];
1627+
1628+
if (shouldKeepGUISize && !fullScreenEnabled && origHasToolbar != on) {
1629+
// "shouldKeepGUISize" means guioptions has 'k' in it, indicating that user doesn't
1630+
// want the window to resize itself. In non-fullscreen when we call setToolbar:
1631+
// Cocoa automatically resizes the window so we need to un-resize it back to
1632+
// original.
1633+
1634+
NSRect newWindowFrame = [decoratedWindow frame];
1635+
if (newWindowFrame.size.height == origWindowFrame.size.height) {
1636+
// This is an odd case here, where the window has not changed size at all.
1637+
// The addition/removal of toolbar should have changed its size. This means that
1638+
// there isn't enough space to grow the window on the screen. Usually we rely
1639+
// on windowDidResize: to call setFrameSizeKeepGUISize for us but now we have
1640+
// to do it manually in this special case.
1641+
[vimView setFrameSizeKeepGUISize:[self contentSize]];
1642+
}
1643+
else {
1644+
[decoratedWindow setFrame:origWindowFrame display:YES];
1645+
}
1646+
}
1647+
16111648
[self updateTablineSeparator];
16121649

16131650
updateToolbarFlag = 0;

0 commit comments

Comments
 (0)