Skip to content

Commit

Permalink
When respecting Preferred Font size, only touch font size and keep ot…
Browse files Browse the repository at this point in the history
…her font attributes
  • Loading branch information
NicolasBuquet committed Nov 20, 2023
1 parent 3fbed20 commit 38c26ea
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
25 changes: 23 additions & 2 deletions Riot/Modules/MatrixKit/Views/MXKMessageTextView.m
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,37 @@ - (void)setAttributedText:(NSAttributedString *)attributedText
if (@available(iOS 15.0, *)) {
[self flushPills];
}

// Tchap: set text type to prefered font to rerspect user text size
attributedText = [self respectPreferredFontForAttributedString:attributedText];

[super setAttributedText:attributedText];

if (@available(iOS 15.0, *)) {
// Fixes an iOS 16 issue where attachment are not drawn properly by
// forcing the layoutManager to redraw the glyphs at all NSAttachment positions.
[self vc_invalidateTextAttachmentsDisplay];
}
}

// Tchap: Update font size using preferred font settings but keeping other attributes
- (NSAttributedString *)respectPreferredFontForAttributedString:(NSAttributedString *)sourceString
{
UIFont *preferredFont = [UIFont preferredFontForTextStyle:UIFontTextStyleBody];

// Tchap: set text type to prefered font to rerspect user text size
self.font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody];
NSMutableAttributedString *workString = [sourceString mutableCopy];

[workString beginEditing];
[workString enumerateAttribute:NSFontAttributeName
inRange:NSMakeRange(0, workString.length)
options:0
usingBlock:^(id _Nullable value, NSRange range, BOOL * _Nonnull stop) {
[workString removeAttribute:NSFontAttributeName range:range];
[workString addAttribute:NSFontAttributeName value:[(UIFont *)value fontWithSize:preferredFont.pointSize] range:range];
}];
[workString endEditing];

return workString;
}

- (void)registerPillView:(UIView *)pillView
Expand Down
1 change: 1 addition & 0 deletions changelog.d/927.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Conserver les enrichissements de texte quand on respecte le réglage de la taille de texte de l'utilisateur

0 comments on commit 38c26ea

Please sign in to comment.