From 7922c5d57959d13a70535a9b259236da3cdfbebc Mon Sep 17 00:00:00 2001 From: Daniel Saidi Date: Tue, 8 Oct 2024 23:12:14 +0100 Subject: [PATCH] Make text view only set image configuration if it's not manually set before --- RELEASE_NOTES.md | 6 +++++- Sources/RichTextKit/RichTextView+Setup.swift | 4 +++- Sources/RichTextKit/RichTextView_AppKit.swift | 7 ++++++- Sources/RichTextKit/RichTextView_UIKit.swift | 4 ++++ 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index c44962966..262b1a6eb 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -27,7 +27,11 @@ Reach out if you think that this version changes too much for a minor bump, or i * Many protocols now use `@preconcurrency @MainActor`. * All mutable `Image` and `Color` extensions are now computed. -* All standard style and configuration values are now computed. +* All standard style and configuration values are now computed. + +### 🐛 Bug Fixes + +* `RichTextView` only sets image configuration if it's not manually set before. diff --git a/Sources/RichTextKit/RichTextView+Setup.swift b/Sources/RichTextKit/RichTextView+Setup.swift index cde742b53..b363e0606 100644 --- a/Sources/RichTextKit/RichTextView+Setup.swift +++ b/Sources/RichTextKit/RichTextView+Setup.swift @@ -16,7 +16,9 @@ extension RichTextView { _ format: RichTextDataFormat ) { attributedString = .empty - imageConfiguration = standardImageConfiguration(for: format) + if !imageConfigurationWasSet { + imageConfiguration = standardImageConfiguration(for: format) + } attributedString = text setContentCompressionResistancePriority(.defaultLow, for: .horizontal) } diff --git a/Sources/RichTextKit/RichTextView_AppKit.swift b/Sources/RichTextKit/RichTextView_AppKit.swift index a7d90ff0b..f8b6a7b84 100644 --- a/Sources/RichTextKit/RichTextView_AppKit.swift +++ b/Sources/RichTextKit/RichTextView_AppKit.swift @@ -39,7 +39,12 @@ open class RichTextView: NSTextView, RichTextViewComponent { public var highlightingStyle: RichTextHighlightingStyle = .standard /// The image configuration to use by the rich text view. - public var imageConfiguration: RichTextImageConfiguration = .disabled + public var imageConfiguration: RichTextImageConfiguration = .disabled { + didSet { imageConfigurationWasSet = true } + } + + /// The image configuration to use by the rich text view. + var imageConfigurationWasSet = false // MARK: - Overrides diff --git a/Sources/RichTextKit/RichTextView_UIKit.swift b/Sources/RichTextKit/RichTextView_UIKit.swift index 273589186..e291dff26 100644 --- a/Sources/RichTextKit/RichTextView_UIKit.swift +++ b/Sources/RichTextKit/RichTextView_UIKit.swift @@ -98,10 +98,14 @@ open class RichTextView: UITextView, RichTextViewComponent { didSet { #if iOS || os(visionOS) refreshDropInteraction() + imageConfigurationWasSet = true #endif } } + /// The image configuration to use by the rich text view. + var imageConfigurationWasSet = false + #if iOS || os(visionOS) /// The image drop interaction to use.