Fix index beyond range in text attachment processing in mouseDown

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/branches/gnustep_testplant_branch@38227 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Marcian Lytwyn 2014-12-03 18:49:58 +00:00
parent 0dc0c821f9
commit fd815172ac

View file

@ -5580,8 +5580,7 @@ other than copy/paste or dragging. */
} }
/* A single click into the selected range can start a drag operation */ /* A single click into the selected range can start a drag operation */
canDrag = granularity == NSSelectByCharacter canDrag = granularity == NSSelectByCharacter && NSLocationInRange(startIndex, _layoutManager->_selected_range);
&& NSLocationInRange(startIndex, _layoutManager->_selected_range);
proposedRange = NSMakeRange (startIndex, 0); proposedRange = NSMakeRange (startIndex, 0);
/* We manage clicks on attachments and links only on the first /* We manage clicks on attachments and links only on the first
@ -5603,28 +5602,37 @@ other than copy/paste or dragging. */
if (cell != nil) if (cell != nil)
{ {
NSRect cellFrame; NSRect cellFrame = NSZeroRect;
NSRect lfRect;
NSUInteger glyphIndex;
glyphIndex = if (startIndex >= [_textStorage length])
[_layoutManager {
glyphRangeForCharacterRange: NSMakeRange(startIndex, 1) NSUInteger glyphIndex = [_textStorage length]-1;
actualCharacterRange: NULL].location; NSRect lfRect = [_layoutManager lineFragmentRectForGlyphAtIndex: glyphIndex
lfRect =
[_layoutManager
lineFragmentRectForGlyphAtIndex: glyphIndex
effectiveRange: NULL]; effectiveRange: NULL];
cellFrame.origin = cellFrame.origin = [_layoutManager locationForGlyphAtIndex: glyphIndex];
[_layoutManager cellFrame.size = [_layoutManager attachmentSizeForGlyphAtIndex: glyphIndex];
locationForGlyphAtIndex: glyphIndex];
cellFrame.size =
[_layoutManager
attachmentSizeForGlyphAtIndex: glyphIndex];
cellFrame.origin.y -= cellFrame.size.height; cellFrame.origin.y -= cellFrame.size.height;
cellFrame.origin.x += lfRect.origin.x; cellFrame.origin.x += lfRect.origin.x;
cellFrame.origin.y += lfRect.origin.y; cellFrame.origin.y += lfRect.origin.y;
}
else
{
NSRect lfRect;
NSUInteger glyphIndex;
glyphIndex = [_layoutManager glyphRangeForCharacterRange: NSMakeRange(startIndex, 1)
actualCharacterRange: NULL].location;
lfRect = [_layoutManager lineFragmentRectForGlyphAtIndex: glyphIndex
effectiveRange: NULL];
cellFrame.origin = [_layoutManager locationForGlyphAtIndex: glyphIndex];
cellFrame.size = [_layoutManager attachmentSizeForGlyphAtIndex: glyphIndex];
cellFrame.origin.y -= cellFrame.size.height;
cellFrame.origin.x += lfRect.origin.x;
cellFrame.origin.y += lfRect.origin.y;
}
if (NSEqualRects(NSZeroRect, cellFrame) == NO)
{
/* TODO: What about the insertion point ? */ /* TODO: What about the insertion point ? */
if ([cell wantsToTrackMouseForEvent: theEvent if ([cell wantsToTrackMouseForEvent: theEvent
inRect: cellFrame inRect: cellFrame
@ -5640,6 +5648,7 @@ other than copy/paste or dragging. */
} }
} }
} }
}
/* This is the code for handling click event on a link (a link /* This is the code for handling click event on a link (a link
is some chars with the NSLinkAttributeName set to something is some chars with the NSLinkAttributeName set to something
@ -5661,8 +5670,7 @@ other than copy/paste or dragging. */
if ([_delegate respondsToSelector: selector]) if ([_delegate respondsToSelector: selector])
{ {
/* Move the insertion point over the link. */ /* Move the insertion point over the link. */
chosenRange = [self selectionRangeForProposedRange: chosenRange = [self selectionRangeForProposedRange: proposedRange
proposedRange
granularity: granularity]; granularity: granularity];
[self setSelectedRange: chosenRange affinity: affinity [self setSelectedRange: chosenRange affinity: affinity
@ -5741,7 +5749,9 @@ other than copy/paste or dragging. */
gotPeriodic = YES; gotPeriodic = YES;
} }
else else
{
lastEvent = currentEvent; lastEvent = currentEvent;
}
currentEvent = [_window nextEventMatchingMask: mask currentEvent = [_window nextEventMatchingMask: mask
untilDate: distantPast untilDate: distantPast
inMode: NSEventTrackingRunLoopMode inMode: NSEventTrackingRunLoopMode