Skip to content

Commit

Permalink
Fixed logic for attachment ranges (#311)
Browse files Browse the repository at this point in the history
  • Loading branch information
rajdeep authored Jun 12, 2024
1 parent 6a50730 commit 393b5ff
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Proton/Sources/Swift/Editor/EditorView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@ open class EditorView: UIView {
}

public func attachmentsInRange(_ range: NSRange) -> [AttachmentRange] {
guard range.endLocation < attributedText.length else { return [] }
guard range.endLocation <= attributedText.length else { return [] }
let substring = attributedText.attributedSubstring(from: range)
return substring.attachmentRanges
}
Expand Down
17 changes: 17 additions & 0 deletions Proton/Tests/Editor/EditorViewTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,23 @@ class EditorViewTests: XCTestCase {
XCTAssertEqual(text.string, expectedString)
}

func testAttachmentsInRangeWithValidRange() {
let editor = EditorView()

let panel1 = PanelView()
panel1.editor.replaceCharacters(in: .zero, with: NSAttributedString(string: "Text inside panel 1"))
let panelAttachment1 = Attachment(panel1, size: .matchContent)
editor.insertAttachment(in: editor.textEndRange, attachment: panelAttachment1)

let panel2 = PanelView()
panel2.editor.replaceCharacters(in: .zero, with: NSAttributedString(string: "Text inside panel 2"))
let panelAttachment2 = Attachment(panel2, size: .matchContent)
editor.insertAttachment(in: editor.textEndRange, attachment: panelAttachment2)

let attachments = editor.attachmentsInRange(NSRange(location: editor.attributedText.length - 2, length: 2))
XCTAssertEqual(attachments.count, 1)
}

func testGetsFullAttributedTextFromRange() {
let viewController = EditorTestViewController()
let editor = viewController.editor
Expand Down

0 comments on commit 393b5ff

Please sign in to comment.