Skip to content

Commit bb2e588

Browse files
committed
feat: drop the neutral kind behavior
1 parent 74e63d3 commit bb2e588

3 files changed

Lines changed: 8 additions & 25 deletions

File tree

ios/inputAttributesManager/InputAttributesManager.mm

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,9 @@ - (void)handleDirtyRangesStyling {
114114
[self stylingOrderFor:_input->stylesDict[a]];
115115
NSInteger bOrder =
116116
[self stylingOrderFor:_input->stylesDict[b]];
117-
if (aOrder == bOrder)
118-
return NSOrderedSame;
117+
if (aOrder == bOrder) {
118+
return [a compare:b];
119+
}
119120
return aOrder < bOrder ? NSOrderedAscending
120121
: NSOrderedDescending;
121122
}];

ios/interfaces/StyleBase.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ - (BOOL)appliesStylingToTyping {
4545
return NO;
4646
}
4747

48-
// determines the order of which the styles are applied
48+
// determines the order in which the styles are applied
4949
- (NSInteger)stylingPriority {
5050
return 0;
5151
}

ios/utils/ItalicUtils.mm

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@
66
static const CGFloat kObliquenessFallback = 0.2;
77

88
typedef NS_ENUM(NSInteger, ItalicKind) {
9-
// whitespace and other invisible characters - takes over the kind of its
10-
// neighbours
11-
ItalicKindNeutral,
12-
// character must not be slanted at all (text attachments)
9+
// character must not be slanted at all (whitespace, control characters,
10+
// text attachments)
1311
ItalicKindNone,
1412
// font has a real italic glyph for the character
1513
ItalicKindFont,
@@ -97,8 +95,6 @@ + (void)applyItalicForFont:(UIFont *)font
9795
hasItalicFace:hasItalicFace])];
9896
}];
9997

100-
[self resolveNeutralKinds:clusterKinds];
101-
10298
// merge neighbouring clusters of the same kind and apply the style
10399
NSUInteger index = 0;
104100
while (index < clusterKinds.count) {
@@ -129,7 +125,7 @@ + (ItalicKind)kindForCluster:(NSString *)cluster
129125
hasItalicFace:(BOOL)hasItalicFace {
130126
if ([cluster rangeOfCharacterFromSet:[NeutralCharacters() invertedSet]]
131127
.location == NSNotFound) {
132-
return ItalicKindNeutral;
128+
return ItalicKindNone;
133129
}
134130

135131
// we just need to analyze the first unicode character to classify the whole
@@ -154,23 +150,10 @@ + (ItalicKind)kindForCluster:(NSString *)cluster
154150
return ItalicKindFont;
155151
}
156152

157-
// italic is not supported, we use the slate instead
153+
// italic is not supported, we use the slant instead
158154
return ItalicKindOblique;
159155
}
160156

161-
// neutral clusters take over the preceding kind
162-
+ (void)resolveNeutralKinds:(NSMutableArray<NSNumber *> *)kinds {
163-
ItalicKind previous = ItalicKindNeutral;
164-
for (NSUInteger i = 0; i < kinds.count; i += 1) {
165-
ItalicKind kind = (ItalicKind)[kinds[i] integerValue];
166-
if (kind == ItalicKindNeutral) {
167-
kinds[i] = @(previous);
168-
} else {
169-
previous = kind;
170-
}
171-
}
172-
}
173-
174157
+ (void)applyKind:(ItalicKind)kind
175158
toSegment:(NSRange)segment
176159
inTextStorage:(NSTextStorage *)textStorage
@@ -188,7 +171,6 @@ + (void)applyKind:(ItalicKind)kind
188171
range:segment];
189172
break;
190173
case ItalicKindNone:
191-
case ItalicKindNeutral:
192174
[textStorage removeAttribute:NSObliquenessAttributeName range:segment];
193175
break;
194176
}

0 commit comments

Comments
 (0)