From 979118a86febca28190a715bb05221f30217693a Mon Sep 17 00:00:00 2001 From: daboe01 Date: Sat, 30 May 2026 08:55:25 +0200 Subject: [PATCH] restored: tabstop-fix --- AppKit/CPTextView/CPTypesetter.j | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/AppKit/CPTextView/CPTypesetter.j b/AppKit/CPTextView/CPTypesetter.j index aa7e39128..06c8a368f 100644 --- a/AppKit/CPTextView/CPTypesetter.j +++ b/AppKit/CPTextView/CPTypesetter.j @@ -135,34 +135,36 @@ var CPSystemTypesetterFactory, return [_layoutManager textContainers]; } +// Retrieves correct CPTextTab stop accounting for CPArray properties - (CPTextTab)textTabForWidth:(double)aWidth writingDirection:(CPWritingDirection)direction { var tabStops = [_currentParagraph tabStops]; if (!tabStops) - tabStops = [CPParagraphStyle _defaultTabStops]; + tabStops = [[CPParagraphStyle defaultParagraphStyle] tabStops]; - var l = tabStops.length; + var l = [tabStops count]; - if (aWidth > tabStops[l - 1]._location) + if (l === 0) return nil; - for (var i = l - 1; i >= 0; i--) + // Find the first tab stop that is strictly greater than the current width + for (var i = 0; i < l; i++) { - if (aWidth > tabStops[i]._location) - { - if (i + 1 < l) - return tabStops[i + 1]; - } + var tab = [tabStops objectAtIndex:i]; + + if ([tab location] > aWidth) + return tab; } - if (i === -1) - return tabStops[0]; + // If aWidth exceeds the last tab stop, dynamically calculate the next + // tab location using the default tab interval. + var defaultInterval = [_currentParagraph defaultTabInterval] || 28.0; + var nextLocation = CEIL((aWidth + 1.0) / defaultInterval) * defaultInterval; - return nil; + return [[CPTextTab alloc] initWithType:CPLeftTextAlignment location:nextLocation]; } - - (BOOL)_flushRange:(CPRange)lineRange lineOrigin:(CGPoint)lineOrigin currentContainer:(CPTextContainer)aContainer