From cddc9fc8071738046ca502c1d828bdafaa3334e6 Mon Sep 17 00:00:00 2001 From: Sergio Estevao Date: Fri, 17 Nov 2017 10:40:26 +0000 Subject: [PATCH 1/2] Output size full. --- .../Conversions/AttributedStringParser.swift | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Aztec/Classes/NSAttributedString/Conversions/AttributedStringParser.swift b/Aztec/Classes/NSAttributedString/Conversions/AttributedStringParser.swift index 3adec7ce1..951210691 100644 --- a/Aztec/Classes/NSAttributedString/Conversions/AttributedStringParser.swift +++ b/Aztec/Classes/NSAttributedString/Conversions/AttributedStringParser.swift @@ -1004,10 +1004,8 @@ private extension AttributedStringParser { style += attachment.alignment.htmlString() } - if attachment.size != .full { - style += style.isEmpty ? String() : String(.space) - style += attachment.size.htmlString() - } + style += style.isEmpty ? String() : String(.space) + style += attachment.size.htmlString() guard !style.isEmpty else { return nil From a6d1642c665f356c68a928629f525cc645148bff Mon Sep 17 00:00:00 2001 From: Sergio Estevao Date: Fri, 17 Nov 2017 11:14:58 +0000 Subject: [PATCH 2/2] Add .none style to size to reflect when none is applied. --- .../Conversions/AttributedStringParser.swift | 8 +++++--- Aztec/Classes/TextKit/ImageAttachment.swift | 11 ++++++++--- .../AttachmentDetailsViewController.storyboard | 15 ++++++++------- .../Example/AttachmentDetailsViewController.swift | 3 +++ Example/Example/EditorDemoController.swift | 1 + 5 files changed, 25 insertions(+), 13 deletions(-) diff --git a/Aztec/Classes/NSAttributedString/Conversions/AttributedStringParser.swift b/Aztec/Classes/NSAttributedString/Conversions/AttributedStringParser.swift index 951210691..fa8193f54 100644 --- a/Aztec/Classes/NSAttributedString/Conversions/AttributedStringParser.swift +++ b/Aztec/Classes/NSAttributedString/Conversions/AttributedStringParser.swift @@ -1003,9 +1003,11 @@ private extension AttributedStringParser { if attachment.alignment != .center { style += attachment.alignment.htmlString() } - - style += style.isEmpty ? String() : String(.space) - style += attachment.size.htmlString() + + if attachment.size != .none { + style += style.isEmpty ? String() : String(.space) + style += attachment.size.htmlString() + } guard !style.isEmpty else { return nil diff --git a/Aztec/Classes/TextKit/ImageAttachment.swift b/Aztec/Classes/TextKit/ImageAttachment.swift index 97c1efd15..6a22dd241 100644 --- a/Aztec/Classes/TextKit/ImageAttachment.swift +++ b/Aztec/Classes/TextKit/ImageAttachment.swift @@ -22,7 +22,7 @@ open class ImageAttachment: MediaAttachment { /// Attachment Size /// - open var size: Size = .full { + open var size: Size = .none { willSet { if newValue != size { glyphImage = nil @@ -117,7 +117,7 @@ open class ImageAttachment: MediaAttachment { override func onScreenWidth(_ containerWidth: CGFloat) -> CGFloat { if let image = image { switch (size) { - case .full: + case .full, .none: return floor(min(image.size.width, containerWidth)) default: return floor(min(min(image.size.width,size.width), containerWidth)) @@ -191,6 +191,7 @@ extension ImageAttachment { case medium case large case full + case none func htmlString() -> String { switch self { @@ -202,6 +203,8 @@ extension ImageAttachment { return "size-large" case .full: return "size-full" + case .none: + return "" } } @@ -209,7 +212,8 @@ extension ImageAttachment { Size.thumbnail.htmlString():.thumbnail, Size.medium.htmlString():.medium, Size.large.htmlString():.large, - Size.full.htmlString():.full + Size.full.htmlString():.full, + Size.none.htmlString():.none ] static func fromHTML(string value:String) -> Size? { @@ -222,6 +226,7 @@ extension ImageAttachment { case .medium: return Settings.medium case .large: return Settings.large case .full: return Settings.maximum + case .none: return Settings.maximum } } diff --git a/Example/Example/AttachmentDetailsViewController.storyboard b/Example/Example/AttachmentDetailsViewController.storyboard index e2d18b3b1..c37590223 100644 --- a/Example/Example/AttachmentDetailsViewController.storyboard +++ b/Example/Example/AttachmentDetailsViewController.storyboard @@ -1,11 +1,11 @@ - + - + @@ -29,12 +29,13 @@ - + + @@ -57,7 +58,7 @@ - + @@ -85,7 +86,7 @@ - + @@ -110,7 +111,7 @@ - + @@ -135,7 +136,7 @@ - + diff --git a/Example/Example/AttachmentDetailsViewController.swift b/Example/Example/AttachmentDetailsViewController.swift index 6182728d3..b037be10a 100644 --- a/Example/Example/AttachmentDetailsViewController.swift +++ b/Example/Example/AttachmentDetailsViewController.swift @@ -130,6 +130,7 @@ private extension AttachmentDetailsViewController case medium case large case maximum + case none init(attachmentSize: AttachmentSize) { switch attachmentSize { @@ -137,6 +138,7 @@ private extension AttachmentDetailsViewController case .medium: self = .medium case .large: self = .large case .full: self = .maximum + case .none: self = .none } } @@ -146,6 +148,7 @@ private extension AttachmentDetailsViewController case .medium: return .medium case .large: return .large case .maximum: return .full + case .none: return .none } } } diff --git a/Example/Example/EditorDemoController.swift b/Example/Example/EditorDemoController.swift index 4aefce92b..6f9d4cf4c 100644 --- a/Example/Example/EditorDemoController.swift +++ b/Example/Example/EditorDemoController.swift @@ -1225,6 +1225,7 @@ private extension EditorDemoController let fileURL = saveToDisk(image: image) let attachment = richTextView.replaceWithImage(at: richTextView.selectedRange, sourceURL: fileURL, placeHolderImage: image) + attachment.size = .full attachment.linkURL = fileURL let imageID = attachment.identifier let progress = Progress(parent: nil, userInfo: [MediaProgressKey.mediaID: imageID])