Skip to content

Commit a7279d8

Browse files
committed
Allow pinning the cmdline to be aligned to the bottom of window
Add a setting that could pin the command-line portion of Vim to the bottom of the MacVim window. This is useful when smooth resizing is set, guioption+=k, or in full screen. In those situations, the MacVim window size is usually not direct multiples of the Vim text sizes. Previously the command-line would be drawn like other texts, and hence not aligned to the bottom and hence looking aesthetically a little off. When this setting is set, the command-line portion would be aligned to the bottom of the window. This essentially moves the gap (due to the extra height of the window) from the bottom to be between cmdline and the rest of Vim. When cmdheight is changed, or other situations (e.g. typing too much cmdline height to be increased), the gap will be adjusted as well. Implementation-wise, this was done by passing the `commandline_row` var from Vim to MacVim, which serves as a good estimate of where the command-line is. This works better than just using the `cmdheight` option as it is closer to the current state of the cmdline. One issue is that in hit-enter prompts, the row is set to the 2nd to last row to anticipate more messages, and we just add a big hack by incrementing the row by 1 in hit-enter state so only the "Press Enter..." part is aligned to bottom. We also have to do something similar to when it's showing "--more--" for similar reasons. - An alternative would have been to modify Vim to provide us the information we want (the number of rows below the status line) but it's pretty tricky to do as cmdline_row is used in lots of places. It's easier / simpler to do a simple hack like this to localize the damage. Close #833
1 parent 6b26957 commit a7279d8

File tree

13 files changed

+193
-26
lines changed

13 files changed

+193
-26
lines changed

runtime/doc/gui_mac.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,20 +256,21 @@ Here is a list of relevant dictionary entries:
256256

257257
KEY VALUE ~
258258
*MMCellWidthMultiplier* width of a normal glyph in em units [float]
259+
*MMCmdLineAlignBottom* Pin command-line to bottom of MacVim [bool]
259260
*MMDialogsTrackPwd* open/save dialogs track the Vim pwd [bool]
260261
*MMDisableLaunchAnimation* disable launch animation when opening a new
261262
MacVim window [bool]
262-
*MMFullScreenFadeTime* fade delay for non-native fullscreen [float]
263+
*MMFontPreserveLineSpacing* use the line-spacing as specified by font [bool]
263264
*MMLoginShellArgument* login shell parameter [string]
264265
*MMLoginShellCommand* which shell to use to launch Vim [string]
266+
*MMFullScreenFadeTime* fade delay for non-native fullscreen [float]
265267
*MMNativeFullScreen* use native full screen mode [bool]
266268
*MMNonNativeFullScreenShowMenu* show menus when in non-native full screen [bool]
267269
*MMNonNativeFullScreenSafeAreaBehavior*
268270
behavior for non-native full sreen regarding
269271
the safe area (aka the "notch") [int]
270272
*MMNoFontSubstitution* disable automatic font substitution [bool]
271273
(Deprecated: Non-CoreText renderer only)
272-
*MMFontPreserveLineSpacing* use the line-spacing as specified by font [bool]
273274
*MMNoTitleBarWindow* hide title bar [bool]
274275
*MMTitlebarAppearsTransparent* enable a transparent titlebar [bool]
275276
*MMAppearanceModeSelection* dark mode selection (|macvim-dark-mode|)[bool]

runtime/doc/tags

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5405,6 +5405,7 @@ M motion.txt /*M*
54055405
MDI starting.txt /*MDI*
54065406
MMAppearanceModeSelection gui_mac.txt /*MMAppearanceModeSelection*
54075407
MMCellWidthMultiplier gui_mac.txt /*MMCellWidthMultiplier*
5408+
MMCmdLineAlignBottom gui_mac.txt /*MMCmdLineAlignBottom*
54085409
MMDialogsTrackPwd gui_mac.txt /*MMDialogsTrackPwd*
54095410
MMDisableLaunchAnimation gui_mac.txt /*MMDisableLaunchAnimation*
54105411
MMFontPreserveLineSpacing gui_mac.txt /*MMFontPreserveLineSpacing*

src/MacVim/Base.lproj/Preferences.xib

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -257,11 +257,11 @@
257257
<point key="canvasLocation" x="137.5" y="21.5"/>
258258
</customView>
259259
<customView id="hr4-G4-3ZG" userLabel="Appearance">
260-
<rect key="frame" x="0.0" y="0.0" width="483" height="315"/>
260+
<rect key="frame" x="0.0" y="0.0" width="483" height="341"/>
261261
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
262262
<subviews>
263263
<customView id="fw0-VK-Nbz" userLabel="Dark mode selection">
264-
<rect key="frame" x="19" y="137" width="433" height="156"/>
264+
<rect key="frame" x="19" y="163" width="433" height="156"/>
265265
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
266266
<subviews>
267267
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" id="T40-Os-PUf" userLabel="Dark mode selection">
@@ -322,7 +322,7 @@
322322
</subviews>
323323
</customView>
324324
<customView id="7af-iK-4r7" userLabel="Titlebar appearance">
325-
<rect key="frame" x="19" y="91" width="433" height="38"/>
325+
<rect key="frame" x="19" y="117" width="433" height="38"/>
326326
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
327327
<subviews>
328328
<button id="7ie-0J-0Zr">
@@ -361,7 +361,7 @@
361361
</subviews>
362362
</customView>
363363
<customView id="BpJ-rH-ona" userLabel="Full Screen">
364-
<rect key="frame" x="19" y="45" width="433" height="38"/>
364+
<rect key="frame" x="19" y="71" width="433" height="38"/>
365365
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
366366
<subviews>
367367
<button toolTip="Use macOS's native full screen mode, which integrates with Mission Control and creates a new Space for the window." id="YKV-u2-Egc" userLabel="Use native full screen">
@@ -405,7 +405,7 @@
405405
</subviews>
406406
</customView>
407407
<customView id="a3v-cB-TFa" userLabel="Font">
408-
<rect key="frame" x="19" y="20" width="433" height="18"/>
408+
<rect key="frame" x="19" y="46" width="433" height="18"/>
409409
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
410410
<subviews>
411411
<button id="A48-s0-kdR" userLabel="Preserve Line Spacing">
@@ -432,8 +432,36 @@
432432
</textField>
433433
</subviews>
434434
</customView>
435+
<customView id="Dey-Wx-2gx" userLabel="Cmdline">
436+
<rect key="frame" x="20" y="20" width="433" height="18"/>
437+
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
438+
<subviews>
439+
<button id="qMh-iV-0iD">
440+
<rect key="frame" x="189" y="-1" width="244" height="18"/>
441+
<autoresizingMask key="autoresizingMask" flexibleMinY="YES"/>
442+
<string key="toolTip">When using smooth resizing, guioption+=k, or full screen; MacVim's window size can sometimes be slightly larger than Vim's content size, causing the command-line to not be aligned to the bottom. This option will make sure the command-line is always pinned to the bottom.</string>
443+
<buttonCell key="cell" type="check" title="Pin to the bottom of the window" bezelStyle="regularSquare" imagePosition="left" alignment="left" inset="2" id="uZL-IX-Dv8">
444+
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
445+
<font key="font" metaFont="system"/>
446+
</buttonCell>
447+
<connections>
448+
<action selector="cmdlineAlignBottomChanged:" target="-2" id="LgN-MI-0Nt"/>
449+
<binding destination="58" name="value" keyPath="values.MMCmdLineAlignBottom" id="pIr-52-5vV"/>
450+
</connections>
451+
</button>
452+
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" id="Lzq-i0-zWi" userLabel="Cmdline">
453+
<rect key="frame" x="-2" y="0.0" width="187" height="17"/>
454+
<autoresizingMask key="autoresizingMask" flexibleMinY="YES"/>
455+
<textFieldCell key="cell" sendsActionOnEndEditing="YES" alignment="right" title="Command-line:" id="2Lp-vX-AcA">
456+
<font key="font" metaFont="system"/>
457+
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
458+
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
459+
</textFieldCell>
460+
</textField>
461+
</subviews>
462+
</customView>
435463
</subviews>
436-
<point key="canvasLocation" x="137.5" y="412.5"/>
464+
<point key="canvasLocation" x="137.5" y="425.5"/>
437465
</customView>
438466
<customView id="620" userLabel="Advanced">
439467
<rect key="frame" x="0.0" y="0.0" width="483" height="264"/>
@@ -504,7 +532,7 @@
504532
</connections>
505533
</button>
506534
</subviews>
507-
<point key="canvasLocation" x="137.5" y="743"/>
535+
<point key="canvasLocation" x="144" y="911"/>
508536
</customView>
509537
</objects>
510538
</document>

src/MacVim/MMAppController.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
- (void)refreshAllAppearances;
6262
- (void)refreshAllFonts;
6363
- (void)refreshAllResizeConstraints;
64+
- (void)refreshAllTextViews;
6465

6566
- (IBAction)newWindow:(id)sender;
6667
- (IBAction)newWindowAndActivate:(id)sender;

src/MacVim/MMAppController.m

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#import "MMAppController.h"
4141
#import "MMPreferenceController.h"
4242
#import "MMVimController.h"
43+
#import "MMVimView.h"
4344
#import "MMWindowController.h"
4445
#import "MMTextView.h"
4546
#import "Miscellaneous.h"
@@ -253,6 +254,7 @@ + (void)initialize
253254
[NSNumber numberWithInt:0], MMNonNativeFullScreenSafeAreaBehaviorKey,
254255
[NSNumber numberWithBool:YES], MMShareFindPboardKey,
255256
[NSNumber numberWithBool:NO], MMSmoothResizeKey,
257+
[NSNumber numberWithBool:NO], MMCmdLineAlignBottomKey,
256258
nil];
257259

258260
[[NSUserDefaults standardUserDefaults] registerDefaults:dict];
@@ -1142,6 +1144,16 @@ - (void)refreshAllResizeConstraints
11421144
}
11431145
}
11441146

1147+
- (void)refreshAllTextViews
1148+
{
1149+
unsigned count = [vimControllers count];
1150+
for (unsigned i = 0; i < count; ++i) {
1151+
MMVimController *vc = [vimControllers objectAtIndex:i];
1152+
[vc.windowController.vimView.textView updateCmdlineRow];
1153+
vc.windowController.vimView.textView.needsDisplay = YES;
1154+
}
1155+
}
1156+
11451157
- (IBAction)newWindow:(id)sender
11461158
{
11471159
ASLogDebug(@"Open new window");

src/MacVim/MMBackend.m

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1816,13 +1816,33 @@ - (void)insertVimStateMessage
18161816
if (numTabs < 0)
18171817
numTabs = 0;
18181818

1819+
// Custom hacks to deal with cmdline_row not being perfect for our use cases.
1820+
int cmdline_row_adjusted = cmdline_row;
1821+
if (State == MODE_HITRETURN) {
1822+
// When we are in hit-return mode, Vim does a weird thing and sets
1823+
// cmdline_row to be the 2nd-to-last row, which would make pinning
1824+
// cmdline to bottom look weird. This is done in msg_start() and
1825+
// wait_return().
1826+
// Instead of modifying Vim, we just hack around this by manually
1827+
// increasing the row by one. This would make the pin happen right at
1828+
// the "Hit Enter..." prompt.
1829+
cmdline_row_adjusted++;
1830+
} else if (State == MODE_ASKMORE) {
1831+
// In "more" mode, Vim sometimes set cmdline_row, sometimes it doesn't.
1832+
// Silver lining is that it always only takes one row and doesn't wrap
1833+
// like hit-enter, so we know we can always just pin it to the last row
1834+
// and be done with the hack.
1835+
cmdline_row_adjusted = Rows - 1;
1836+
}
1837+
18191838
NSDictionary *vimState = [NSDictionary dictionaryWithObjectsAndKeys:
18201839
[[NSFileManager defaultManager] currentDirectoryPath], @"pwd",
18211840
[NSNumber numberWithInt:p_mh], @"p_mh",
18221841
[NSNumber numberWithBool:mmta], @"p_mmta",
18231842
[NSNumber numberWithInt:numTabs], @"numTabs",
18241843
[NSNumber numberWithInt:fuoptions_flags], @"fullScreenOptions",
18251844
[NSNumber numberWithLong:p_mouset], @"p_mouset",
1845+
[NSNumber numberWithInt:cmdline_row_adjusted], @"cmdline_row", // Used for pinning cmdline to bottom of window
18261846
nil];
18271847

18281848
// Put the state before all other messages.

src/MacVim/MMCoreTextView.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
- (BOOL)convertPoint:(NSPoint)point toRow:(int *)row column:(int *)column;
8787
- (NSRect)rectForRow:(int)row column:(int)column numRows:(int)nr
8888
numColumns:(int)nc;
89+
- (void)updateCmdlineRow;
8990

9091
//
9192
// NSTextView methods

0 commit comments

Comments
 (0)