From 85155fd64fb9255b0ec7a7f4c2eb17fe08ac6035 Mon Sep 17 00:00:00 2001 From: Riccardo Mottola Date: Tue, 11 Oct 2022 23:26:51 +0200 Subject: [PATCH] Fix click on TextAttachmentCells, where the left side was not respected. This was because index was respecting fraction and thus loosing the attachment when clicking on the right part, only for this case, recalculate character index without respectFraction. --- ChangeLog | 8 ++++++++ Source/NSTextView.m | 14 ++++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index cd64d206db..7771552d55 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2022-10-11 Riccardo Mottola + + * Source/NSTextView.m + Fix click on TextAttachmentCells, where the left side was not respected. + This was because index was respecting fraction and thus loosing the + attachment when clicking on the right part, only for this case, + recalculate character index without respectFraction. + 2022-09-01 Gregory John Casamento * Source/NSButtonCell.m: Move method to detect if button is a diff --git a/Source/NSTextView.m b/Source/NSTextView.m index 8d98d13346..c03450fda5 100644 --- a/Source/NSTextView.m +++ b/Source/NSTextView.m @@ -5554,12 +5554,18 @@ - (void) mouseDown: (NSEvent *)theEvent if (granularity == NSSelectByCharacter) { NSTextAttachment *attachment; + NSInteger startIndexNoFraction; + + /* since we look for an attachment with by-character granularity, + recalculate the index without resepecting fraction */ + startIndexNoFraction = [self _characterIndexForPoint: startPoint + respectFraction: NO]; /* Check if the click was on an attachment cell. */ attachment = [_textStorage attribute: NSAttachmentAttributeName - atIndex: startIndex + atIndex: startIndexNoFraction effectiveRange: NULL]; - + if (attachment != nil) { id cell = [attachment attachmentCell]; @@ -5594,11 +5600,11 @@ - (void) mouseDown: (NSEvent *)theEvent if ([cell wantsToTrackMouseForEvent: theEvent inRect: cellFrame ofView: self - atCharacterIndex: startIndex] + atCharacterIndex: startIndexNoFraction] && [cell trackMouse: theEvent inRect: cellFrame ofView: self - atCharacterIndex: startIndex + atCharacterIndex: startIndexNoFraction untilMouseUp: NO]) { return;