diff --git a/AppKit/CPTextView/CPTextView.j b/AppKit/CPTextView/CPTextView.j index 91ea5ebf1..1985411aa 100644 --- a/AppKit/CPTextView/CPTextView.j +++ b/AppKit/CPTextView/CPTextView.j @@ -1673,6 +1673,8 @@ Sets the selection to a range of characters in response to user action. - (void)insertLineBreak:(id)sender { [self insertText:@"\n"]; + // make sure that the return key is "swallowed" and the default button not triggered as is the case in cocoa + [[self window] _temporarilyDisableKeyEquivalentForDefaultButton]; } - (void)insertTab:(id)sender diff --git a/AppKit/CPWindow/CPWindow.j b/AppKit/CPWindow/CPWindow.j index dfedcf4cf..90917f81e 100644 --- a/AppKit/CPWindow/CPWindow.j +++ b/AppKit/CPWindow/CPWindow.j @@ -238,6 +238,7 @@ var CPWindowActionMessageKeys = [ CPButton _defaultButton; BOOL _defaultButtonEnabled; + BOOL _defaultButtonDisabledTemporarily; BOOL _autorecalculatesKeyViewLoop; BOOL _keyViewLoopIsDirty; @@ -402,6 +403,7 @@ CPTexturedBackgroundWindowMask _autorecalculatesKeyViewLoop = NO; _defaultButtonEnabled = YES; + _defaultButtonDisabledTemporarily = NO; _keyViewLoopIsDirty = NO; _hasBecomeKeyWindow = NO; @@ -1930,8 +1932,7 @@ CPTexturedBackgroundWindowMask [[self firstResponder] keyDown:anEvent]; // Trigger the default button if needed - // FIXME: Is this only applicable in a sheet? See isse: #722. - if (![self disableKeyEquivalentForDefaultButton]) + if (_defaultButtonEnabled && !_defaultButtonDisabledTemporarily) { var defaultButton = [self defaultButton], keyEquivalent = [defaultButton keyEquivalent], @@ -1941,6 +1942,8 @@ CPTexturedBackgroundWindowMask [[self defaultButton] performClick:self]; } + _defaultButtonDisabledTemporarily = NO; + return; case CPScrollWheel: @@ -3439,6 +3442,11 @@ CPTexturedBackgroundWindowMask _defaultButtonEnabled = NO; } +- (void)_temporarilyDisableKeyEquivalentForDefaultButton +{ + _defaultButtonDisabledTemporarily = YES; +} + /*! Removes the key equivalent for the default button. Note: this method is deprecated. Use disableKeyEquivalentForDefaultButton instead. diff --git a/Tests/Manual/CPTextView/AppController.j b/Tests/Manual/CPTextView/AppController.j index 963916c9a..3258f11c3 100755 --- a/Tests/Manual/CPTextView/AppController.j +++ b/Tests/Manual/CPTextView/AppController.j @@ -51,23 +51,25 @@ [contentView setBackgroundColor:[CPColor colorWithWhite:0.95 alpha:1.0]]; - var mybutton=[[CPButton alloc] initWithFrame:CGRectMake(0, 0,50, 25)]; - [mybutton setTitle:"Open sheet"] - [mybutton setTarget:self] - [mybutton setAction:@selector(openSheet:)] - [contentView addSubview:mybutton] + var mybutton=[[CPButton alloc] initWithFrame:CGRectMake(0, 0, 250, 25)]; + [mybutton setTitle:"Open sheet (must not be triggered by return)"] + [mybutton setTarget:self]; + [mybutton setAction:@selector(openSheet:)]; + [mybutton setKeyEquivalent:@"\r"]; + + [contentView addSubview:mybutton]; - _textView = [[CPTextView alloc] initWithFrame:CGRectMake(0,0,500,500)]; + _textView = [[CPTextView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)]; [_textView setRichText:YES]; - _textView2 = [[CPTextView alloc] initWithFrame:CGRectMake(0,0,500,500)]; + _textView2 = [[CPTextView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)]; _textView2._isRichText = NO; [_textView setBackgroundColor:[CPColor whiteColor]]; [_textView2 setBackgroundColor:[CPColor whiteColor]]; - var scrollView = [[CPScrollView alloc] initWithFrame:CGRectMake(20, 20,520,510)]; - var scrollView2 = [[CPScrollView alloc] initWithFrame:CGRectMake(560, 20,520,510)]; + var scrollView = [[CPScrollView alloc] initWithFrame:CGRectMake(20, 70, 520, 510)]; + var scrollView2 = [[CPScrollView alloc] initWithFrame:CGRectMake(560, 70, 520, 510)]; // [scrollView setAutohidesScrollers:YES]; [scrollView setDocumentView:_textView]; [scrollView2 setDocumentView:_textView2];