mirror of
https://github.com/coteditor/CotEditor.git
synced 2024-09-11 11:25:57 +03:00
Improve window restoration of text view
This commit is contained in:
parent
f9d2bd7f74
commit
2596744213
@ -21,7 +21,9 @@ develop
|
||||
- Better file encoding handling on revert action.
|
||||
- Set access-group `com.coteditor.CotEditor.edit` to CotEditor's script definition.
|
||||
- Change behavior to save `com.apple.TextEncoding` xattr on saving if the file had no content.
|
||||
- Improve to restore also the last syntax style mode of unsaved documents.
|
||||
- Improve window restoration:
|
||||
- To restore also the last scroll position and cursor position.
|
||||
- To restore also the last syntax style mode of unsaved documents.
|
||||
- Optimize saving process.
|
||||
|
||||
|
||||
@ -134,7 +136,7 @@ develop
|
||||
- Fix an issue where application could hang up on text editing.
|
||||
- Improve general stability.
|
||||
|
||||
|
||||
a
|
||||
|
||||
2.1.0
|
||||
--------------------------
|
||||
@ -228,7 +230,7 @@ develop
|
||||
|
||||
|
||||
### Additions/Changes
|
||||
|
||||
a
|
||||
- Drop support for __OS X Lion.__
|
||||
- Migrate document drawer to sidebar style.
|
||||
- Add “show document inspector” option to preferences.
|
||||
|
@ -48,6 +48,9 @@
|
||||
// constant
|
||||
const NSInteger kNoMenuItem = -1;
|
||||
|
||||
NSString *const CESelectedRangesKey = @"selectedRange";
|
||||
NSString *const CEVisibleRectKey = @"visibleRect";
|
||||
|
||||
|
||||
@interface CETextView ()
|
||||
|
||||
@ -98,6 +101,9 @@ static NSPoint kTextContainerOrigin;
|
||||
{
|
||||
self = [super initWithFrame:frameRect textContainer:aTextContainer];
|
||||
if (self) {
|
||||
// set class identifier for window restoration
|
||||
[self setIdentifier:@"coreTextView"];
|
||||
|
||||
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
||||
|
||||
// This method is partly based on Smultron's SMLTextView by Peter Borg. (2006-09-09)
|
||||
@ -181,6 +187,40 @@ static NSPoint kTextContainerOrigin;
|
||||
}
|
||||
|
||||
|
||||
// ------------------------------------------------------
|
||||
/// store UI state for the window restoration
|
||||
- (void)encodeRestorableStateWithCoder:(NSCoder *)coder
|
||||
// ------------------------------------------------------
|
||||
{
|
||||
[super encodeRestorableStateWithCoder:coder];
|
||||
|
||||
[coder encodeObject:[self selectedRanges] forKey:CESelectedRangesKey];
|
||||
[coder encodeRect:[self visibleRect]forKey:CEVisibleRectKey];
|
||||
}
|
||||
|
||||
|
||||
// ------------------------------------------------------
|
||||
/// restore UI state on the window restoration
|
||||
- (void)restoreStateWithCoder:(NSCoder *)coder
|
||||
// ------------------------------------------------------
|
||||
{
|
||||
[super restoreStateWithCoder:coder];
|
||||
|
||||
if ([coder containsValueForKey:CEVisibleRectKey]) {
|
||||
NSRect visibleRect = [coder decodeRectForKey:CEVisibleRectKey];
|
||||
NSArray *selectedRanges = [coder decodeObjectForKey:CESelectedRangesKey];
|
||||
|
||||
[self setSelectedRanges:selectedRanges];
|
||||
|
||||
// perform scroll
|
||||
__unsafe_unretained typeof(self) weakSelf = self; // NSTextView cannnot be weak
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[weakSelf scrollRectToVisible:visibleRect];
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ------------------------------------------------------
|
||||
/// first responder になれるかを返す
|
||||
- (BOOL)becomeFirstResponder
|
||||
|
Loading…
Reference in New Issue
Block a user