Page MenuHomePhabricator

Remember textarea scrollbar position between previews
Closed, ResolvedPublic

Description

Author: markus

Description:
It would be a nice useability enhancement to also remember the position of the
textarea's scrollbar between preview requests of a page.

Say I've entered many lines of text and work currently somewhere in the middle
of the text, upon preview of the page, the scrollbar ist always at the top.

An implementation would need to rely on JavaScript. Before the page (form) is
submitted for preview, the scrollTop position is read and written into a already
existing hidden input field which is then written back to the client as
JavaScript statement to the textarea so it positions itself to the old position.


Version: unspecified
Severity: enhancement

Details

Reference
bz1499
TitleReferenceAuthorSource BranchDest Branch
Indent JSON files with tab instead of two spacesrepos/phabricator/arcanist!3aklapperT349989jsonIndentTabSpaceswmf/stable
GerritStreamHandler: Cleanup work directory if no suggestionskharlan/fix-suggester-bot!20kharlanmain-I28e0a010792032768e78381913271f25290cf12emain
GerritStreamHandler: Use rmdir to get rid of working directorykharlan/fix-suggester-bot!19kharlanmain-If023d2d9482fa0d64707b5890d914a2ebea464d1main
Customize query in GitLab

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 21 2014, 8:13 PM
bzimport set Reference to bz1499.
bzimport added a subscriber: Unknown Object (MLST).

markus wrote:

Patch for remembering scrollTop in Preview-Mode

This patch gives basic support for remembering the scrollTop position on the
preview page.

How it works:

  1. It creates a new property $jsScrollTop in EditPage, initially set to 0
  2. If EditPage is showing a preview, the $jsScrollTop is set from the Request
  3. If we're previewing a page and $jsScrollTop > 0 , add the necessary body

onload Handler to set the scrollTop value on the textarea, once the page is
loaded

  1. Adds a handleEditformSubmit JS function which gets triggered when "editform"

is submitted (currently does make no distinction whether it's a preview or not)

  1. Adds a input type="hidden" field which holds the jsScrollTop value
  2. Lets SkinTemplate.php set the body onload handler (this was missing before

anyway)

  1. Enabled the body onload handler in skins/MonoBook.php (was missing, too)

attachment scrollTop.diff ignored as obsolete

markus wrote:

Cleaned up patch, moved JS code to wikibits

This is like the first patch, with the following things changed:

  1. Moves the JS-handler to skins/common/wikibits.js
  2. More carefully checks if all the elements required for making this feature work are there.

I've tested in successfully on Windows with:
IE 5.0+
Netscape 7.1+
Mozilla 1.7.3+
Firefox 1.0

In Opera (7.54u2), the scrollTop property can be read and will be
submitted and later set in onload, but this scrollbar of the
textarea doesn't refelect the change (though re-reading the property
tells the newly set value).

In all other browsers the feature did not work but didn't cause
any troubles (javascript errors, abort of submit) either.

One thing I've spotted:
Since I've enabled the onload-Handler in the (default) Template, the
"document.editform.wpTextbox1.focus()" handler (EditPage.php, line 583)
will start working too, which was not ran until now. In any circumstance
both onload-Handlers will get fired, my new handler would overwrite the
previous one (no logic of stacking handlers at PHP level like with
addEventListener.

Attached:

lupin.wp wrote:

I like this idea.

The patch should probably use the existing javascript function addOnloadHook
from wikibits.js instead of altering Monobook.php.

markus wrote:

It most likely should. When I came up with the patch, there was no addOnloadHook
in the stable release back then. Since I'm running still the same version of
MediaWiki I'm currently not able to create a new patch, I hope someone else can.
This is really useful and I'm still happy every day that I wrote it ;)

lupin.wp wrote:

It turns out that this feature has been in Mediawiki since October 2005 :-)