Skip to content

Commit

Permalink
Add common custom attribute key for green editor text
Browse files Browse the repository at this point in the history
  • Loading branch information
tonisevener committed Dec 14, 2023
1 parent 970c853 commit 0ccd7a5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Components/Sources/ComponentsObjC/WKSourceEditorFormatter.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
NS_ASSUME_NONNULL_BEGIN

@interface WKSourceEditorFormatter : NSObject

extern NSString *const WKSourceEditorCustomKeyColorGreen;

- (instancetype)initWithColors:(nonnull WKSourceEditorColors *)colors fonts:(nonnull WKSourceEditorFonts *)fonts;
- (void)addSyntaxHighlightingToAttributedString:(NSMutableAttributedString *)attributedString inRange:(NSRange)range;

Expand Down
5 changes: 5 additions & 0 deletions Components/Sources/ComponentsObjC/WKSourceEditorFormatter.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
#import "WKSourceEditorFonts.h"

@implementation WKSourceEditorFormatter

#pragma mark - Common Custom Attributed String Keys

NSString * const WKSourceEditorCustomKeyColorGreen = @"WKSourceEditorKeyColorGreen";

- (nonnull instancetype)initWithColors:(nonnull WKSourceEditorColors *)colors fonts:(nonnull WKSourceEditorFonts *)fonts {
self = [super init];
return self;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,13 @@ - (instancetype)initWithColors:(nonnull WKSourceEditorColors *)colors fonts:(non

- (void)addSyntaxHighlightingToAttributedString:(NSMutableAttributedString *)attributedString inRange:(NSRange)range {

// reset old attributes
// reset base attributes
[attributedString removeAttribute:NSFontAttributeName range:range];
[attributedString removeAttribute:NSForegroundColorAttributeName range:range];

// reset shared custom attributes
[attributedString removeAttribute:WKSourceEditorCustomKeyColorGreen range:range];

[attributedString addAttributes:self.attributes range:range];
}

Expand Down

0 comments on commit 0ccd7a5

Please sign in to comment.