Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure the text field is visible before focus #1679

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions AppKit/CPTextField.j
Expand Up @@ -513,6 +513,9 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
*/ */
- (void)_becomeFirstKeyResponder - (void)_becomeFirstKeyResponder
{ {
// Make sure the text field is visible so the browser will not scroll without the NSScrollView knowing about it.
[self scrollRectToVisible:[self bounds]];

[self setThemeState:CPThemeStateEditing]; [self setThemeState:CPThemeStateEditing];


[self _updatePlaceholderState]; [self _updatePlaceholderState];
Expand Down
19 changes: 12 additions & 7 deletions AppKit/CPTokenField.j
Expand Up @@ -320,6 +320,8 @@ var CPScrollDestinationNone = 0,
// As long as we are the first responder we need to monitor the key status of our window. // As long as we are the first responder we need to monitor the key status of our window.
[self _setObserveWindowKeyNotifications:YES]; [self _setObserveWindowKeyNotifications:YES];


[self scrollRectToVisible:[self bounds]];

if ([[self window] isKeyWindow]) if ([[self window] isKeyWindow])
[self _becomeFirstKeyResponder]; [self _becomeFirstKeyResponder];


Expand Down Expand Up @@ -361,16 +363,19 @@ var CPScrollDestinationNone = 0,
element.style.width = CGRectGetWidth(contentRect) + "px"; element.style.width = CGRectGetWidth(contentRect) + "px";
element.style.height = [font defaultLineHeightForFont] + "px"; element.style.height = [font defaultLineHeightForFont] + "px";


[_tokenScrollView documentView]._DOMElement.appendChild(element);

window.setTimeout(function() window.setTimeout(function()
{ {
element.focus(); [_tokenScrollView documentView]._DOMElement.appendChild(element);
CPTokenFieldInputOwner = self;
}, 0.0);


//post CPControlTextDidBeginEditingNotification //post CPControlTextDidBeginEditingNotification
[self textDidBeginEditing:[CPNotification notificationWithName:CPControlTextDidBeginEditingNotification object:self userInfo:nil]]; [self textDidBeginEditing:[CPNotification notificationWithName:CPControlTextDidBeginEditingNotification object:self userInfo:nil]];

window.setTimeout(function()
{
element.focus();
CPTokenFieldInputOwner = self;
}, 0.0);
}, 0.0);


[[[self window] platformWindow] _propagateCurrentDOMEvent:YES]; [[[self window] platformWindow] _propagateCurrentDOMEvent:YES];


Expand Down