Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Make sure the text field is visible before focus #1679

Merged
merged 3 commits into from

6 participants

Martin Carlberg CappBot Alexander Ljungberg Francisco Ryan Tolmasky I Andrew Hankinson Aparajita Fishman
Martin Carlberg
Collaborator

so the browser will not scroll without the NSScrollView knowing about it.
Issue #1675 and maybe a little of issue #1301.
This fix will not work without pull
request #1678 - Fixed scrollRectToVisible in CPView.

The problem can be tested here (from issue #1675)

The same application with the fix and pull request #1678 can be tested here

Martin Carlberg mrcarlberg Make sure the text field is visible before focus so the browser
will not scroll without the NSScrollView knowing about it
Issue #1675 and maybe a little of issue #1301
This fix will not work without pull
request #1678 - Fixed scrollRectToVisible in CPView
182f4c3
CappBot
Collaborator

Milestone: Someday. Label: #new. What's next? A reviewer should examine this issue.

Alexander Ljungberg
Owner

Shouldn't it, in theory, be possible to focus a text field that's not on screen? It's certainly possible in Cocoa, and it's up to the developer to add any automatic scrolling if they want it. (To test this in Cocoa, create a scroll view with two text fields and scroll until you can only see one of them. Then select it, tab to the other one and start typing. Your scroll position doesn't change, but if you later scroll the textfield into view the result of your typing is visible.)

Perhaps what we need is to figure out how to prevent the browser from messing with our scroll position in the first place.

Francisco Ryan Tolmasky I
Collaborator

It should, but if I recall correctly it isn't possible when dealing with scrolling divs. We do it all the time though by placing textfields at negative world coordinates, but if the browser can scroll to the textfield, it will. I think mrcarlberg's approach may be the best one here.

Martin Carlberg
Collaborator

True, we can't take control of scrolling divs. My approach may not be what we want, but it will at least work. Today it is broken as you can see in the above example.

Alexander Ljungberg
Owner
CappBot
Collaborator

Milestone: 0.9.6. Labels: #accepted, AppKit, bug. What's next? A reviewer should examine this issue.

CappBot
Collaborator

Milestone: 0.9.7. Labels: #accepted, AppKit, bug. What's next? A reviewer should examine this issue.

Andrew Hankinson

I can't get the fix pages to load, but I can verify that the code merges cleanly with master, and with #1678 applied builds and tests fine.

+#ready-to-commit

CappBot
Collaborator

Milestone: 0.9.7. Labels: #accepted, #ready-to-commit, AppKit, bug. What's next? The changes for this issue are ready to be committed by a member of the core team.

Aparajita Fishman
Owner

@aljungberg If you are good with this, please merge it.

Andrew Hankinson

Also possibly related to #1674.

Aparajita Fishman aparajita merged commit ceeaab7 into from
Aparajita Fishman
Owner

It looks okay, let's see what happens

#fixed

CappBot
Collaborator

Milestone: 0.9.7. Labels: #fixed, AppKit, bug. What's next? This issue is considered successfully resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 28, 2012
  1. Martin Carlberg

    Make sure the text field is visible before focus so the browser

    mrcarlberg authored
    will not scroll without the NSScrollView knowing about it
    Issue #1675 and maybe a little of issue #1301
    This fix will not work without pull
    request #1678 - Fixed scrollRectToVisible in CPView
Commits on Oct 27, 2012
  1. Martin Carlberg
Commits on Nov 30, 2012
  1. Martin Carlberg

    Merge branch 'master' into scroll_before_focus_text_field

    mrcarlberg authored
    Conflicts:
    	AppKit/CPTokenField.j
This page is out of date. Refresh to see the latest.
Showing with 15 additions and 7 deletions.
  1. +3 −0  AppKit/CPTextField.j
  2. +12 −7 AppKit/CPTokenField.j
3  AppKit/CPTextField.j
View
@@ -513,6 +513,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];
19 AppKit/CPTokenField.j
View
@@ -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.
[self _setObserveWindowKeyNotifications:YES];
+ [self scrollRectToVisible:[self bounds]];
+
if ([[self window] isKeyWindow])
[self _becomeFirstKeyResponder];
@@ -361,16 +363,19 @@ var CPScrollDestinationNone = 0,
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];
Something went wrong with that request. Please try again.