mirror of
https://github.com/coteditor/CotEditor.git
synced 2024-09-11 11:25:57 +03:00
Improve line selecting with Shift key
This commit is contained in:
parent
936cf17a9e
commit
c022d6acf0
@ -7,6 +7,7 @@ develop
|
||||
|
||||
### Improvements
|
||||
|
||||
- Improve text selection by clicking line numbers view.
|
||||
- Tweak style of popup menus in toolbar.
|
||||
- Update Python syntax style:
|
||||
- Add `__copy__` and `__deepcopy__` to commands.
|
||||
|
@ -402,12 +402,31 @@ static const NSString *LineNumberFontName;
|
||||
}
|
||||
|
||||
// select lines
|
||||
NSInteger currentIndex = [textView characterIndexForPoint:point];
|
||||
NSInteger clickedIndex = timer ? [[timer userInfo] unsignedIntegerValue] : currentIndex;
|
||||
NSRange range = NSMakeRange(MIN(currentIndex, clickedIndex), ABS(currentIndex - clickedIndex));
|
||||
NSRange lineRange = [[textView string] lineRangeForRange:range];
|
||||
NSUInteger currentIndex = [textView characterIndexForPoint:point];
|
||||
NSUInteger clickedIndex = timer ? [[timer userInfo] unsignedIntegerValue] : currentIndex;
|
||||
NSRange currentLineRange = [[textView string] lineRangeForRange:NSMakeRange(currentIndex, 0)];
|
||||
NSRange clickedLineRange = [[textView string] lineRangeForRange:NSMakeRange(clickedIndex, 0)];
|
||||
NSRange range = NSUnionRange(currentLineRange, clickedLineRange);
|
||||
|
||||
[textView setSelectedRange:lineRange];
|
||||
// with Shift key
|
||||
if ([NSEvent modifierFlags] & NSShiftKeyMask) {
|
||||
NSRange selectedRange = [textView selectedRange];
|
||||
if (NSLocationInRange(currentIndex, selectedRange)) { // reduce
|
||||
BOOL inUpperSection = (currentIndex - selectedRange.location) < selectedRange.length / 2;
|
||||
if (inUpperSection) { // clicked upper half section of selected range
|
||||
range = NSMakeRange(currentIndex, NSMaxRange(selectedRange) - currentIndex);
|
||||
|
||||
} else {
|
||||
range = selectedRange;
|
||||
range.length -= NSMaxRange(selectedRange) - NSMaxRange(currentLineRange);
|
||||
}
|
||||
|
||||
} else { // expand
|
||||
range = NSUnionRange(range, selectedRange);
|
||||
}
|
||||
}
|
||||
|
||||
[textView setSelectedRange:range];
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user