-
Notifications
You must be signed in to change notification settings - Fork 149
Implement undo and redo when removing attachments by code. #572
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
Changes from all commits
8648cb5
b6ba092
370e7e4
9d2d25b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -972,18 +972,28 @@ open class TextView: UITextView { | |
| return storage.attachment(withId: id) | ||
| } | ||
|
|
||
| /// Removes the attachments that match the attachament identifier provided from the storage | ||
| /// Removes the attachment that matches the attachment identifier provided from the storage | ||
| /// | ||
| /// - Parameter attachmentID: the unique id of the attachment | ||
| /// | ||
| open func remove(attachmentID: String) { | ||
| storage.remove(attachmentID: attachmentID) | ||
| guard let range = storage.rangeFor(attachmentID: attachmentID) else { | ||
| return | ||
| } | ||
| let originalText = storage.attributedSubstring(from: range) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From line 983 to line 990 we're repeating code that's in several other places in Why not implement in to take care of unified undo support?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good suggestion may I do this in another PR just dedicated to that refactor?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure. |
||
| let finalRange = NSRange(location: range.location, length: 0) | ||
|
|
||
| undoManager?.registerUndo(withTarget: self, handler: { [weak self] target in | ||
| self?.undoTextReplacement(of: originalText, finalRange: finalRange) | ||
| }) | ||
|
|
||
| storage.replaceCharacters(in: range, with: NSAttributedString(string: "", attributes: typingAttributes)) | ||
| delegate?.textViewDidChange?(self) | ||
| } | ||
|
|
||
| /// Removes all of the text attachments contained within the storage | ||
| /// | ||
| open func removeTextAttachments() { | ||
| open func removeMediaAttachments() { | ||
| storage.removeMediaAttachments() | ||
| delegate?.textViewDidChange?(self) | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method is no longer called from anywhere in the code. We should remove it from
TextStorage.swift.