Skip to content

Commit f8231e7

Browse files
pbernerylucasderraugh
authored andcommitted
Improve char width computation (#593)
Char width computation didn't work as expected when the first character of the NSTextView was an emoji. The `maximumAdvancement` returned the length of the emoji, placing the margins at unexpected position. This commit improves the computation by using a fixed character (`x` has been chosen, arbitrarily). The margin will thus be placed at 50 non-emoji characters.
1 parent 5f37a78 commit f8231e7

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

GitUpKit/Utilities/GIAppKit.m

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,10 @@ - (void)drawRect:(NSRect)dirtyRect {
174174
if ([[NSUserDefaults standardUserDefaults] boolForKey:GICommitMessageViewUserDefaultKey_ShowMargins]) {
175175
NSRect bounds = self.bounds;
176176
CGFloat offset = self.textContainerOrigin.x + self.textContainerInset.width + self.textContainer.lineFragmentPadding;
177-
CGFloat charWidth = self.font.maximumAdvancement.width; // TODO: Is this the most reliable way to get the character width of a fixed-width font?
177+
CGFloat charWidth = [@"x" sizeWithAttributes:@{
178+
NSFontAttributeName : self.font
179+
}]
180+
.width;
178181
CGContextRef context = [[NSGraphicsContext currentContext] graphicsPort];
179182

180183
CGContextSaveGState(context);

0 commit comments

Comments
 (0)