Get string on visual line (not wordwrapped) in a wordwrapped

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
vapoorize
Forum Newbie
Posts: 22
Joined: Mon Dec 17, 2007 5:35 pm

Get string on visual line (not wordwrapped) in a wordwrapped

Post by vapoorize »

Hi is there an easy way (method, property) to get the string occupying a "visual line" in a wordwrapped textarea?

What I mean by visual line:
A string of characters that does not spill into the line below it and occupies one line on the textarea, even if this line strays into the right-side scrolling portion of the textarea. How would a wordwrapped textarea manage to have a horizontal scroll bar you ask? Well, a line will have horizontal scrollbar when the # of chars occupying the line are more than the width dimensions of the textarea AND there are no spaces in the line. ie: sdddddNOSPACESddddddsddddddddddddddddddddddd


A simpleton solution is to determine where there are linebreaks and after that determine where there are more characters than what fits on a line. That in itself is a debatable matter, because how many characters that fit on a textarea line depend on their pixel width which is not uniform for all characters in the same pixel setting. IE: in the same pixel size the char 'a' will have different pixel width than '.'
A line full of '.' will have more characters occupying it than a line full of 'a'


-thanks for reading
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Re: Get string on visual line (not wordwrapped) in a wordwrapped

Post by Kieran Huggins »

so you want to determine the width of a string?
vapoorize
Forum Newbie
Posts: 22
Joined: Mon Dec 17, 2007 5:35 pm

Re: Get string on visual line (not wordwrapped) in a wordwrapped

Post by vapoorize »

In a more complicated way...
With scrollWidth property you can determine the width of the widest line in a textarea, but I'm wanting to determine the width of any particular line among a wordwrapped text inside of a textarea that consists of many different size width lines.

Ugh.. questions aren't answers to other questions! :(
Post Reply