@@ -94,7 +94,8 @@ - (void)setDefaults {
9494 @([UnorderedListStyle getStyleType ]): [[UnorderedListStyle alloc ] initWithInput: self ],
9595 @([OrderedListStyle getStyleType ]): [[OrderedListStyle alloc ] initWithInput: self ],
9696 @([BlockQuoteStyle getStyleType ]): [[BlockQuoteStyle alloc ] initWithInput: self ],
97- @([CodeBlockStyle getStyleType ]): [[CodeBlockStyle alloc ] initWithInput: self ]
97+ @([CodeBlockStyle getStyleType ]): [[CodeBlockStyle alloc ] initWithInput: self ],
98+ @([ImageStyle getStyleType ]): [[ImageStyle alloc ] initWithInput: self ]
9899 };
99100
100101 conflictingStyles = @{
@@ -112,24 +113,26 @@ - (void)setDefaults {
112113 @([OrderedListStyle getStyleType ]): @[@([H1Style getStyleType ]), @([H2Style getStyleType ]), @([H3Style getStyleType ]), @([UnorderedListStyle getStyleType ]), @([BlockQuoteStyle getStyleType ]), @([CodeBlockStyle getStyleType ])],
113114 @([BlockQuoteStyle getStyleType ]): @[@([H1Style getStyleType ]), @([H2Style getStyleType ]), @([H3Style getStyleType ]), @([UnorderedListStyle getStyleType ]), @([OrderedListStyle getStyleType ]), @([CodeBlockStyle getStyleType ])],
114115 @([CodeBlockStyle getStyleType ]): @[@([H1Style getStyleType ]), @([H2Style getStyleType ]), @([H3Style getStyleType ]),
115- @([BoldStyle getStyleType ]), @([ItalicStyle getStyleType ]), @([UnderlineStyle getStyleType ]), @([StrikethroughStyle getStyleType ]), @([UnorderedListStyle getStyleType ]), @([OrderedListStyle getStyleType ]), @([BlockQuoteStyle getStyleType ]), @([InlineCodeStyle getStyleType ]), @([MentionStyle getStyleType ]), @([LinkStyle getStyleType ])]
116+ @([BoldStyle getStyleType ]), @([ItalicStyle getStyleType ]), @([UnderlineStyle getStyleType ]), @([StrikethroughStyle getStyleType ]), @([UnorderedListStyle getStyleType ]), @([OrderedListStyle getStyleType ]), @([BlockQuoteStyle getStyleType ]), @([InlineCodeStyle getStyleType ]), @([MentionStyle getStyleType ]), @([LinkStyle getStyleType ])],
117+ @([ImageStyle getStyleType ]) : @[@([LinkStyle getStyleType ]), @([MentionStyle getStyleType ])]
116118 };
117119
118120 blockingStyles = @{
119121 @([BoldStyle getStyleType ]) : @[@([CodeBlockStyle getStyleType ])],
120122 @([ItalicStyle getStyleType ]) : @[@([CodeBlockStyle getStyleType ])],
121123 @([UnderlineStyle getStyleType ]) : @[@([CodeBlockStyle getStyleType ])],
122124 @([StrikethroughStyle getStyleType ]) : @[@([CodeBlockStyle getStyleType ])],
123- @([InlineCodeStyle getStyleType ]) : @[@([CodeBlockStyle getStyleType ])],
124- @([LinkStyle getStyleType ]): @[@([CodeBlockStyle getStyleType ])],
125- @([MentionStyle getStyleType ]): @[@([CodeBlockStyle getStyleType ])],
125+ @([InlineCodeStyle getStyleType ]) : @[@([CodeBlockStyle getStyleType ]), @([ImageStyle getStyleType ]) ],
126+ @([LinkStyle getStyleType ]): @[@([CodeBlockStyle getStyleType ]), @([ImageStyle getStyleType ]) ],
127+ @([MentionStyle getStyleType ]): @[@([CodeBlockStyle getStyleType ]), @([ImageStyle getStyleType ]) ],
126128 @([H1Style getStyleType ]): @[],
127129 @([H2Style getStyleType ]): @[],
128130 @([H3Style getStyleType ]): @[],
129131 @([UnorderedListStyle getStyleType ]): @[],
130132 @([OrderedListStyle getStyleType ]): @[],
131133 @([BlockQuoteStyle getStyleType ]): @[],
132134 @([CodeBlockStyle getStyleType ]): @[],
135+ @([ImageStyle getStyleType ]) : @[@([InlineCodeStyle getStyleType ])]
133136 };
134137
135138 parser = [[InputParser alloc ] initWithInput: self ];
@@ -368,6 +371,16 @@ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &
368371 stylePropChanged = YES ;
369372 }
370373
374+ if (newViewProps.htmlStyle .img .width != oldViewProps.htmlStyle .img .width ) {
375+ [newConfig setImageWidth: newViewProps.htmlStyle.img.width];
376+ stylePropChanged = YES ;
377+ }
378+
379+ if (newViewProps.htmlStyle .img .height != oldViewProps.htmlStyle .img .height ) {
380+ [newConfig setImageHeight: newViewProps.htmlStyle.img.height];
381+ stylePropChanged = YES ;
382+ }
383+
371384 if (newViewProps.htmlStyle .a .textDecorationLine != oldViewProps.htmlStyle .a .textDecorationLine ) {
372385 NSString *objcString = [NSString fromCppString: newViewProps.htmlStyle.a.textDecorationLine];
373386 if ([objcString isEqualToString: DecorationUnderline]) {
@@ -723,7 +736,7 @@ - (void)tryUpdatingActiveStyles {
723736 .isOrderedList = [_activeStyles containsObject: @([OrderedListStyle getStyleType ])],
724737 .isBlockQuote = [_activeStyles containsObject: @([BlockQuoteStyle getStyleType ])],
725738 .isCodeBlock = [_activeStyles containsObject: @([CodeBlockStyle getStyleType ])],
726- .isImage = NO // [_activeStyles containsObject: @([ImageStyle getStyleType] ])],
739+ .isImage = [_activeStyles containsObject: @([ImageStyle getStyleType ])],
727740 });
728741 }
729742 }
@@ -793,6 +806,9 @@ - (void)handleCommand:(const NSString *)commandName args:(const NSArray *)args {
793806 [self toggleParagraphStyle: [BlockQuoteStyle getStyleType ]];
794807 } else if ([commandName isEqualToString: @" toggleCodeBlock" ]) {
795808 [self toggleParagraphStyle: [CodeBlockStyle getStyleType ]];
809+ } else if ([commandName isEqualToString: @" addImage" ]) {
810+ NSString *uri = (NSString *)args[0 ];
811+ [self addImage: uri];
796812 }
797813}
798814
@@ -939,6 +955,17 @@ - (void)addMention:(NSString *)indicator text:(NSString *)text attributes:(NSStr
939955 }
940956}
941957
958+ - (void )addImage : (NSString *)uri
959+ {
960+ ImageStyle *imageStyleClass = (ImageStyle *)stylesDict[@([ImageStyle getStyleType ])];
961+ if (imageStyleClass == nullptr ) { return ; }
962+
963+ if ([self handleStyleBlocksAndConflicts: [ImageStyle getStyleType ] range: textView.selectedRange]) {
964+ [imageStyleClass addImage: uri];
965+ [self anyTextMayHaveBeenModified ];
966+ }
967+ }
968+
942969- (void )startMentionWithIndicator : (NSString *)indicator {
943970 MentionStyle *mentionStyleClass = (MentionStyle *)stylesDict[@([MentionStyle getStyleType ])];
944971 if (mentionStyleClass == nullptr ) { return ; }
0 commit comments