mirror of
https://github.com/macvim-dev/macvim.git
synced 2026-06-11 15:37:29 +02:00
Keep whole window visible on ":set lines=X columns=Y"
This commit is contained in:
@@ -1698,13 +1698,18 @@ static NSString *MMSymlinkWarningString =
|
||||
if (SetTextRowsMsgID == msgid || SetTextColumnsMsgID == msgid) {
|
||||
int dim[2] = { rows, cols };
|
||||
d = [NSData dataWithBytes:dim length:2*sizeof(int)];
|
||||
msgid = SetTextDimensionsMsgID;
|
||||
msgid = SetTextDimensionsReplyMsgID;
|
||||
}
|
||||
|
||||
if (SetTextDimensionsMsgID == msgid)
|
||||
msgid = SetTextDimensionsReplyMsgID;
|
||||
|
||||
// NOTE! Vim doesn't call gui_mch_set_shellsize() after
|
||||
// gui_resize_shell(), so we have to manually set the rows and columns
|
||||
// here. (MacVim doesn't change the rows and columns to avoid
|
||||
// inconsistent states between Vim and MacVim.)
|
||||
// here since MacVim doesn't change the rows and columns to avoid
|
||||
// inconsistent states between Vim and MacVim. The message sent back
|
||||
// indicates that it is a reply to a message that originated in MacVim
|
||||
// since we need to be able to determine where a message originated.
|
||||
[self queueMessage:msgid data:d];
|
||||
|
||||
//NSLog(@"[VimTask] Resizing shell to %dx%d.", cols, rows);
|
||||
|
||||
@@ -742,13 +742,16 @@ static BOOL isUnsafeMessage(int msgid);
|
||||
[windowController showTabBar:YES];
|
||||
} else if (HideTabBarMsgID == msgid) {
|
||||
[windowController showTabBar:NO];
|
||||
} else if (SetTextDimensionsMsgID == msgid || LiveResizeMsgID == msgid) {
|
||||
} else if (SetTextDimensionsMsgID == msgid || LiveResizeMsgID == msgid ||
|
||||
SetTextDimensionsReplyMsgID == msgid) {
|
||||
const void *bytes = [data bytes];
|
||||
int rows = *((int*)bytes); bytes += sizeof(int);
|
||||
int cols = *((int*)bytes); bytes += sizeof(int);
|
||||
|
||||
[windowController setTextDimensionsWithRows:rows columns:cols
|
||||
live:(LiveResizeMsgID==msgid)];
|
||||
[windowController setTextDimensionsWithRows:rows
|
||||
columns:cols
|
||||
isLive:(LiveResizeMsgID==msgid)
|
||||
isReply:(SetTextDimensionsReplyMsgID==msgid)];
|
||||
} else if (SetWindowTitleMsgID == msgid) {
|
||||
const void *bytes = [data bytes];
|
||||
int len = *((int*)bytes); bytes += sizeof(int);
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
MMVimView *vimView;
|
||||
BOOL setupDone;
|
||||
BOOL shouldResizeVimView;
|
||||
BOOL keepOnScreen;
|
||||
BOOL fullscreenEnabled;
|
||||
NSString *windowAutosaveKey;
|
||||
MMFullscreenWindow *fullscreenWindow;
|
||||
@@ -39,7 +40,8 @@
|
||||
- (void)showWindow;
|
||||
- (void)updateTabsWithData:(NSData *)data;
|
||||
- (void)selectTabWithIndex:(int)idx;
|
||||
- (void)setTextDimensionsWithRows:(int)rows columns:(int)cols live:(BOOL)live;
|
||||
- (void)setTextDimensionsWithRows:(int)rows columns:(int)cols isLive:(BOOL)live
|
||||
isReply:(BOOL)reply;
|
||||
- (void)setTitle:(NSString *)title;
|
||||
- (void)setDocumentFilename:(NSString *)filename;
|
||||
- (void)setToolbar:(NSToolbar *)toolbar;
|
||||
|
||||
@@ -72,7 +72,8 @@
|
||||
|
||||
@interface MMWindowController (Private)
|
||||
- (NSSize)contentSize;
|
||||
- (void)resizeWindowToFitContentSize:(NSSize)contentSize;
|
||||
- (void)resizeWindowToFitContentSize:(NSSize)contentSize
|
||||
keepOnScreen:(BOOL)onScreen;
|
||||
- (NSSize)constrainContentSizeToScreenSize:(NSSize)contentSize;
|
||||
- (NSRect)constrainFrame:(NSRect)frame;
|
||||
- (void)updateResizeConstraints;
|
||||
@@ -272,7 +273,8 @@
|
||||
setupDone = YES;
|
||||
|
||||
[self updateResizeConstraints];
|
||||
[self resizeWindowToFitContentSize:[vimView desiredSize]];
|
||||
[self resizeWindowToFitContentSize:[vimView desiredSize]
|
||||
keepOnScreen:YES];
|
||||
}
|
||||
|
||||
- (void)showWindow
|
||||
@@ -296,10 +298,11 @@
|
||||
[vimView selectTabWithIndex:idx];
|
||||
}
|
||||
|
||||
- (void)setTextDimensionsWithRows:(int)rows columns:(int)cols live:(BOOL)live
|
||||
- (void)setTextDimensionsWithRows:(int)rows columns:(int)cols isLive:(BOOL)live
|
||||
isReply:(BOOL)reply
|
||||
{
|
||||
//NSLog(@"setTextDimensionsWithRows:%d columns:%d live:%s", rows, cols,
|
||||
// live ? "YES" : "NO");
|
||||
//NSLog(@"setTextDimensionsWithRows:%d columns:%d isLive:%d isReply:%d",
|
||||
// rows, cols, live, reply);
|
||||
|
||||
// NOTE: The only place where the (rows,columns) of the vim view are
|
||||
// modified is here and when entering/leaving full-screen. Setting these
|
||||
@@ -311,11 +314,17 @@
|
||||
// resize when this message is received. We refrain from changing the view
|
||||
// size when this flag is set, otherwise the window might jitter when the
|
||||
// user drags to resize the window.
|
||||
//
|
||||
// The 'reply' flag indicates that this resize originated in MacVim and
|
||||
// that Vim is now replying to that resize to make sure that it comes into
|
||||
// effect.
|
||||
|
||||
[vimView setDesiredRows:rows columns:cols];
|
||||
|
||||
if (setupDone && !live)
|
||||
if (setupDone && !live) {
|
||||
shouldResizeVimView = YES;
|
||||
keepOnScreen = !reply;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setTitle:(NSString *)title
|
||||
@@ -433,8 +442,11 @@
|
||||
[[fullscreenWindow contentView] setNeedsDisplay:YES];
|
||||
[fullscreenWindow centerView];
|
||||
} else {
|
||||
[self resizeWindowToFitContentSize:contentSize];
|
||||
[self resizeWindowToFitContentSize:contentSize
|
||||
keepOnScreen:keepOnScreen];
|
||||
}
|
||||
|
||||
keepOnScreen = NO;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -534,7 +546,8 @@
|
||||
// Sending of synchronous message failed. Force the window size to
|
||||
// match the last dimensions received from Vim, otherwise we end up
|
||||
// with inconsistent states.
|
||||
[self resizeWindowToFitContentSize:[vimView desiredSize]];
|
||||
[self resizeWindowToFitContentSize:[vimView desiredSize]
|
||||
keepOnScreen:NO];
|
||||
}
|
||||
|
||||
// If we saved the original title while resizing, restore it.
|
||||
@@ -836,6 +849,7 @@
|
||||
}
|
||||
|
||||
- (void)resizeWindowToFitContentSize:(NSSize)contentSize
|
||||
keepOnScreen:(BOOL)onScreen
|
||||
{
|
||||
NSRect frame = [decoratedWindow frame];
|
||||
NSRect contentRect = [decoratedWindow contentRectForFrameRect:frame];
|
||||
@@ -844,22 +858,29 @@
|
||||
contentRect.origin.y -= contentSize.height - contentRect.size.height;
|
||||
contentRect.size = contentSize;
|
||||
|
||||
frame = [decoratedWindow frameRectForContentRect:contentRect];
|
||||
NSRect newFrame = [decoratedWindow frameRectForContentRect:contentRect];
|
||||
|
||||
// Ensure that the window fits inside the visible part of the screen.
|
||||
NSRect maxFrame = [[decoratedWindow screen] visibleFrame];
|
||||
maxFrame = [self constrainFrame:maxFrame];
|
||||
|
||||
if (frame.size.width > maxFrame.size.width) {
|
||||
frame.size.width = maxFrame.size.width;
|
||||
frame.origin.x = maxFrame.origin.x;
|
||||
if (newFrame.size.width > maxFrame.size.width) {
|
||||
newFrame.size.width = maxFrame.size.width;
|
||||
newFrame.origin.x = maxFrame.origin.x;
|
||||
}
|
||||
if (frame.size.height > maxFrame.size.height) {
|
||||
frame.size.height = maxFrame.size.height;
|
||||
frame.origin.y = maxFrame.origin.y;
|
||||
if (newFrame.size.height > maxFrame.size.height) {
|
||||
newFrame.size.height = maxFrame.size.height;
|
||||
newFrame.origin.y = maxFrame.origin.y;
|
||||
}
|
||||
|
||||
[decoratedWindow setFrame:frame display:YES];
|
||||
if (onScreen) {
|
||||
if (newFrame.origin.y < maxFrame.origin.y)
|
||||
newFrame.origin.y = maxFrame.origin.y;
|
||||
if (NSMaxX(newFrame) > NSMaxX(maxFrame))
|
||||
newFrame.origin.x = NSMaxX(maxFrame) - newFrame.size.width;
|
||||
}
|
||||
|
||||
[decoratedWindow setFrame:newFrame display:YES];
|
||||
}
|
||||
|
||||
- (NSSize)constrainContentSizeToScreenSize:(NSSize)contentSize
|
||||
|
||||
+2
-1
@@ -124,6 +124,8 @@ enum {
|
||||
SetTextRowsMsgID,
|
||||
SetTextColumnsMsgID,
|
||||
SetTextDimensionsMsgID,
|
||||
LiveResizeMsgID,
|
||||
SetTextDimensionsReplyMsgID,
|
||||
SetWindowTitleMsgID,
|
||||
ScrollWheelMsgID,
|
||||
MouseDownMsgID,
|
||||
@@ -166,7 +168,6 @@ enum {
|
||||
SetPreEditPositionMsgID,
|
||||
TerminateNowMsgID,
|
||||
XcodeModMsgID,
|
||||
LiveResizeMsgID,
|
||||
EnableAntialiasMsgID,
|
||||
DisableAntialiasMsgID,
|
||||
SetVimStateMsgID,
|
||||
|
||||
+2
-1
@@ -31,6 +31,8 @@ char *MessageStrings[] =
|
||||
"SetTextRowsMsgID",
|
||||
"SetTextColumsMsgID",
|
||||
"SetTextDimensionsMsgID",
|
||||
"LiveResizeMsgID",
|
||||
"SetTextDimensionsReplyMsgID",
|
||||
"SetWindowTitleMsgID",
|
||||
"ScrollWheelMsgID",
|
||||
"MouseDownMsgID",
|
||||
@@ -73,7 +75,6 @@ char *MessageStrings[] =
|
||||
"SetPreEditPositionMsgID",
|
||||
"TerminateNowMsgID",
|
||||
"XcodeModMsgID",
|
||||
"LiveResizeMsgID",
|
||||
"EnableAntialiasMsgID",
|
||||
"DisableAntialiasMsgID",
|
||||
"SetVimStateMsgID",
|
||||
|
||||
Reference in New Issue
Block a user