Skip to content

Commit

Permalink
Fixed backspace callbaco on attachments (#288)
Browse files Browse the repository at this point in the history
  • Loading branch information
rajdeep authored Feb 29, 2024
1 parent 0b81209 commit 9ca0289
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ extension CommandsExampleViewController: EditorViewDelegate {
print("Key: \(key)")
}

func editor(_ editor: EditorView, shouldSelectAttachmentOnBackspace attachment: Attachment) -> Bool {
func editor(_ editor: EditorView, shouldSelectAttachmentOnBackspace attachment: Attachment) -> Bool? {
guard let panel = attachment as? PanelAttachment, panel.isInSelectedRange == false else { return false }

panel.view.editor.setFocus()
Expand Down
2 changes: 1 addition & 1 deletion Proton/Sources/Swift/Core/RichTextEditorContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class RichTextEditorContext: RichTextViewContext {
range.location <= attributedText.length, // ... within bounds
let attachment = attributedText.attribute(.attachment, at: range.location, effectiveRange: nil) as? Attachment,
let delegate = richTextView.richTextViewDelegate,
(delegate.richTextView(richTextView, shouldSelectAttachmentOnBackspace: attachment) ||
(delegate.richTextView(richTextView, shouldSelectAttachmentOnBackspace: attachment) == true ||
attachment.selectBeforeDelete), // ...should be selected
!attachment.isSelected // ... but isn't.
{
Expand Down
2 changes: 1 addition & 1 deletion Proton/Sources/Swift/Core/RichTextViewDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ protocol RichTextViewDelegate: AnyObject {
func richTextView(_ richTextView: RichTextView, didChangeTextAtRange range: NSRange)
func richTextView(_ richTextView: RichTextView, didTapAtLocation location: CGPoint, characterRange: NSRange?)
func richTextView(_ richTextView: RichTextView, selectedRangeChangedFrom oldRange: NSRange?, to newRange: NSRange?)
func richTextView(_ richTextView: RichTextView, shouldSelectAttachmentOnBackspace attachment: Attachment) -> Bool
func richTextView(_ richTextView: RichTextView, shouldSelectAttachmentOnBackspace attachment: Attachment) -> Bool?
}

protocol RichTextViewListDelegate: AnyObject {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class AggregateEditorViewDelegate: EditorViewDelegate {
editor.editorContextDelegate?.editor(editor, didRenderAttachment: attachment)
}

static func editor(_ editor: EditorView, shouldSelectAttachmentOnBackspace attachment: Attachment) -> Bool {
static func editor(_ editor: EditorView, shouldSelectAttachmentOnBackspace attachment: Attachment) -> Bool? {
return editor.delegate?.editor(editor, shouldSelectAttachmentOnBackspace: attachment) ??
editor.editorContextDelegate?.editor(editor, shouldSelectAttachmentOnBackspace: attachment) ??
attachment.selectBeforeDelete
Expand Down
2 changes: 1 addition & 1 deletion Proton/Sources/Swift/Editor/EditorView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1399,7 +1399,7 @@ extension EditorView: RichTextViewDelegate {
AggregateEditorViewDelegate.editor(self, didTapAtLocation: location, characterRange: characterRange)
}

func richTextView(_ richTextView: RichTextView, shouldSelectAttachmentOnBackspace attachment: Attachment) -> Bool {
func richTextView(_ richTextView: RichTextView, shouldSelectAttachmentOnBackspace attachment: Attachment) -> Bool? {
AggregateEditorViewDelegate.editor(self, shouldSelectAttachmentOnBackspace: attachment)
}
}
Expand Down
6 changes: 3 additions & 3 deletions Proton/Sources/Swift/Editor/EditorViewDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public protocol EditorViewDelegate: AnyObject {
/// - attachment: Attachment at the range where backspace is received
/// - Returns: `true` to delete, else `false`
/// - Note: If either this or`Attachment`s property of `selectBeforeDelete` is `true`, the attachment will be shown as selected on backspace.
func editor(_ editor: EditorView, shouldSelectAttachmentOnBackspace attachment: Attachment) -> Bool
func editor(_ editor: EditorView, shouldSelectAttachmentOnBackspace attachment: Attachment) -> Bool?
}

public extension EditorViewDelegate {
Expand All @@ -152,7 +152,7 @@ public extension EditorViewDelegate {
func editor(_ editor: EditorView, isReady: Bool) { }
func editor(_ editor: EditorView, didChangeEditable isEditable: Bool) { }
func editor(_ editor: EditorView, didRenderAttachment attachment: Attachment) { }
func editor(_ editor: EditorView, shouldSelectAttachmentOnBackspace attachment: Attachment) -> Bool {
attachment.selectBeforeDelete
func editor(_ editor: EditorView, shouldSelectAttachmentOnBackspace attachment: Attachment) -> Bool? {
return nil
}
}
2 changes: 1 addition & 1 deletion Proton/Tests/Core/Mocks/MockRichTextViewDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class MockRichTextViewDelegate: RichTextViewDelegate {
onSelectedRangeChanged?(richTextView, oldRange, newRange)
}

func richTextView(_ richTextView: RichTextView, shouldSelectAttachmentOnBackspace attachment: Attachment) -> Bool {
func richTextView(_ richTextView: RichTextView, shouldSelectAttachmentOnBackspace attachment: Attachment) -> Bool? {
onShouldSelectAttachmentOnBackspace?(richTextView, attachment) ?? false
}
}

0 comments on commit 9ca0289

Please sign in to comment.