Textarea scrolls to top after changing its .value, regardless of cursor position

RESOLVED FIXED in mozilla1.9.3a4

Status

()

Core
Editor
RESOLVED FIXED
14 years ago
5 years ago

People

(Reporter: Erik Moeller, Assigned: Ehsan)

Tracking

Trunk
mozilla1.9.3a4
x86
All
Points:
---
Bug Flags:
blocking1.8.1 -
in-testsuite +

Firefox Tracking Flags

(Not tracked)

Details

(URL)

Attachments

(2 attachments, 4 obsolete attachments)

(Reporter)

Description

14 years ago
User-Agent:       Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4) Gecko/20030624
Build Identifier: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4) Gecko/20030624, also tested with Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7a) Gecko/20040111 Firebird/0.8.0+

After changing the value of a textarea via JavaScript, it scrolls to the top. If
the cursor is subsequently set via selectionStart/selectionEnd or
setSelectionRange(a,b), the cursor itself is correctly set, but the textarea
view is still at the top. Calls to focus() make no difference either. 

This affects comment formatting toolbars, where we want to change the selection
to apply tags like "bold" and "italic" around it. This works as long as the
selection is not beyond the textarea visible range, i.e. as long as no scrolling
is required to make it. Any selection that goes beyond that triggers the bug:
the textarea scrolls to the top after its contents are overwritten.

Reproducible: Always

Steps to Reproduce:
1. Go to http://test.wikipedia.org/w/wiki.phtml?title=Main_Page&action=edit
2. Scroll to the bottom
3. Select some text
4. Click the "bold" button
Actual Results:  
Textarea view scrolls to top. When you press a non-dead key, you're in the right
position again (the cursor is correctly set in this script).

Expected Results:  
Textarea view should not have scrolled, or there should be a JavaScript method
to change the selection text without scrolling.

The script used is at
http://test.wikipedia.org/style/wikibits.js
(Reporter)

Comment 1

14 years ago
Another example:
http://www.massless.org/mozedit/
> After changing the value of a textarea via JavaScript, it scrolls to the top.

This part is correct -- you have wiped out the old text completely, so the old
insertion point is lost.

> cursor itself is correctly set, but the textarea view is still at the top

That sounds like a bug.  Over to editor core.  If you could attach a testcase to
this bug, that would be great.
Assignee: general → mozeditor
Component: DOM: Level 0 → Editor: Core
QA Contact: ian → sairuh
(Reporter)

Comment 3

14 years ago
Created attachment 139397 [details]
A HTML/JavaScript test case for this bug
(Reporter)

Comment 4

14 years ago
Does this help, Boris?

Comment 5

14 years ago
I see this using testcase on LInux 2004020207
(Reporter)

Comment 6

14 years ago
Created attachment 145368 [details]
Problem solved

JavaScript that solves this problem

Comment 7

13 years ago
Created attachment 151619 [details] [diff] [review]
Patch to fix the problem w/o a workaround

This patch has the textarea scroll the cursor into view whenever the selection
changes.  This seems to be the appropriate behavior.  With it the above
workaround is no longer required.

Comment 8

13 years ago
Comment on attachment 151619 [details] [diff] [review]
Patch to fix the problem w/o a workaround

The workaround worked, but this is nicer.
Attachment #151619 - Flags: review?(pinkerton)
Comment on attachment 151619 [details] [diff] [review]
Patch to fix the problem w/o a workaround

r=pink, though i know nothing about this code ;)
Attachment #151619 - Flags: review?(pinkerton) → review+
Comment on attachment 151619 [details] [diff] [review]
Patch to fix the problem w/o a workaround

>+  rv = selection->AddRange(range);
>+  // scroll the new selection into view
>+  // ignore any scrolling errors.
>+  mTextSelImpl->ScrollSelectionIntoView(nsISelectionController::SELECTION_NORMAL, 
>+    nsISelectionController::SELECTION_FOCUS_REGION, PR_TRUE);
>+  return rv;

You should probably test rv before the call to ScrollSelectionIntoView,
return it if NS_FAILED(rv) and return NS_OK after the call.

Comment 11

13 years ago
Sorry for being untutored about these things, but how does one install the
attachment so that it will fix the bug?  This bug has been driving me crazy for
months & I'd dearly love to fix it.

Are you perhaps in a testing stage & will reveal this fix & installation
protocols later?

Comment 12

13 years ago
d/l & extract
http://ftp.mozilla.org/pub/mozilla.org/mozilla/nightly/latest/mozilla-source.tar.bz2
apply patch using http://www.mozilla.org/build/unix-cheatsheet.html#applyPatch
make .mozconfig using http://webtools.mozilla.org/build/config.cgi
`make -f client.mk build`
if you need any other help contact irc://moznet/#mozillazine

Comment 13

13 years ago
(In reply to comment #12)
> d/l & extract
>
http://ftp.mozilla.org/pub/mozilla.org/mozilla/nightly/latest/mozilla-source.tar.bz2
> apply patch using http://www.mozilla.org/build/unix-cheatsheet.html#applyPatch
> make .mozconfig using http://webtools.mozilla.org/build/config.cgi
> `make -f client.mk build`
> if you need any other help contact irc://moznet/#mozillazine

when I try to save the .tar file to my desktop & open it w. winzip I get an
error saying it cannot open the file since it doesn't appear to be a legitimate
archive file.  I don't understand how one's supposed to use the Unix
Configurator.  Also, don't understand how to follow the patch cheatsheet
instructions.  I'm still totally confused about what one needs to do to fix the
problem or whether it's even possible to do so.

Comment 14

13 years ago
Created attachment 151854 [details] [diff] [review]
Patch v2

Now checking the return value per comments.  Not using NS_ENSURE_SUCCESS as
this really isn't the sort of place we'd want to assert.

Updated

13 years ago
Attachment #151619 - Attachment is obsolete: true

Comment 15

13 years ago
Sorry Richard, I thought you where the reporter who is using Linux. 
You can patch/compile Mozilla using the instructions located at
http://www.mozilla.org/build/win32.html.  This option is the most difficult of
the two and it will take hours to finish.

Your second option is to wait untill this patch is checked in to the tree.  When
this happens, the next nightly will have this patch.  The nightlys are located
at http://ftp.mozilla.org/pub/mozilla.org/mozilla/nightly/latest/.

Updated

13 years ago
Attachment #151854 - Flags: review?(pinkerton)

Updated

13 years ago
OS: Linux → All
Comment on attachment 151854 [details] [diff] [review]
Patch v2

again, r=pink but i'm not the best person to review this.
Attachment #151854 - Flags: review?(pinkerton) → review+

Comment 17

13 years ago
Tom Hennen: Do you plan land it in 1.8 timeframe? What's next step on this way,
if Mike Pinkerton review your last patch?

Comment 18

12 years ago
Not sure if this is relevant to the code, but since only selectionStart is
considered when scrolling the selection into view, perhaps only the code for
scrolling selection into view should be called only if selectionStart has
changed.  That would happen when setting selectionStart to a different value or
setting selectionEnd to a value less than selectionStart.  A little optimization.

Comment 19

12 years ago
A case where the JS workaround is still needed even if patch is checked in:

1) Enter enough text to make the scroll bar appear.
2) Select some text or a position in the text, so that the selection's
y-position is greater than clientHeight.
3) Scroll down a bit, so that the selected text is still in view.  Denote
current scrollTop as A.
4) Set value.  scrollTop=selectionStart=selectionEnd=0.
5) Set selectionStart/selectionEnd.

The textarea scrolls until the selected text is in view.  The selection should
be displayed at the bottom of the textarea.  However the new scroll position is
not A - at position A, the selection should not appear at the bottom of the
textarea.

Is this intended?
Requesting attention / blocking for 2.0 via IRC request.
Flags: blocking1.8.1?

Comment 21

11 years ago
Not going to block 1.8.1 for this, but we'd happily consider a patch once it has baked on the trunk.
Flags: blocking1.8.1? → blocking1.8.1-
QA Contact: bugzilla → editor
Assignee: mozeditor → nobody

Updated

10 years ago
Blocks: 232405

Comment 22

10 years ago
Created attachment 289312 [details] [diff] [review]
mozilla-input-selection-scroll-on-focus.patch

Updated patch, works for me ;)
Created attachment 432855 [details] [diff] [review]
Patch (v1)

Patch + test.
Assignee: nobody → ehsan.akhgari
Attachment #145368 - Attachment is obsolete: true
Attachment #151854 - Attachment is obsolete: true
Attachment #289312 - Attachment is obsolete: true
Status: NEW → ASSIGNED
Attachment #432855 - Flags: review?(bzbarsky)
Comment on attachment 432855 [details] [diff] [review]
Patch (v1)

bz's out, switching the review request to roc.
Attachment #432855 - Flags: review?(bzbarsky) → review?(roc)
Attachment #432855 - Flags: review?(roc) → review+
http://hg.mozilla.org/mozilla-central/rev/ba70a0cb9240
Status: ASSIGNED → RESOLVED
Last Resolved: 8 years ago
Flags: in-testsuite+
Resolution: --- → FIXED
Target Milestone: --- → mozilla1.9.3a4

Updated

5 years ago
Duplicate of this bug: 779913
You need to log in before you can comment on or make changes to this bug.