mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-10-01 06:37:41 +00:00
Fixed: return key was not swallowed by textview but triggered the default button. (#2598)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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];
|
||||
|
||||
Reference in New Issue
Block a user