Change character inspector behavior

This commit is contained in:
1024jp 2016-01-05 20:40:46 +09:00
parent ccb4244a13
commit 2cdbd65916
2 changed files with 20 additions and 1 deletions

View File

@ -5,6 +5,11 @@ Change Log
develop
--------------------------
### Improvements
- Close character inspector when text selection was changed.
### Fixes
- Fix an issue where window title bar was dyed in the editor's background color on El Capitan.

View File

@ -91,6 +91,7 @@
return self;
}
// ------------------------------------------------------
/// nib name
- (nullable NSString *)nibName
@ -114,7 +115,6 @@
}
// ------------------------------------------------------
/// show popover
- (void)showPopoverRelativeToRect:(NSRect)positioningRect ofView:(nonnull NSView *)parentView
@ -126,6 +126,20 @@
[popover setBehavior:NSPopoverBehaviorSemitransient];
[popover showRelativeToRect:positioningRect ofView:parentView preferredEdge:NSMinYEdge];
[[parentView window] makeFirstResponder:parentView];
// auto-close popover if selection is changed.
if ([parentView isKindOfClass:[NSTextView class]]) {
__block __weak id observer = [[NSNotificationCenter defaultCenter] addObserverForName:NSTextViewDidChangeSelectionNotification
object:parentView
queue:[NSOperationQueue mainQueue]
usingBlock:^(NSNotification *note)
{
if (![popover isDetached]) {
[popover performClose:nil];
}
[[NSNotificationCenter defaultCenter] removeObserver:observer];
}];
}
}