diff --git a/CHANGELOG.md b/CHANGELOG.md index d7a1f0a89..68acadf06 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/CotEditor/Sources/CETextView+LineProcessing.m b/CotEditor/Sources/CETextView+LineProcessing.m index 0bb73d6fc..aaff54e37 100644 --- a/CotEditor/Sources/CETextView+LineProcessing.m +++ b/CotEditor/Sources/CETextView+LineProcessing.m @@ -53,7 +53,7 @@ // register redo for text selection [[[self undoManager] prepareWithInvocationTarget:self] setSelectedRangesWithUndo:[self selectedRanges]]; - NSMutableArray *newSelectedRanges = [NSMutableArray arrayWithCapacity:[selectedRanges count]]; + NSMutableArray *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 *newSelectedRanges = [NSMutableArray arrayWithCapacity:[selectedRanges count]]; + NSMutableArray *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]]; } } }