@@ -222,6 +222,10 @@ static void grid_free(Grid *grid) {
222222
223223@implementation MMCoreTextView {
224224 Grid grid;
225+ NSMutableSet <NSString *> *characterStrings; // /< Storage for characters in the grid
226+
227+ NSMutableDictionary <NSNumber *, NSFont *> *fontVariants; // /< Cache for fonts used for each variant (e.g. italic)
228+ NSMutableDictionary <NSNumber *,NSCache <NSString *,id > *> *characterLines; // /< Cache for built CTLine objects
225229
226230 BOOL alignCmdLineToBottom; // /< Whether to pin the Vim command-line to the bottom of the window
227231 int cmdlineRow; // /< Row number (0-indexed) where the cmdline starts. Used for pinning it to the bottom if desired.
@@ -251,8 +255,9 @@ - (instancetype)initWithFrame:(NSRect)frame
251255 antialias = YES ;
252256
253257 [self setFont: [NSFont userFixedPitchFontOfSize: 0 ]];
254- fontVariants = [[NSMutableDictionary alloc ] init ];
255258 characterStrings = [[NSMutableSet alloc ] init ];
259+
260+ fontVariants = [[NSMutableDictionary alloc ] init ];
256261 characterLines = [[NSMutableDictionary alloc ] init ];
257262
258263 helper = [[MMTextViewHelper alloc ] init ];
@@ -276,8 +281,8 @@ - (void)dealloc
276281 [fontWide release ]; fontWide = nil ;
277282 [defaultBackgroundColor release ]; defaultBackgroundColor = nil ;
278283 [defaultForegroundColor release ]; defaultForegroundColor = nil ;
279- [fontVariants release ]; fontVariants = nil ;
280284 [characterStrings release ]; characterStrings = nil ;
285+ [fontVariants release ]; fontVariants = nil ;
281286 [characterLines release ]; characterLines = nil ;
282287
283288 [helper setTextView: nil ];
@@ -478,9 +483,7 @@ - (void)setFont:(NSFont *)newFont
478483 cellSize.width = columnspace + ceil (em * cellWidthMultiplier);
479484 cellSize.height = linespace + defaultLineHeightForFont (font);
480485
481- [self clearAll ];
482486 [fontVariants removeAllObjects ];
483- [characterStrings removeAllObjects ];
484487 [characterLines removeAllObjects ];
485488}
486489
@@ -498,9 +501,7 @@ - (void)setWideFont:(NSFont *)newFont
498501 fontWide = [newFont retain ];
499502 }
500503
501- [self clearAll ];
502504 [fontVariants removeAllObjects ];
503- [characterStrings removeAllObjects ];
504505 [characterLines removeAllObjects ];
505506}
506507
@@ -1485,6 +1486,9 @@ - (NSRect)rectForRow:(int)row column:(int)col numRows:(int)nr
14851486 rect.size .width = nc*cellSize.width ;
14861487 rect.size .height = nr*cellSize.height ;
14871488
1489+ rect.origin .x += _drawRectOffset.width ;
1490+ rect.origin .y += _drawRectOffset.height ;
1491+
14881492 // Under smooth resizing, full screen, or guioption-k; we frequently have a frame size that's not
14891493 // aligned with the exact grid size. If the user has 'cursorline' set, or the color scheme uses
14901494 // the NonText highlight group, this will leave a small gap on the right filled with bg color looking
@@ -1505,13 +1509,15 @@ - (NSRect)rectForRow:(int)row column:(int)col numRows:(int)nr
15051509 const CGFloat gapHeight = frame.size .height - grid.rows *cellSize.height - insetSize.height - insetBottom;
15061510 if (row >= cmdlineRow) {
15071511 rect.origin .y -= gapHeight;
1512+ rect.origin .y -= _drawRectOffset.height ; // Pinning ignores draw rect offset for stability
15081513 } else if (row + nr - 1 >= cmdlineRow) {
15091514 // This is an odd case where the gap between cmdline and the top-aligned content is inside
15101515 // the rect so we need to adjust the height as well. During rendering we draw line-by-line
15111516 // so this shouldn't cause any issues as we only encounter this situation when calculating
15121517 // the rect in setNeedsDisplayFromRow:.
15131518 rect.size .height += gapHeight;
15141519 rect.origin .y -= gapHeight;
1520+ rect.origin .y -= _drawRectOffset.height ; // Pinning ignores draw rect offset for stability
15151521 }
15161522 }
15171523 return rect;
0 commit comments