Skip to content

Preserve font zoom level during Automatic Profile Switching#634

Open
objectiveSee wants to merge 1 commit into
gnachman:masterfrom
objectiveSee:fix/preserve-zoom-on-aps
Open

Preserve font zoom level during Automatic Profile Switching#634
objectiveSee wants to merge 1 commit into
gnachman:masterfrom
objectiveSee:fix/preserve-zoom-on-aps

Conversation

@objectiveSee
Copy link
Copy Markdown
Contributor

@objectiveSee objectiveSee commented Mar 27, 2026

Summary

  • When Automatic Profile Switching (APS) changes profiles, the font zoom level (set via Cmd+Plus/Cmd-Minus) is lost because setPreferencesFromAddressBookEntry: unconditionally resets the font to the profile's configured font
  • This computes the zoom delta (current font size minus profile base font size) before the switch and re-applies it after
  • When restoring a divorced profile from the stack, the saved overrides already contain the zoomed font, so the delta is not re-applied (avoids double-applying)
  • Window frame is saved/restored to prevent rounding glitches from intermediate font size changes
  • Adds _windowAdjustmentDisabled = YES around setSessionSpecificProfileValues: to prevent window resizing when restoring divorced profile overrides

New Advanced Setting

"Preserve font zoom level when Automatic Profile Switching changes profiles" (defaults to YES, under Session section)

Files Changed

  • sources/PTYSession.m — modified automaticProfileSwitcherLoadProfile: to save/restore zoom delta and window frame
  • sources/iTermAdvancedSettingsModel.h — declare preserveFontSizeOnAutomaticProfileSwitch
  • sources/iTermAdvancedSettingsModel.m — define setting (defaults to YES)

Test plan

  • Create two profiles with different colors but same font settings
  • Set up Automatic Profile Switching rule on one profile for a specific directory
  • Zoom in with Cmd+Plus several times
  • cd into the directory that triggers the profile switch — verify font size is preserved and window does not resize
  • cd out of the directory — verify font size is preserved and window does not resize
  • Repeat several times to verify no cumulative drift
  • Toggle the Advanced Setting off and verify original behavior (zoom is lost on switch)

🤖 Generated with Claude Code

When Automatic Profile Switching changes profiles, the font zoom level
(set via Cmd+Plus/Cmd-Minus) was lost because setPreferencesFromAddressBookEntry:
unconditionally resets the font to the profile's configured font.

This computes the zoom delta before the switch and re-applies it after,
with care to avoid double-applying when restoring divorced profiles from
the stack (which already contain the zoomed font in their overrides).
Window frame is saved and restored to prevent rounding glitches from
intermediate font size changes.

Controlled by a new Advanced Setting: "Preserve font zoom level when
Automatic Profile Switching changes profiles" (defaults to YES).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
gnachman added a commit that referenced this pull request Apr 8, 2026
When Automatic Profile Switching changes profiles, the font zoom level
(set via Cmd+Plus/Cmd-Minus) was lost because setPreferencesFromAddressBookEntry:
unconditionally resets the font to the profile's configured font.

This computes the zoom delta before the switch and re-applies it after,
with care to avoid double-applying when restoring divorced profiles from
the stack (which already contain the zoomed font in their overrides).
Window adjustments are suppressed via _windowAdjustmentDisabled during
font changes to prevent resizing.

The base (unzoomed) font point size is tracked in a dedicated ivar
rather than re-derived from _originalProfile, so the delta computation
does not depend on profile dictionary state.

Controlled by a new Advanced Setting: "Preserve font zoom level when
Automatic Profile Switching changes profiles" (defaults to YES).

Co-Authored-By: Danny Ricciotti <dan.ricciotti@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant