Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't disable image pasting #158

Open
dave0111 opened this issue Mar 6, 2024 · 2 comments
Open

Can't disable image pasting #158

dave0111 opened this issue Mar 6, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@dave0111
Copy link

dave0111 commented Mar 6, 2024

I'm trying to disable the possibility to past an image in RichTextEditor but can't get it to work.

So far, I've been trying to use imageConfiguration, that, from what I could understand, should work like this

RichTextEditor(text: self.$text,
                          context: self.context) {
            
     $0.imageConfiguration = .init(pasteConfiguration: .disabled,
                                                        dropConfiguration: .disabled,
                                                        maxImageSize: (width: .points(0), height: .points(0)))
            
     print("Paste config: \($0.imagePasteConfiguration)") // This prints "disabled" as expected
}

However, it still allows me to paste images.

This doesn't work either:

RichTextEditor(text: self.$text,
                          context: self.context) {
            
     $0.imageConfiguration = .disabled
            
     print("Paste config: \($0.imagePasteConfiguration)") // This prints "disabled" as expected
}

Am I doing something wrong? Because I couldn't find any other way of preventing the user from inserting an image

@carminchameleon
Copy link

carminchameleon commented Apr 23, 2024

I'm curious about this too!

I set the format to .plainText to prevent image pasting, and it worked.
However, we also support iPads. so users can drag and drop images into the text editor on these devices.

 RichTextEditor(text: $vm.attributedText, context: context, format: .plainText) {
                    $0.setRichTextColor(.foreground, to: UIColor.textOnSurfaceBackground)
                    $0.imageConfiguration = RichTextImageConfiguration(pasteConfiguration: .disabled, dropConfiguration: .disabled,maxImageSize: (width: RichTextImageAttachmentSize.points(0), height: RichTextImageAttachmentSize.points(0)))                    
                }

If there is another way to prevent drag drop, please let me know!

@danielsaidi
Copy link
Owner

Hi @dave0111 and @carminchameleon

Setting the paste configuration should work, so this may have gotten lost when rewriting the action handling earlier in 2024.

I'm busy work other projects atm, but will happily merge any fix for this.

@danielsaidi danielsaidi added the bug Something isn't working label Apr 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants