@@ -86,7 +86,6 @@ - (void)resizeWindowToFitContentSize:(NSSize)contentSize
8686 keepOnScreen : (BOOL )onScreen ;
8787- (NSSize )constrainContentSizeToScreenSize : (NSSize )contentSize ;
8888- (NSRect )constrainFrame : (NSRect )frame ;
89- - (void )updateResizeConstraints ;
9089- (NSTabViewItem *)addNewTabViewItem ;
9190- (BOOL )askBackendForStarRegister : (NSPasteboard *)pb ;
9291- (void )updateTablineSeparator ;
@@ -332,7 +331,7 @@ - (BOOL)presentWindow:(id)unused
332331 // code that is executed before this point must not depend on the screen!
333332
334333 [[MMAppController sharedInstance ] windowControllerWillOpen: self ];
335- [self updateResizeConstraints ];
334+ [self updateResizeConstraints: NO ];
336335 [self resizeWindowToFitContentSize: [vimView desiredSize ]
337336 keepOnScreen: YES ];
338337
@@ -707,7 +706,7 @@ - (void)setFont:(NSFont *)font
707706 }
708707
709708 [[vimView textView ] setFont: font];
710- [self updateResizeConstraints ];
709+ [self updateResizeConstraints: NO ];
711710 shouldMaximizeWindow = YES ;
712711}
713712
@@ -1519,6 +1518,35 @@ - (NSTouchBar *)makeTouchBar
15191518}
15201519#endif
15211520
1521+ // / This will update the window's resizing constraints to either be smooth or rounded to whole cells.
1522+ // /
1523+ // / @param resizeWindow If specified, will also resize the window itself down to match the Vim view's desired size.
1524+ - (void )updateResizeConstraints : (BOOL )resizeWindow
1525+ {
1526+ if (!setupDone) return ;
1527+
1528+ // If smooth resizing is not set, set the resize increments to exactly
1529+ // match the font size; this way the window will always hold an integer
1530+ // number of (rows,columns). Otherwise, just allow arbitrary resizing.
1531+ const BOOL smoothResize = [[NSUserDefaults standardUserDefaults ] boolForKey: MMSmoothResizeKey];
1532+ const NSSize desiredResizeConstraints = smoothResize ?
1533+ NSMakeSize (1 , 1 ) :
1534+ [[vimView textView ] cellSize ];
1535+ [decoratedWindow setContentResizeIncrements: desiredResizeConstraints];
1536+
1537+ const NSSize minSize = [vimView minSize ];
1538+ [decoratedWindow setContentMinSize: minSize];
1539+
1540+ if (resizeWindow) {
1541+ if (!smoothResize) {
1542+ // We only want to resize the window down to match the Vim size if not using smooth resizing.
1543+ // This resizing is going to re-snap the Window size to multiples of grid size. Otherwise
1544+ // the resize constraint is always going to be at an offset to the desired size.
1545+ shouldResizeVimView = YES ;
1546+ }
1547+ }
1548+ }
1549+
15221550@end // MMWindowController
15231551
15241552
@@ -1645,19 +1673,6 @@ - (NSRect)constrainFrame:(NSRect)frame
16451673 return [decoratedWindow frameRectForContentRect: contentRect];
16461674}
16471675
1648- - (void )updateResizeConstraints
1649- {
1650- if (!setupDone) return ;
1651-
1652- // Set the resize increments to exactly match the font size; this way the
1653- // window will always hold an integer number of (rows,columns).
1654- NSSize cellSize = [[vimView textView ] cellSize ];
1655- [decoratedWindow setContentResizeIncrements: cellSize];
1656-
1657- NSSize minSize = [vimView minSize ];
1658- [decoratedWindow setContentMinSize: minSize];
1659- }
1660-
16611676- (NSTabViewItem *)addNewTabViewItem
16621677{
16631678 return [vimView addNewTabViewItem ];
@@ -1711,7 +1726,7 @@ - (void)hideTablineSeparator:(BOOL)hide
17111726 if ([decoratedWindow hideTablineSeparator: hide]) {
17121727 // The tabline separator was toggled so the content view must change
17131728 // size.
1714- [self updateResizeConstraints ];
1729+ [self updateResizeConstraints: NO ];
17151730 }
17161731}
17171732
0 commit comments