input: preserve mention links when inserting text before them
Previously, inserting text right before a mention (@user) would remove the link attribute, breaking the mention. This was because the intersection check in shouldChangeTextIn would trigger and remove the link for any edit that touched the link boundary. Added a new condition to handle insertion at the left edge of a link separately, similar to the existing handling for the right edge. This allows users to type before a mention without breaking it. Added UI test that creates a real mention via autocomplete selection, then verifies text can be typed before it without corrupting the mention. The test uses predicate-based waits for reliability and properly marks the UserView as an accessibility element. Link attribute preservation is verified in unit tests. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Changelog-Fixed: Fixed mentions unlinking when typing text before them Closes: https://github.com/damus-io/damus/pull/3473 Closes: https://github.com/damus-io/damus/issues/3460 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> Tested-by: William Casarin <jb55@jb55.com> Signed-off-by: alltheseas <alltheseas@users.noreply.github.com> Reviewed-by: William Casarin <jb55@jb55.com>
This commit is contained in:
committed by
Daniel D’Aquino
parent
4941b502d5
commit
a4ad4960c4
@@ -107,12 +107,13 @@ final class PostViewTests: XCTestCase {
|
||||
XCTAssertNil(newManuallyEditedContent.attribute(.link, at: 6, effectiveRange: nil))
|
||||
})
|
||||
|
||||
// Test adding text right at the start of a mention link, to check that the link is removed
|
||||
// Test adding text right at the start of a mention link - link should be preserved
|
||||
content = NSMutableAttributedString(string: "Hello @user")
|
||||
content.addAttribute(.link, value: "damus:1234", range: NSRange(location: 6, length: 5))
|
||||
checkMentionLinkEditorHandling(content: content, replacementText: "a", replacementRange: NSRange(location: 6, length: 0), shouldBeAbleToChangeAutomatically: false, expectedNewCursorIndex: 7, handleNewContent: { newManuallyEditedContent in
|
||||
XCTAssertEqual(newManuallyEditedContent.string, "Hello a@user")
|
||||
XCTAssertNil(newManuallyEditedContent.attribute(.link, at: 7, effectiveRange: nil))
|
||||
// Link should be preserved and shifted to position 7 (after the inserted "a")
|
||||
XCTAssertNotNil(newManuallyEditedContent.attribute(.link, at: 7, effectiveRange: nil))
|
||||
})
|
||||
|
||||
// Test that removing one link does not affect the other
|
||||
|
||||
Reference in New Issue
Block a user