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

Preserve scroll position and textarea height when previewing a comment #194

Closed
roryokane opened this Issue Mar 19, 2015 · 0 comments

Comments

Projects
None yet
1 participant
@roryokane

roryokane commented Mar 19, 2015

The problem

Say I am writing a long comment, and I have used the browser-provided drag handles on textareas to make the editing area taller:

writing comment at bottom of resized textarea

I am having trouble writing this last paragraph. So I click Preview to see how it looks without markup, so I can review what I have written more easily. I see this:

after clicking Preview

After reading the preview of the comment, I know what to write next. But now I have to drag the window back to a readable height, and then scroll back to where I was. This is very annoying when it happens multiple times over the course of writing a long comment.

The solution

The Preview button currently deletes and replaces the comment textarea. It should save the scroll position and height before deletion, and restore them after creating the replacement. Or, even better, it should just preserve the current textarea element, so that all properties remain the same. This would make it easier to preserve other useful properties in the future if necessary, such as cursor position. (Right now, cursor position is always lost by the click outside of the textarea, so it doesn’t need to be preserved.)

The JavaScript that handles previewing is previewComment in application.js. It currently sends the comment form to the server, then uses jQuery’s replaceWith to overwrite the entire comment form (the closest .comment) with the HTML contained in the server’s response. The server’s response comes from preview in CommentsController, which renders the view comments/commentbox.

This issue will still apply if #101 “Use a Github-style markdown previewer tab” is implemented. When switching back from the preview tab, the scroll position and height should be the same as the user left them. GitHub’s implementation already does this.

@jcs jcs closed this in ff09781 Jul 24, 2015

SiDevesh pushed a commit to RedCarpetUp/lobsters that referenced this issue Jul 11, 2016

SiDevesh pushed a commit to RedCarpetUp/lobsters that referenced this issue Aug 1, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment