Fix text selection after line moving

This commit is contained in:
1024jp 2016-01-10 16:49:59 +09:00
parent e111b4a8ee
commit 18b03804ae
2 changed files with 12 additions and 13 deletions

View File

@ -16,7 +16,8 @@ develop
### Fixes
- Fix an issue where window title bar was dyed in the editor's background color on El Capitan.
- Fix an issue where window title bar was dyed in the editor's background color on El Capitan.
- Fix an issue where text selection after move multiple lines was broken.
- Fix an issue where `$` or `^` anchors in the regular expression via AppleScript didn't work with document that has non-LF line endings.
- Fix an issue where syntax highlighting indicator became occasionally unclosable under the specific condition on document opening.

View File

@ -53,7 +53,7 @@
// register redo for text selection
[[[self undoManager] prepareWithInvocationTarget:self] setSelectedRangesWithUndo:[self selectedRanges]];
NSMutableArray<NSValue *> *newSelectedRanges = [NSMutableArray arrayWithCapacity:[selectedRanges count]];
NSMutableArray<NSValue *> *newSelectedRanges = [NSMutableArray arrayWithCapacity:[lineRanges count]];
// swap lines
[textStorage beginEditing];
@ -80,12 +80,11 @@
// move selected ranges in the line to move
for (NSValue *selectedRangeValue in selectedRanges) {
NSRange selectedRange = [selectedRangeValue rangeValue];
NSRange intersectionRange = NSIntersectionRange(selectedRange, editRange);
if ((selectedRange.location > lineRange.location) ||
(selectedRange.location <= NSMaxRange(lineRange)))
{
selectedRange.location -= upperLineRange.length;
[newSelectedRanges addObject:[NSValue valueWithRange:selectedRange]];
if (intersectionRange.length > 0) {
intersectionRange.location -= upperLineRange.length;
[newSelectedRanges addObject:[NSValue valueWithRange:intersectionRange]];
}
}
}
@ -119,7 +118,7 @@
// register redo for text selection
[[[self undoManager] prepareWithInvocationTarget:self] setSelectedRangesWithUndo:[self selectedRanges]];
NSMutableArray<NSValue *> *newSelectedRanges = [NSMutableArray arrayWithCapacity:[selectedRanges count]];
NSMutableArray<NSValue *> *newSelectedRanges = [NSMutableArray arrayWithCapacity:[lineRanges count]];
// swap lines
[textStorage beginEditing];
@ -147,12 +146,11 @@
// move selected ranges in the line to move
for (NSValue *selectedRangeValue in selectedRanges) {
NSRange selectedRange = [selectedRangeValue rangeValue];
NSRange intersectionRange = NSIntersectionRange(selectedRange, editRange);
if ((selectedRange.location > lineRange.location) ||
(selectedRange.location <= NSMaxRange(lineRange)))
{
selectedRange.location += lowerLineRange.length;
[newSelectedRanges addObject:[NSValue valueWithRange:selectedRange]];
if (intersectionRange.length > 0) {
intersectionRange.location += lowerLineRange.length;
[newSelectedRanges addObject:[NSValue valueWithRange:intersectionRange]];
}
}
}