Allow shift-clicking in a text view to shrink the current selection.

Comes handy when you accidentally selected a few characters too much.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@30054 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Wolfgang Lux 2010-03-27 21:29:02 +00:00
parent 79ef3c7045
commit ca3261653b
2 changed files with 23 additions and 15 deletions

View file

@ -1,5 +1,9 @@
2010-03-27 Wolfgang Lux <wolfgang.lux@gmail.com>
* Source/NSTextView.m (-mouseDown:): Allow shift-clicking to
shrink the current selection. Comes handy when you accidentally
select a few characters too much.
* Source/NSTextView.m (-performDragOperation:): Select pasted text
after a DnD operation.

View file

@ -5140,26 +5140,30 @@ other than copy/paste or dragging. */
if ([theEvent modifierFlags] & NSShiftKeyMask)
{
/* Shift-click is for extending an existing selection using
/* Shift-click is for extending or shrinking an existing selection using
the existing granularity */
proposedRange = _layoutManager->_selected_range;
granularity = _layoutManager->_selectionGranularity;
/* Compute the new selection */
proposedRange = NSMakeRange (startIndex, 0);
proposedRange = NSUnionRange (_layoutManager->_selected_range,
proposedRange);
proposedRange = [self selectionRangeForProposedRange: proposedRange
granularity: granularity];
/* Merge it with the old one */
proposedRange = NSUnionRange (_layoutManager->_selected_range,
proposedRange);
/* Now decide what happens if the user shift-drags. The range
will be based in startIndex, so we need to adjust it. */
if (startIndex <= _layoutManager->_selected_range.location)
/* If the clicked point is closer to the left end of the current selection
adjust the left end of the selected range */
if (startIndex < proposedRange.location + proposedRange.length / 2)
{
startIndex = NSMaxRange (proposedRange);
proposedRange = NSMakeRange(startIndex,
NSMaxRange(proposedRange) - startIndex);
proposedRange = [self selectionRangeForProposedRange: proposedRange
granularity: granularity];
/* Prepare for shift-dragging. Anchor is at the right end. */
startIndex = NSMaxRange(proposedRange);
}
else
/* otherwise, adjust the right end of the selected range */
else
{
proposedRange = NSMakeRange(proposedRange.location,
startIndex - proposedRange.location);
proposedRange = [self selectionRangeForProposedRange: proposedRange
granularity: granularity];
/* Prepare for shift-dragging. Anchor is at the left end. */
startIndex = proposedRange.location;
}
}