padolsey/jQuery.fn.autoResize — Issue #48: FF/Win: Inserting carriage returns in text area content moves cursor to end of content
Author: wwjamieson3
Created: 2012-02-15 03:05:56+00:00
State: open

### Conditions to replicate:

1. Browser: Firefox

2. Platform: Windows

3. Have a resizing text area containing several lines of content at load time

### To trigger the error:
Place your cursor somewhere in the middle of the text are and hit the enter or return key.

### Error Description:
The carriage return is added to the text area content in the correct position, however the cursor is then moved to the end of the text area content for some reason. This makes it extremely frustrating for users to insert content into a text area containing existing content.

### Solution:
Add the line: `immediate = true; `after `scrollTop = config.minHeight;` at line 236

#### Change From (Starting at line 231):
if (scrollTop + config.extraSpace >= config.maxHeight) {
el.css('overflowY', '');
scrollTop = config.maxHeight;
immediate = true;
} else if (scrollTop <= config.minHeight) {
scrollTop = config.minHeight;
} else {
el.css('overflowY', 'hidden');
scrollTop += config.extraSpace;
}

#### Change To:
if (scrollTop + config.extraSpace >= config.maxHeight) {
el.css('overflowY', '');
scrollTop = config.maxHeight;
immediate = true;
} else if (scrollTop <= config.minHeight) {
scrollTop = config.minHeight;
// ADDED TO FIX A FIREFOX BUG WHERE INSERTING A CARRIAGE RETURN IN THE MIDDLE OF
// TEXTAREA CONTENT ADDS THE CARRIAGE RETURN IN THE CORRECT POSITION, BUT THEN
// FOR SOME REASON MOVES THE CURSOR TO THE END OF THE TEXT AREA CONTENT
immediate = true;
} else {
el.css('overflowY', 'hidden');
scrollTop += config.extraSpace;
}