mirror of
https://github.com/coteditor/CotEditor.git
synced 2024-09-11 11:25:57 +03:00
Fix incompatible char select
This commit is contained in:
parent
ff079e2962
commit
a15f20d8c2
@ -21,7 +21,8 @@ Change Log
|
||||
### Fixes
|
||||
|
||||
- Fix duplication check in key bindings editor.
|
||||
- Fix some missing localizations in simplified Chinese.
|
||||
- Fix an issue that incompatible character markup positions were wrong by CR/LF line endings.
|
||||
- Fix some missing localizations in simplified Chinese. (Thanks to Wei Wang!)
|
||||
|
||||
|
||||
|
||||
|
@ -1111,7 +1111,7 @@
|
||||
<binding destination="-2" name="contentObject" keyPath="documentInfo" id="8kq-c1-odm"/>
|
||||
</connections>
|
||||
</objectController>
|
||||
<arrayController automaticallyPreparesContent="YES" selectsInsertedObjects="NO" avoidsEmptySelection="NO" id="127" userLabel="Incompatible Chars Controller">
|
||||
<arrayController objectClassName="NSDictionary" automaticallyPreparesContent="YES" selectsInsertedObjects="NO" avoidsEmptySelection="NO" id="127" userLabel="Incompatible Chars Controller">
|
||||
<declaredKeys>
|
||||
<string>lineNumber</string>
|
||||
<string>incompatibleChar</string>
|
||||
|
@ -532,6 +532,7 @@ NSString *const CEIncompatibleConvertedCharKey = @"convertedChar";
|
||||
|
||||
// 削除/変換される文字をリストアップ
|
||||
NSString *yenMarkChar = [NSString stringWithCharacters:&kYenMark length:1];
|
||||
BOOL isInvalidYenEncoding = [CEUtils isInvalidYenEncoding:encoding];
|
||||
|
||||
for (NSUInteger i = 0; i < currentLength; i++) {
|
||||
unichar currentUnichar = [currentString characterAtIndex:i];
|
||||
@ -539,32 +540,30 @@ NSString *const CEIncompatibleConvertedCharKey = @"convertedChar";
|
||||
|
||||
if (currentUnichar == convertedUnichar) { continue; }
|
||||
|
||||
NSRange charRange = NSMakeRange(i, 1);
|
||||
NSString *currentChar = [currentString substringWithRange:charRange];
|
||||
NSString *convertedChar = [convertedString substringWithRange:charRange];
|
||||
|
||||
if ([CEUtils isInvalidYenEncoding:encoding] && [currentChar isEqualToString:yenMarkChar]) {
|
||||
currentChar = yenMarkChar;
|
||||
convertedChar = @"\\";
|
||||
if (isInvalidYenEncoding && currentUnichar == kYenMark) {
|
||||
convertedUnichar = '\\';
|
||||
}
|
||||
|
||||
NSUInteger curLine = 1;
|
||||
NSString *currentChar = [NSString stringWithCharacters:¤tUnichar length:1];
|
||||
NSString *convertedChar = [NSString stringWithCharacters:&convertedUnichar length:1];
|
||||
|
||||
NSUInteger lineNumber = 1;
|
||||
for (NSUInteger index = 0, lines = 0; index < currentLength; lines++) {
|
||||
if (index <= i) {
|
||||
curLine = lines + 1;
|
||||
lineNumber = lines + 1;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
index = NSMaxRange([currentString lineRangeForRange:NSMakeRange(index, 0)]);
|
||||
}
|
||||
|
||||
[incompatibleChars addObject:[@{CEIncompatibleLineNumberKey: @(curLine),
|
||||
CEIncompatibleRangeKey: [NSValue valueWithRange:charRange],
|
||||
CEIncompatibleCharKey: currentChar,
|
||||
CEIncompatibleConvertedCharKey: convertedChar} mutableCopy]];
|
||||
[incompatibleChars addObject:@{CEIncompatibleLineNumberKey: @(lineNumber),
|
||||
CEIncompatibleRangeKey: [NSValue valueWithRange:NSMakeRange(i, 1)],
|
||||
CEIncompatibleCharKey: currentChar,
|
||||
CEIncompatibleConvertedCharKey: convertedChar}];
|
||||
}
|
||||
|
||||
return incompatibleChars;
|
||||
return [incompatibleChars copy];
|
||||
}
|
||||
|
||||
|
||||
@ -889,9 +888,9 @@ NSString *const CEIncompatibleConvertedCharKey = @"convertedChar";
|
||||
}
|
||||
|
||||
NSTextView *textView = [[self editor] textView];
|
||||
[[[self windowController] window] makeKeyAndOrderFront:self]; // 対象ウィンドウをキーに
|
||||
[textView scrollRangeToVisible:[textView selectedRange]]; // 選択範囲が見えるようにスクロール
|
||||
[textView showFindIndicatorForRange:[textView selectedRange]]; // 検索結果表示エフェクトを追加
|
||||
[[[self windowController] window] makeKeyAndOrderFront:self]; // 対象ウィンドウをキーに
|
||||
}
|
||||
|
||||
|
||||
|
@ -291,15 +291,7 @@ static NSTimeInterval secondColoringDelay;
|
||||
- (NSRange)selectedRange
|
||||
// ------------------------------------------------------
|
||||
{
|
||||
if ([[[self textView] lineEndingString] length] > 1) {
|
||||
NSRange range = [[self textView] selectedRange];
|
||||
NSString *tmpLocStr = [[self string] substringWithRange:NSMakeRange(0, range.location)];
|
||||
NSString *locStr = [tmpLocStr stringByReplacingNewLineCharacersWith:[[self document] lineEnding]];
|
||||
NSString *lenStr = [self substringWithSelectionForSave];
|
||||
|
||||
return NSMakeRange([locStr length], [lenStr length]);
|
||||
}
|
||||
return [[self textView] selectedRange];
|
||||
return [self documentRangeFromRange:[[self textView] selectedRange]];
|
||||
}
|
||||
|
||||
|
||||
@ -308,15 +300,7 @@ static NSTimeInterval secondColoringDelay;
|
||||
- (void)setSelectedRange:(NSRange)charRange
|
||||
// ------------------------------------------------------
|
||||
{
|
||||
if ([[[self textView] lineEndingString] length] > 1) {
|
||||
NSString *tmpLocStr = [[[self document] stringForSave] substringWithRange:NSMakeRange(0, charRange.location)];
|
||||
NSString *locStr = [tmpLocStr stringByReplacingNewLineCharacersWith:CENewLineLF];
|
||||
NSString *tmpLenStr = [[[self document] stringForSave] substringWithRange:charRange];
|
||||
NSString *lenStr = [tmpLenStr stringByReplacingNewLineCharacersWith:CENewLineLF];
|
||||
[[self textView] setSelectedRange:NSMakeRange([locStr length], [lenStr length])];
|
||||
} else {
|
||||
[[self textView] setSelectedRange:charRange];
|
||||
}
|
||||
[[self textView] setSelectedRange:[self rangeFromDocumentRange:charRange]];
|
||||
}
|
||||
|
||||
|
||||
@ -352,7 +336,7 @@ static NSTimeInterval secondColoringDelay;
|
||||
|
||||
for (NSLayoutManager *manager in layoutManagers) {
|
||||
[manager addTemporaryAttribute:NSBackgroundColorAttributeName value:color
|
||||
forCharacterRange:range];
|
||||
forCharacterRange:[self rangeFromDocumentRange:range]];
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -903,6 +887,43 @@ static NSTimeInterval secondColoringDelay;
|
||||
}
|
||||
|
||||
|
||||
// ------------------------------------------------------
|
||||
/// sanitized range for text view
|
||||
- (NSRange)rangeFromDocumentRange:(NSRange)range
|
||||
// ------------------------------------------------------
|
||||
{
|
||||
if ([[[self textView] lineEndingString] length] == 1) {
|
||||
return range;
|
||||
}
|
||||
|
||||
// sanitize for CR/LF
|
||||
NSString *tmpLocStr = [[[self document] stringForSave] substringWithRange:NSMakeRange(0, range.location)];
|
||||
NSString *locStr = [tmpLocStr stringByReplacingNewLineCharacersWith:CENewLineLF];
|
||||
NSString *tmpLenStr = [[[self document] stringForSave] substringWithRange:range];
|
||||
NSString *lenStr = [tmpLenStr stringByReplacingNewLineCharacersWith:CENewLineLF];
|
||||
|
||||
return NSMakeRange([locStr length], [lenStr length]);
|
||||
}
|
||||
|
||||
|
||||
// ------------------------------------------------------
|
||||
/// sanitized range for document
|
||||
- (NSRange)documentRangeFromRange:(NSRange)range
|
||||
// ------------------------------------------------------
|
||||
{
|
||||
if ([[[self textView] lineEndingString] length] == 1) {
|
||||
return range;
|
||||
}
|
||||
|
||||
// sanitize for CR/LF
|
||||
NSString *tmpLocStr = [[self string] substringWithRange:NSMakeRange(0, range.location)];
|
||||
NSString *locStr = [tmpLocStr stringByReplacingNewLineCharacersWith:[[self document] lineEnding]];
|
||||
NSString *lenStr = [self substringWithSelectionForSave];
|
||||
|
||||
return NSMakeRange([locStr length], [lenStr length]);
|
||||
}
|
||||
|
||||
|
||||
// ------------------------------------------------------
|
||||
/// カラーリング実行
|
||||
- (void)doColoringNow
|
||||
|
@ -715,16 +715,19 @@ static NSTimeInterval incompatibleCharInterval;
|
||||
- (IBAction)selectIncompatibleRange:(id)sender
|
||||
// ------------------------------------------------------
|
||||
{
|
||||
if ([[[self incompatibleCharsController] selectedObjects] count] == 0) { return; }
|
||||
NSArray *selectedIncompatibles = [[self incompatibleCharsController] selectedObjects];
|
||||
|
||||
if ([selectedIncompatibles count] == 0) { return; }
|
||||
|
||||
NSRange range = [[[self incompatibleCharsController] selectedObjects][0][CEIncompatibleRangeKey] rangeValue];
|
||||
NSRange range = [selectedIncompatibles[0][CEIncompatibleRangeKey] rangeValue];
|
||||
NSTextView *textView = [[self editor] textView];
|
||||
|
||||
[[self editor] setSelectedRange:range];
|
||||
[[self window] makeFirstResponder:[[self editor] textView]];
|
||||
[[[self editor] textView] scrollRangeToVisible:range];
|
||||
[[self window] makeFirstResponder:textView];
|
||||
|
||||
// 検索結果表示エフェクトを追加
|
||||
[[[self editor] textView] showFindIndicatorForRange:range];
|
||||
// 検索結果表示エフェクトを追加 (改行コードが CR/LF のときにずれるので range は使えない)
|
||||
[textView scrollRangeToVisible:[textView selectedRange]];
|
||||
[textView showFindIndicatorForRange:[textView selectedRange]];
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user