diff options
author | Damiano Galassi <[email protected]> | 2017-12-07 11:34:12 +0100 |
---|---|---|
committer | Damiano Galassi <[email protected]> | 2017-12-07 11:34:12 +0100 |
commit | 41687a491796b1affe7f8243e66851da1ceacff8 (patch) | |
tree | 7431dfa8525fb752de2bbd30e012fe4962ef4ab4 /macosx | |
parent | f440027a2fc3e2c247c71ccf4bd4013ff30f89a1 (diff) |
MacGui: preserve the textfield selection/insertion point when calling HB_endEditing.
Diffstat (limited to 'macosx')
-rw-r--r-- | macosx/NSWindow+HBAdditions.m | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/macosx/NSWindow+HBAdditions.m b/macosx/NSWindow+HBAdditions.m index fbf65f116..ddb9a7899 100644 --- a/macosx/NSWindow+HBAdditions.m +++ b/macosx/NSWindow+HBAdditions.m @@ -76,13 +76,19 @@ - (BOOL)HB_endEditing; { BOOL success; + NSRange selectedRange = NSMakeRange(0, 0); id responder = self.firstResponder; // If we're dealing with the field editor, the real first responder is // its delegate. - if ((responder != nil) && [responder isKindOfClass:[NSTextView class]] && [(NSTextView*)responder isFieldEditor]) + if ((responder != nil) && [responder isKindOfClass:[NSTextView class]] && [(NSTextView *)responder isFieldEditor]) { responder = ([[responder delegate] isKindOfClass:[NSResponder class]]) ? [responder delegate] : nil; + if ([responder isKindOfClass:[NSTextField class]]) + { + NSTextField *textField = (NSTextField *)responder; + selectedRange = textField.currentEditor.selectedRange; + } } success = [self makeFirstResponder:nil]; @@ -91,6 +97,11 @@ if (success && responder != nil) { [self makeFirstResponder:responder]; + if ([responder isKindOfClass:[NSTextField class]]) + { + NSTextField *textField = (NSTextField *)responder; + textField.currentEditor.selectedRange = selectedRange; + } } return success; |