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 */
canDrag = granularity == NSSelectByCharacter
&& NSLocationInRange(startIndex, _layoutManager->_selected_range);
canDrag = granularity == NSSelectByCharacter && NSLocationInRange(startIndex, _layoutManager->_selected_range);
proposedRange = NSMakeRange (startIndex, 0);
/* We manage clicks on attachments and links only on the first
@ -5603,28 +5602,37 @@ other than copy/paste or dragging. */
if (cell != nil)
{
NSRect cellFrame;
NSRect lfRect;
NSUInteger glyphIndex;
NSRect cellFrame = NSZeroRect;
glyphIndex =
[_layoutManager
glyphRangeForCharacterRange: NSMakeRange(startIndex, 1)
actualCharacterRange: NULL].location;
lfRect =
[_layoutManager
lineFragmentRectForGlyphAtIndex: glyphIndex
if (startIndex >= [_textStorage length])
{
NSUInteger glyphIndex = [_textStorage length]-1;
NSRect lfRect = [_layoutManager lineFragmentRectForGlyphAtIndex: glyphIndex
effectiveRange: NULL];
cellFrame.origin =
[_layoutManager
locationForGlyphAtIndex: glyphIndex];
cellFrame.size =
[_layoutManager
attachmentSizeForGlyphAtIndex: glyphIndex];
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;
}
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 ? */
if ([cell wantsToTrackMouseForEvent: theEvent
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
is some chars with the NSLinkAttributeName set to something
@ -5661,8 +5670,7 @@ other than copy/paste or dragging. */
if ([_delegate respondsToSelector: selector])
{
/* Move the insertion point over the link. */
chosenRange = [self selectionRangeForProposedRange:
proposedRange
chosenRange = [self selectionRangeForProposedRange: proposedRange
granularity: granularity];
[self setSelectedRange: chosenRange affinity: affinity
@ -5741,7 +5749,9 @@ other than copy/paste or dragging. */
gotPeriodic = YES;
}
else
{
lastEvent = currentEvent;
}
currentEvent = [_window nextEventMatchingMask: mask
untilDate: distantPast
inMode: NSEventTrackingRunLoopMode