atom feed3 messages in com.googlegroups.jquery-en[jQuery] Dealing with Firefox textare...
FromSent OnAttachments
Patrick HallJun 27, 2006 3:23 am 
Michael GearyJun 27, 2006 8:28 am 
Patrick HallJun 27, 2006 11:54 am 
Subject:[jQuery] Dealing with Firefox textarea bug? (somewhat off topic)
From:Michael Geary (M.@Geary.com)
Date:Jun 27, 2006 8:28:57 am
List:com.googlegroups.jquery-en

I hope this isn't too terribly off topic, since the actual problem is a Firefox bug, but perhaps it will be of interest to other Firefox/jQuery users. I am using a very simple jQuery script to input unusual characters. It simply runs a bunch of substitutions on the .value of a textarea on every .keyup(). Here's a test:

http://ruphus.com/debug/eo.html

It works fine, but if the text is too long to fit in the textarea, it automatically scrolls back to the top after every keyup -- that is, every time the textarea's .value is reset. This is a known bug in Firefox:

https://bugzilla.mozilla.org/show_bug.cgi?id=231389

There is a workaround in that thread:

https://bugzilla.mozilla.org/attachment.cgi?id=145368

But it ain't pretty. Perhaps someone here has dealt with this bug, or has an idea for a better workaround?

The scrolling workaround in that page is just these two lines of code:

var scrollTop = txtarea.scrollTop; /* change text and set new selection here */ txtarea.scrollTop = scrollTop;

I don't see how it could get any simpler than that - save the scroll position before changing the text, restore it after.

The rest of the JavaScript code on that test page corresponds to code you'd have anyway - replacing the selected text, setting the new selection, etc. You don't need to replace your existing code to implement the workaround, just save and restore scrollTop at the right place.

-Mike