Handsotnable auto convert \r\n to \n

Tags: #<Tag:0x00007efc606010e0>

Hi,

I want to check cell is changed with data contain multi line in a cell.

The data get from API will contain \r\n as new line. When I open edit mode then focus out (Don’t change the value), the value will auto convert \r\n to \n. It will detect the value has changed
You can check at https://jsfiddle.net/TonyNguyen001/jxgp7vnm/20/

I don’t want to replace \r\n to \n to check value is changed. I just want the value will not convert from \r\n to \n. Is there any way can I do that ?

Thanks in advance !

Hi @khanguyen96

I asked my colleague to share his feedback. I should be back with updates next week.

Handsontable uses a textarea internally. Web browsers normalize the value of textarea by converting CRLF to LF, according to the HTML spec:

The algorithm for obtaining the element’s API value is to return the element’s raw value, with newlines normalized.

Source: https://html.spec.whatwg.org/#the-textarea-element

The newline normalization algorithm is exactly explained in the spec:

To normalize newlines in a string, replace every U+000D CR U+000A LF code point pair with a single U+000A LF code point, and then replace every remaining U+000D CR code point with a U+000A LF code point.

Source: https://infra.spec.whatwg.org/#normalize-newlines

After normalization, there is no way we can tell if the original string contained \r\n or \n. The only thing you can do is to apply some kind of reverse normalization in your user code.

Thanks for your reply, I decided to replace \r\n to \n