Bug 56061 - selectionStart reports wrong caret position when the last characters are newlines
Summary: selectionStart reports wrong caret position when the last characters are newl...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Forms (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Ryosuke Niwa
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-03-09 16:33 PST by Ryosuke Niwa
Modified: 2011-03-09 17:46 PST (History)
6 users (show)

See Also:


Attachments
demo (1.27 KB, text/html)
2011-03-09 17:02 PST, Ryosuke Niwa
no flags Details
fixes the bug (3.60 KB, patch)
2011-03-09 17:15 PST, Ryosuke Niwa
tkent: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ryosuke Niwa 2011-03-09 16:33:36 PST
http://crbug.com/56971

What steps will reproduce the problem?
1. Put some newlines in an empty textarea.
2. Read its selectionStart property via Javascript.

What is the expected result?
It should return the a number equal to the number of newlines.

What happens instead?
It always returns 1.

It may be a bug in Webkit, since Safari fails too. I did a reduction that shows the problem very easily:
http://martinml.com/textarea.html

This is especially annoying in a phpBB forum editor, since if you want to put some newlines and then click the button to insert a bbcode tag, it's inserted just after the last text, and not after the newlines.
Comment 1 Ryosuke Niwa 2011-03-09 17:02:58 PST
Created attachment 85260 [details]
demo

This is a failed attempt to write a layout out for this bug.  It seems like the bug can be reproduced only if we ran it manually.
Comment 2 Ryosuke Niwa 2011-03-09 17:15:11 PST
Created attachment 85262 [details]
fixes the bug
Comment 3 Kent Tamura 2011-03-09 17:24:41 PST
Comment on attachment 85262 [details]
fixes the bug

View in context: https://bugs.webkit.org/attachment.cgi?id=85262&action=review

> Source/WebCore/editing/SelectionController.cpp:171
> +        // See https://bugs.webkit.org/show_bug.cgi?id=56061

nit: I feel the bug entry doesn't have additional information and ChangeLog is enough.
Comment 4 Ryosuke Niwa 2011-03-09 17:34:31 PST
(In reply to comment #3)
> (From update of attachment 85262 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=85262&action=review
> 
> > Source/WebCore/editing/SelectionController.cpp:171
> > +        // See https://bugs.webkit.org/show_bug.cgi?id=56061
> 
> nit: I feel the bug entry doesn't have additional information and ChangeLog is enough.

Ok. Do you think I can also get rid of the line above where I say "// Even if selection was not changed, selection offset may have been changed." ?
Comment 5 Kent Tamura 2011-03-09 17:36:17 PST
(In reply to comment #4)
> Do you think I can also get rid of the line above where I say "// Even if selection was not changed, selection offset may have been changed." ?

No.  This line looks helpful.
Comment 6 Ryosuke Niwa 2011-03-09 17:43:57 PST
(In reply to comment #5)
> (In reply to comment #4)
> > Do you think I can also get rid of the line above where I say "// Even if selection was not changed, selection offset may have been changed." ?
> 
> No.  This line looks helpful.

Ok.  Thanks for the review.  Landing it now.
Comment 7 Ryosuke Niwa 2011-03-09 17:46:58 PST
Committed r80679: <http://trac.webkit.org/changeset/80679>