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

Auto-height fix for text area which is contained in a scroll container #1933

Merged
merged 1 commit into from
Dec 22, 2015

Conversation

felixhayashi
Copy link
Contributor

Hi @Jermolene

Finally found the time to implement this (see #1575). Your suggested way for fixing was the way to go.

Description

Allows text areas to be auto-height while being wrapped in an
element that has scrollbars. The wrapper element with the
scroll bar does not need to be a direct parent of the text area.

Demo

For a demo of the new behaviour see:
http://wkpr.de/hosting/tmp/tw5/scrolling/new.html

The old (bad) behaviour can be viewed here:
http://wkpr.de/hosting/tmp/tw5/scrolling/old.html

-Felix

@pmario
Copy link
Member

pmario commented Sep 14, 2015

I'm not sure, but I don't see a difference in behaviour between old and new. using win10, ff 40.0.3.

If I use the scroll wheel, both versions scroll. ... there is a little difference: The new versions scrolls a little bit later.

@pmario
Copy link
Member

pmario commented Sep 14, 2015

probably, I use your test cases in a wrong way. How to reproduce?

@felixhayashi
Copy link
Contributor Author

Hi @pmario

I'm not sure, but I don't see a difference in behaviour between old and new. using win10, ff 40.0.3.

The behaviour for tiddlers without scroll containers is for both the same (I am referring to writing text in "A dummy Tiddler").

But old and new differ for text areas with scrollable parents. To see a difference,

  1. go to "Inside a scrollable parent".
  2. Click into the text area and scroll down till you see "junk TV quiz." (By the way, I just noticed the blind text I copied from a generator is rather stupid, sorry).
  3. Type a letter with your keyboard
    1. For the old wiki, it will jump/scroll to the top (like I demonstrated in this video a few weeks ago: https://www.youtube.com/watch?v=Fw-_zlJzuDg&feature=youtu.be).
    2. For the new wiki, it will behave just like when you are inside in a tiddler edit mode.

-Felix

@pmario
Copy link
Member

pmario commented Sep 14, 2015

ahh, I see. Sorry for the trouble. so

+1 for the fix. tested with ff latest and MS Edge on win 10 :)

@felixhayashi
Copy link
Contributor Author

ahh, I see. Sorry for the trouble. so
+1 for the fix. tested with ff latest and MS Edge on win 10 :)

No problem, glad you tested it and it works! :)

-Felix

@felixhayashi
Copy link
Contributor Author

Hi @Jermolene

Could you please signal me, whether you are satisfied with the PR or not? It is important for TiddlyMap, otherwise working in fullscreen is not really possible, so I hope it is included in the next TiddlyWiki release.

Thanks
-Felix

@tobibeer
Copy link
Contributor

@felixhayashi, when I test "A dummy tiddler" in the new version, the behavior seems to have actually deteriorated from working fine in the old one to jumpy in the new one. Hit enter at the bottom to add some new lines. Can you confirm?

@felixhayashi
Copy link
Contributor Author

Can you confirm?

Whoops. Yes. Not sure what is causing this, I'll need to fix that.

@felixhayashi
Copy link
Contributor Author

It only happens for the very last tiddler in the river. If you open/create other tiddlers in the river and do as you described above, it works fine. Strange…

@felixhayashi
Copy link
Contributor Author

Ok found the problem and will upload a new version in a minute.

felixhayashi added a commit to felixhayashi/TiddlyWiki5 that referenced this pull request Sep 20, 2015
element that has scrollbars. The wrapper element with the
scroll bar does not need to be a direct parent of the text area.

**update:** fixed a bug

This is fixed now: TiddlyWiki#1933 (comment)

The problem was the check in getScrollContainer()
felixhayashi added a commit to felixhayashi/TiddlyWiki5 that referenced this pull request Sep 20, 2015
element that has scrollbars. The wrapper element with the
scroll bar does not need to be a direct parent of the text area.

**update:** fixed a bug

This is fixed now: TiddlyWiki#1933 (comment)

The problem was the check in getScrollContainer()
var container = this.getScrollContainer(domNode),
scrollTop = container.scrollTop;
// Measure the specified minimum height
domNode.style.height = this.editMinHeight;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Jermolene that is an interesting way to allow the user to use calc() and percent units… I mean you assign the minHeight to the domNode just to measure it and the override it again with "auto", that seems strange at first sight – but considering, that the user may enter values that are not pixels, it is very clever to calculate the height that way.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The purpose of the manoeuvre is actually to measure the 'natural' size of the content of the textarea so that we can then explicitly set the textarea itself to that size. If the user is manually sizing the textarea then none of this is needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, then I misinterpreted this line. Thanks for the clarification.

@felixhayashi
Copy link
Contributor Author

@tobibeer thanks for telling me. I updated the patch. Should work now :)

See the demo.

@Jermolene
Copy link
Member

Sorry @felixhayashi I'm only just having a look at this now. In principle I'm very keen on a fix, but I haven't yet investigated the approach you've taken or explored any unintended impact.

@felixhayashi
Copy link
Contributor Author

Sorry @felixhayashi I'm only just having a look at this now. In principle I'm very keen on a fix, but I haven't yet investigated the approach you've taken or explored any unintended impact.

Ah ok, thanks for telling me. Then I know you are aware of it. :)

@tobibeer
Copy link
Contributor

@felixhayashi, works like a charm now, thanks.

@Jermolene
Copy link
Member

@felixhayashi I haven't forgotten this PR! I will make some time to test it properly over the next couple of days

@felixhayashi
Copy link
Contributor Author

Thanks @Jermolene. I appreciate very much that you are informing me. Please take your time, I agree this needs some thorough testing as it is an important widget :)

element that has scrollbars. The wrapper element with the
scroll bar does not need to be a direct parent of the text area.

**update:** fixed a bug that came up in the discussion

This is fixed now: TiddlyWiki#1933 (comment)

The problem was the check in getScrollContainer()
@felixhayashi
Copy link
Contributor Author

Just as a sidenote: I have tested this PR in all my wikis (Chrome + FF) the past weeks and it works without any problems.

// Make sure that the dimensions of the textarea are recalculated
$tw.utils.forceLayout(domNode);
// Check that the scroll position is still visible before trying to scroll back to it
scrollTop = Math.min(scrollTop,self.document.body.scrollHeight - window.innerHeight);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @felixhayashi my apologies. I'm going to focus on the backlog of pull requests for a few days, and wanted to start with this one!

Anyhow, your changes appear to have lost the logic here that checks that the scroll position is still visible. Is that intentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Jermolene

This is intentional because I use scrollTop and not window.scrollTo()

scrollTop can be set to any integer value, with certain caveats:

If the element can't be scrolled (e.g. it has no overflow or if the element is non-scrollable), scrollTop is set to 0.
If set to a value less than 0, scrollTop is set to 0.
If set to a value greater than the maximum that the content can be scrolled, scrollTop is set to the maximum.

https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollTop

So I do not need to do this check.

Moreover, the new code that accounts for situation with nested elements that act as scroll containers, the parent may not be the window object (as in the original/old code; also reflected in $tw.utils.getScrollPosition only looking at the window object) and the scrollHeight of relevance may not be the one of the body element.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But feel free to thoroughly test it :)

Jermolene added a commit that referenced this pull request Dec 22, 2015
Auto-height fix for text area which is contained in a scroll container
@Jermolene Jermolene merged commit ccf6edb into TiddlyWiki:master Dec 22, 2015
@felixhayashi
Copy link
Contributor Author

Yay! 😃 thanks @Jermolene

@Jermolene
Copy link
Member

No problem @felixhayashi

I've just updated the prerelease too: http://tiddlywiki.com/prerelease

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants