Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions sources/PTYSession.m
Original file line number Diff line number Diff line change
Expand Up @@ -18285,6 +18285,23 @@ - (NSDictionary *)automaticProfileSwitcherCurrentProfile {
- (void)automaticProfileSwitcherLoadProfile:(iTermSavedProfile *)savedProfile {
Profile *underlyingProfile = [[ProfileModel sharedInstance] bookmarkWithGuid:savedProfile.originalProfile[KEY_GUID]];
Profile *replacementProfile = underlyingProfile ?: savedProfile.originalProfile;

// Compute the font zoom delta before switching profiles so we can preserve it.
// The zoom delta is the difference between the current font size and the
// profile\u2019s base font size.
CGFloat fontZoomDelta = 0;
NSRect savedWindowFrame = NSZeroRect;
NSWindow *window = [[_delegate realParentWindow] window];
if ([iTermAdvancedSettingsModel preserveFontSizeOnAutomaticProfileSwitch]) {
iTermFontTable *originalFontTable = [iTermFontTable fontTableForProfile:_originalProfile];
CGFloat currentPointSize = _textview.fontTable.asciiFont.font.pointSize;
CGFloat originalPointSize = originalFontTable.asciiFont.font.pointSize;
fontZoomDelta = currentPointSize - originalPointSize;
if (fontZoomDelta != 0 && window) {
savedWindowFrame = window.frame;
}
}

if (![self setProfile:replacementProfile preservingName:NO adjustWindow:NO]) {
[_view showUnobtrusiveMessage:[NSString stringWithFormat:@"Can’t switch to profile “%@”—wrong profile type.", underlyingProfile[KEY_NAME]]];
return;
Expand All @@ -18297,8 +18314,29 @@ - (void)automaticProfileSwitcherLoadProfile:(iTermSavedProfile *)savedProfile {
}
overrides[key] = savedProfile.profile[key];
}
_windowAdjustmentDisabled = YES;
[self setSessionSpecificProfileValues:overrides];
_windowAdjustmentDisabled = NO;
}

// Re-apply the font zoom delta after the profile switch, but only when
// switching to a new profile. When restoring a divorced profile from the
// stack, the saved overrides already include the zoomed font.
if (fontZoomDelta != 0 && !savedProfile.isDivorced) {
_windowAdjustmentDisabled = YES;
iTermFontTable *zoomedTable = [_textview.fontTable fontTableGrownBy:fontZoomDelta];
[self setFontTable:zoomedTable
horizontalSpacing:_textview.horizontalSpacing
verticalSpacing:_textview.verticalSpacing];
_windowAdjustmentDisabled = NO;
}

// Restore the window frame to eliminate any rounding glitches from
// intermediate font size changes during the profile switch.
if (!NSIsEmptyRect(savedWindowFrame) && window) {
[window setFrame:savedWindowFrame display:YES];
}

if ([iTermAdvancedSettingsModel showAutomaticProfileSwitchingBanner]) {
[_view showUnobtrusiveMessage:[NSString stringWithFormat:@"Switched to profile “%@”.", underlyingProfile[KEY_NAME]]];
}
Expand Down
1 change: 1 addition & 0 deletions sources/iTermAdvancedSettingsModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ extern NSString *const iTermAdvancedSettingsDidChange;
+ (BOOL)shouldSetLCTerminal;
+ (BOOL)shouldSetTerminfoDirs;
+ (BOOL)showAutomaticProfileSwitchingBanner;
+ (BOOL)preserveFontSizeOnAutomaticProfileSwitch;
+ (BOOL)showBlockBoundaries;
+ (BOOL)showButtonsForSelectedCommand;
+ (BOOL)showHintsInSplitPaneMenuItems;
Expand Down
1 change: 1 addition & 0 deletions sources/iTermAdvancedSettingsModel.m
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,7 @@ + (BOOL)settingIsDeprecated:(NSString *)name {
DEFINE_BOOL(focusNewSplitPaneWithFocusFollowsMouse, YES, SECTION_SESSION @"When focus follows mouse is enabled, should new split panes automatically be focused?");
DEFINE_BOOL(NoSyncSuppressRestartSessionConfirmationAlert, NO, SECTION_SESSION @"Suppress restart session confirmation alert.\nDon't ask for a confirmation when manually restarting a session.");
DEFINE_BOOL(showAutomaticProfileSwitchingBanner, YES, SECTION_SESSION @"Show a “Switched to profile” message when Automatic Profile Switching activates.");
DEFINE_BOOL(preserveFontSizeOnAutomaticProfileSwitch, YES, SECTION_SESSION @"Preserve font zoom level when Automatic Profile Switching changes profiles.");
DEFINE_BOOL(autoLockSessionNameOnEdit, YES, SECTION_SESSION @"Auto-lock session name after editing it.");
DEFINE_FLOAT(timeoutForDaemonAttachment, 10, SECTION_SESSION @"How long to wait when trying to attach to an iTerm daemon at startup when restoring windows (in seconds)?");
DEFINE_BOOL(logTimestampsWithPlainText, YES, SECTION_SESSION @"When logging plain text, include timestamps for each line?");
Expand Down