Keep text selection after color code insertion

This commit is contained in:
1024jp 2015-12-09 03:20:11 +09:00
parent 3626be22a8
commit ccfd850e0d
2 changed files with 6 additions and 3 deletions

View File

@ -7,8 +7,9 @@ develop
### Improvements
- Tweak preferences layout.
- Add dot mark to installed syntax style list in preferences to represent the state if style is customized.
- Keep text selection after inserting color code from the color code panel.
- Tweak preferences layout.
### Fixes

View File

@ -180,11 +180,13 @@
if (![self colorCode]) { return; }
NSTextView *textView = [[[self documentWindowController] editor] focusedTextView];
NSRange selectedRange = [textView selectedRange];
if ([textView shouldChangeTextInRange:[textView selectedRange] replacementString:[self colorCode]]) {
[textView replaceCharactersInRange:[textView selectedRange] withString:[self colorCode]];
if ([textView shouldChangeTextInRange:selectedRange replacementString:[self colorCode]]) {
[textView replaceCharactersInRange:selectedRange withString:[self colorCode]];
[[textView undoManager] setActionName:NSLocalizedString(@"Insert Color Code", nil)];
[textView didChangeText];
[textView setSelectedRange:NSMakeRange(selectedRange.location, [[self colorCode] length])];
[textView scrollRangeToVisible:[textView selectedRange]];
}
}