Merge pull request #1679 from mrcarlberg/scroll_before_focus_text_field

Make sure the text field is visible before focus
This commit is contained in:
aparajita committed 2013-02-19 06:14:42 -08:00
commit ceeaab70fc
2 files changed
+15 -7

No files matched your search

+3
View File
@@ -543,6 +543,9 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
*/
- (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 _updatePlaceholderState];
+12 -7
View File
@@ -330,6 +330,8 @@ CPTokenFieldDeleteButtonType = 1;
// As long as we are the first responder we need to monitor the key status of our window.
[self _setObserveWindowKeyNotifications:YES];
[self scrollRectToVisible:[self bounds]];
if ([[self window] isKeyWindow])
[self _becomeFirstKeyResponder];
@@ -371,16 +373,19 @@ CPTokenFieldDeleteButtonType = 1;
element.style.width = CGRectGetWidth(contentRect) + "px";
element.style.height = [font defaultLineHeightForFont] + "px";
[_tokenScrollView documentView]._DOMElement.appendChild(element);
window.setTimeout(function()
{
element.focus();
CPTokenFieldInputOwner = self;
}, 0.0);
[_tokenScrollView documentView]._DOMElement.appendChild(element);
//post CPControlTextDidBeginEditingNotification
[self textDidBeginEditing:[CPNotification notificationWithName:CPControlTextDidBeginEditingNotification object:self userInfo:nil]];
//post CPControlTextDidBeginEditingNotification
[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];