mirror of
https://github.com/coteditor/CotEditor.git
synced 2024-09-11 11:25:57 +03:00
Add "Duplicate Line" action (close #471)
This commit is contained in:
parent
59f1966d42
commit
2661cad627
@ -5,6 +5,15 @@ Change Log
|
||||
develop
|
||||
--------------------------
|
||||
|
||||
### New Features
|
||||
|
||||
- Add “Duplicate” action to Text > Lines menu.
|
||||
|
||||
|
||||
|
||||
2.3.1 (84)
|
||||
--------------------------
|
||||
|
||||
### Additions/Changes
|
||||
|
||||
- Update Python syntax style:
|
||||
|
@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="9059" systemVersion="15C27e" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
|
||||
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="9059" systemVersion="15C31f" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
|
||||
<dependencies>
|
||||
<deployment identifier="macosx"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="9059"/>
|
||||
@ -694,6 +694,11 @@
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem isSeparatorItem="YES" id="Dpo-h5-IyY"/>
|
||||
<menuItem title="Duplicate Line" keyEquivalent="D" id="m48-5E-yia">
|
||||
<connections>
|
||||
<action selector="duplicateLine:" target="-1" id="Ufn-Zf-Ykf"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Delete Line" id="sFn-3j-pY5">
|
||||
<string key="keyEquivalent" base64-UTF8="YES">
|
||||
CA
|
||||
|
@ -6,6 +6,8 @@
|
||||
<string>selectLines:</string>
|
||||
<key>$@C</key>
|
||||
<string>copyWithStyle:</string>
|
||||
<key>$@D</key>
|
||||
<string>duplicateLine:</string>
|
||||
<key>$@E</key>
|
||||
<string>useSelectionForReplace:</string>
|
||||
<key>$@F</key>
|
||||
|
@ -130,6 +130,7 @@
|
||||
- (IBAction)sortLinesAscending:(nullable id)sender;
|
||||
- (IBAction)reverseLines:(nullable id)sender;
|
||||
- (IBAction)deleteDuplicateLine:(nullable id)sender;
|
||||
- (IBAction)duplicateLine:(nullable id)sender;
|
||||
- (IBAction)deleteLine:(nullable id)sender;
|
||||
|
||||
@end
|
||||
|
@ -2710,6 +2710,47 @@ static NSPoint kTextContainerOrigin;
|
||||
|
||||
|
||||
|
||||
// ------------------------------------------------------
|
||||
/// duplicate selected lines below
|
||||
- (IBAction)duplicateLine:(nullable id)sender
|
||||
// ------------------------------------------------------
|
||||
{
|
||||
NSMutableArray<NSValue *> *replacementRanges = [NSMutableArray array];
|
||||
NSMutableArray<NSString *> *replacementStrings = [NSMutableArray array];
|
||||
|
||||
// get lines to process
|
||||
for (NSValue *rangeValue in [self selectedRanges]) {
|
||||
NSRange range = [rangeValue rangeValue];
|
||||
NSRange lineRange = [[self string] lineRangeForRange:range];
|
||||
NSRange replacementRange = NSMakeRange(lineRange.location, 0);
|
||||
NSString *lineString = [[self string] substringWithRange:lineRange];
|
||||
|
||||
// add line break if it's the last line
|
||||
if (![lineString hasSuffix:@"\n"]) {
|
||||
lineString = [lineString stringByAppendingString:@"\n"];
|
||||
}
|
||||
|
||||
[replacementRanges addObject:[NSValue valueWithRange:replacementRange]];
|
||||
[replacementStrings addObject:lineString];
|
||||
}
|
||||
|
||||
if (![self shouldChangeTextInRanges:replacementRanges replacementStrings:replacementStrings]) { return; }
|
||||
|
||||
// duplicate lines
|
||||
NSTextStorage *textStorage = [self textStorage];
|
||||
[replacementStrings enumerateObjectsWithOptions:NSEnumerationReverse
|
||||
usingBlock:^(NSString *_Nonnull replacementString, NSUInteger idx, BOOL * _Nonnull stop)
|
||||
{
|
||||
NSRange replacementRange = [replacementRanges[idx] rangeValue];
|
||||
[textStorage replaceCharactersInRange:replacementRange withString:replacementString];
|
||||
}];
|
||||
[self didChangeText];
|
||||
|
||||
[[self undoManager] setActionName:NSLocalizedString(@"Duplicate Line", @"action name")];
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ------------------------------------------------------
|
||||
/// remove selected lines
|
||||
- (IBAction)deleteLine:(nullable id)sender
|
||||
|
@ -186,6 +186,7 @@
|
||||
"Sort Lines" = "Zeilen sortieren";
|
||||
"Reverse Lines" = "Zeilen umdrehen";
|
||||
"Remove Duplicate Lines" = "Doppelte Zeilen löschen";
|
||||
"Duplicate Line" = "Zeile duplizieren";
|
||||
"Delete Line" = "Zeile löschen";
|
||||
|
||||
// Menu items
|
||||
|
@ -331,6 +331,8 @@
|
||||
"xhf-NR-D2Q.title" = "Umdrehen";
|
||||
/* Class = "NSMenuItem"; title = "Delete Duplicates"; ObjectID = "bjv-m0-tZq"; */
|
||||
"bjv-m0-tZq.title" = "Doppelte löschen";
|
||||
/* Class = "NSMenuItem"; title = "Duplicate Line"; ObjectID = "m48-5E-yia"; */
|
||||
"m48-5E-yia.title" = "Zeile duplizieren";
|
||||
/* Class = "NSMenuItem"; title = "Delete Line"; ObjectID = "sFn-3j-pY5"; */
|
||||
"sFn-3j-pY5.title" = "Zeile löschen";
|
||||
|
||||
|
@ -188,6 +188,7 @@
|
||||
"Sort Lines" = "行をソート";
|
||||
"Reverse Lines" = "行を反転";
|
||||
"Remove Duplicate Lines" = "重複行を削除";
|
||||
"Duplicate Line" = "行を複製";
|
||||
"Delete Line" = "行を削除";
|
||||
|
||||
// Menu items
|
||||
|
@ -331,6 +331,8 @@
|
||||
"xhf-NR-D2Q.title" = "反転";
|
||||
/* Class = "NSMenuItem"; title = "Delete Duplicates"; ObjectID = "bjv-m0-tZq"; */
|
||||
"bjv-m0-tZq.title" = "重複を削除";
|
||||
/* Class = "NSMenuItem"; title = "Duplicate Line"; ObjectID = "m48-5E-yia"; */
|
||||
"m48-5E-yia.title" = "行を複製";
|
||||
/* Class = "NSMenuItem"; title = "Delete Line"; ObjectID = "sFn-3j-pY5"; */
|
||||
"sFn-3j-pY5.title" = "行を削除";
|
||||
|
||||
|
@ -185,6 +185,7 @@
|
||||
"Sort Lines" = "排序行";
|
||||
"Reverse Lines" = "逆序行";
|
||||
"Remove Duplicate Lines" = "移除重复行";
|
||||
"Duplicate Line" = "复制行";
|
||||
"Delete Line" = "删除行";
|
||||
|
||||
// Menu items
|
||||
|
@ -332,6 +332,8 @@
|
||||
"xhf-NR-D2Q.title" = "逆向排序";
|
||||
/* Class = "NSMenuItem"; title = "Delete Duplicates"; ObjectID = "bjv-m0-tZq"; */
|
||||
"bjv-m0-tZq.title" = "删除重复";
|
||||
/* Class = "NSMenuItem"; title = "Duplicate Line"; ObjectID = "m48-5E-yia"; */
|
||||
"m48-5E-yia.title" = "复制行";
|
||||
/* Class = "NSMenuItem"; title = "Delete Line"; ObjectID = "sFn-3j-pY5"; */
|
||||
"sFn-3j-pY5.title" = "删除行";
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user