File tree Expand file tree Collapse file tree 6 files changed +28
-1
lines changed
Expand file tree Collapse file tree 6 files changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -1333,6 +1333,15 @@ - (void)changeFont:(id)sender
13331333
13341334 if (newFont) {
13351335 NSString *name = [newFont fontName ];
1336+
1337+ // If this is a system monospace font, retrieve the user-friendly
1338+ // name before we send it to Vim. We don't want to expose the OS-
1339+ // specific system font name which is confusing to the user.
1340+ NSString *userMonospaceFontName = [[self vimController ] systemFontNamesToAlias ][name];
1341+ if (userMonospaceFontName != nil ) {
1342+ name = userMonospaceFontName;
1343+ }
1344+
13361345 unsigned len = (unsigned )[name lengthOfBytesUsingEncoding: NSUTF8StringEncoding];
13371346 if (len > 0 ) {
13381347 NSMutableData *data = [NSMutableData data ];
Original file line number Diff line number Diff line change 5656 BOOL hasModifiedBuffer;
5757}
5858
59+ // / Mapping from internal names for system monospace font to user-visible one.
60+ // / E.g. ".AppleSystemUIFontMonospaced-Medium" -> "-monospace-Medium"
61+ @property (nonatomic , readonly ) NSMutableDictionary <NSString*, NSString*>* systemFontNamesToAlias;
62+
5963- (id )initWithBackend : (id )backend pid : (int )processIdentifier ;
6064- (void )uninitialize ;
6165- (unsigned long )vimControllerId ;
Original file line number Diff line number Diff line change @@ -250,6 +250,8 @@ - (void)dealloc
250250 [mainMenu release ]; mainMenu = nil ;
251251 [creationDate release ]; creationDate = nil ;
252252
253+ [_systemFontNamesToAlias release ]; _systemFontNamesToAlias = nil ;
254+
253255 [super dealloc ];
254256}
255257
@@ -927,6 +929,14 @@ - (void)handleMessage:(int)msgid data:(NSData *)data
927929 fontWeight = NSFontWeightBlack ;
928930 }
929931 font = [NSFont monospacedSystemFontOfSize: size weight: fontWeight];
932+
933+ // We cache the internal name -> user-facing alias mapping
934+ // to allow fontSizeUp/Down actions to be able to retain
935+ // the user-facing font name in 'guifont'.
936+ if (_systemFontNamesToAlias == nil ) {
937+ _systemFontNamesToAlias = [[NSMutableDictionary alloc ] initWithCapacity: 9 ];
938+ }
939+ _systemFontNamesToAlias[font.fontName] = name;
930940 }
931941 else
932942#endif
Original file line number Diff line number Diff line change @@ -1239,12 +1239,14 @@ - (IBAction)vimTouchbarItemAction:(id)sender
12391239
12401240- (IBAction )fontSizeUp : (id )sender
12411241{
1242+ // This creates a new font and triggers text view's changeFont: callback
12421243 [[NSFontManager sharedFontManager ] modifyFont:
12431244 [NSNumber numberWithInt: NSSizeUpFontAction]];
12441245}
12451246
12461247- (IBAction )fontSizeDown : (id )sender
12471248{
1249+ // This creates a new font and triggers text view's changeFont: callback
12481250 [[NSFontManager sharedFontManager ] modifyFont:
12491251 [NSNumber numberWithInt: NSSizeDownFontAction]];
12501252}
Original file line number Diff line number Diff line change @@ -446,7 +446,7 @@ enum {
446446
447447extern NSString *VimFindPboardType;
448448
449- // Alias for system monospace font name
449+ // / Alias for system monospace font name
450450extern NSString *MMSystemFontAlias;
451451
452452
Original file line number Diff line number Diff line change @@ -536,10 +536,12 @@ - (void) testGuifontSystemMonospace {
536536 [[[app keyVimController ] windowController ] fontSizeUp: nil ];
537537 [self waitForEventHandlingAndVimProcess ];
538538 XCTAssertEqualObjects ([textView font ], [NSFont monospacedSystemFontOfSize: 13 weight: NSFontWeightHeavy ]);
539+ XCTAssertEqualObjects ([[app keyVimController ] evaluateVimExpression: @" &guifont" ], @" -monospace-Heavy:h13" );
539540
540541 [[[app keyVimController ] windowController ] fontSizeDown: nil ];
541542 [self waitForEventHandlingAndVimProcess ];
542543 XCTAssertEqualObjects ([textView font ], [NSFont monospacedSystemFontOfSize: 12 weight: NSFontWeightHeavy ]);
544+ XCTAssertEqualObjects ([[app keyVimController ] evaluateVimExpression: @" &guifont" ], @" -monospace-Heavy:h12" );
543545}
544546
545547// / Test that dark mode settings work and the corresponding Vim bindings are functional.
You can’t perform that action at this time.
0 commit comments