Why do indents disappear from custom materials on my site?

My site has text areas where users can post (code) posts. When they visit the page later, it will display their presentation. This works great, but recently some of the entries do not display the correct tabs and new lines at startup. I looked at the data in Rails, and it looks like some elements do not have the tab labels ( \t ) that should be there. It seems that the tabs have been replaced with spaces that are not displayed when the text is displayed. What can cause this error and how to fix it?

Example text that was saved correctly:

 "lots of text;\r\n\r\some more text {\r\n\r\n\tsome code here(int a, int b{\r\n\t\t\tif(a%2==0)" 

An example of a mysterious problem text:

 " some text\r\n some more text\r\n come code\r\n bla bla\r\n end end\r\n " 

Note. The text is entered into the Ace editor , but is transferred to the hidden text area when the user clicks the "Submit" button.

I could not repeat this error when starting locally during the development process. This happened only with some representations in production (at Heroku).

Refresh . Hidden text_area sometimes displays text with a space, but the ace editor does not display it correctly in its div.

+4
source share
1 answer

How do you set the value for an ace? If you use editor.setvalue(str) str=editor.getvalue() , the line cannot be changed.

But if you set the text to the dom element and call ace.edit , you have to be careful.

+3
source

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


All Articles