What characters will TextArea wrap other than spaces?

I am working on the latest version of my plugin, Textarea Line Counter ( http://mostthingsweb.com/?p=84 ). To make it even more accurate, I want to identify areas of text that are wrapped because they are too large to fit on a line (for example, a sequence of repeating characters).

I assume that browsers only wrap text in spaces. Are there any other characters that can be enclosed in strings? Thanks,

+4
source share
4 answers

Based on all your tips, I created a solution. It is quite large, and in fact I think that I will make it a separate plugin, as well as including it in my Textarea Line Counter. It works as follows:

  • Create a div to act as a container and set the font to something monospaced (i.e. each character has the same width)
  • Create a span inside the container and place one letter.
  • Take a range width dimension (which will be the width of the letter after the fields, indents, and some other CSS attributes are cloned).
  • Create another div inside the container and clone its CSS attributes. Set the width to half the width of the letter found in step 3 and write down its height.
  • To check if the character will wrap, set the div text to: A[some character]A [some character] is the character you are trying to verify.
  • Check the height of the div . If it is greater than the height found in step 4, the text is wrapped.

I look forward to the release of this plugin. Thanks again for all your advice.

+1
source

It looks like it depends on the browser, my Opera also wraps up, for example. + % ? $ / ( [ { } \ ° ! ¿
Safari / Chrome on ¿ ? also

(guess there are many more)

+2
source

Good idea for a plugin. Dealing with accuracy issues will be a challenge.

There is no universal catch for the textarea path that will process the string (except for line breaks in spaces) or using word-wrap.

FireFox screenshot in OSX

IE has created a gap with . , () {} ? . , () {} ? but not with / * = +

IE7.8

In this example, textarea seems to have a "special" feel like td

+2
source

some browsers will break inside words if the word is longer than the width of the column, otherwise they break into spaces.

I noticed that some browsers set this by default - you too can in most browsers:

 textarea{word-wrap: break-word} 

you can be sure that it is not installed using textarea{word-wrap: normal}

+1
source

Source: https://habr.com/ru/post/1339925/


All Articles