Permalink
Browse files

Merge pull request #1679 from mrcarlberg/scroll_before_focus_text_field

Make sure the text field is visible before focus
  • Loading branch information...
aparajita committed Feb 19, 2013
2 parents 3cfa81b + 82337b8 commit ceeaab70fc915af92d5405fd7a58a3591b5a1e79
Showing with 15 additions and 7 deletions.
  1. +3 −0 AppKit/CPTextField.j
  2. +12 −7 AppKit/CPTokenField.j
View
@@ -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];
View
@@ -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];

0 comments on commit ceeaab7

Please sign in to comment.