This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 197204 - HTML formating doesn't format line without a tag in some cases.
Summary: HTML formating doesn't format line without a tag in some cases.
Status: RESOLVED FIXED
Alias: None
Product: web
Classification: Unclassified
Component: HTML Editor (show other bugs)
Version: -S1S-
Hardware: PC Linux
: P3 normal (vote)
Assignee: David Konecny
URL:
Keywords:
Depends on:
Blocks: 196519
  Show dependency tree
 
Reported: 2011-03-29 17:07 UTC by Petr Pisl
Modified: 2011-04-08 08:52 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Petr Pisl 2011-03-29 17:07:52 UTC
Have this code:


<html>
    <body>
        <p>
					This text keeps getting indented with each auto-format.
        </p>
        <p>
            <span>This text stays put.</span>
					But this line does not because of the leading newline.
        </p>
    </body>
</html>

The tabs are probably important before the lines without an html tag. After formatting the lines are not moved.
Comment 1 David Konecny 2011-04-04 19:38:28 UTC
I thought that tab characters would be automatically converted to space characters. But that's not the case even if that option is set in editor properties. Do you know what's the story Marek??
Comment 2 Petr Pisl 2011-04-05 09:32:37 UTC
I can be wrong, but when I debugged it (2 weeks ago), it seemed  to me that the lines are not touched by the formatter, there are somehow skipped. 

Another problem what I see there:
In the code you use the  context.modifyIndent () that basically call IndentUtils.createIndentString(Document doc, int indent) and this method works (at least it worked, when I used it in PHP formatter). But using this is performance problem during formatting bigger files. IndentUtils.createIndentString(Document doc, int indent) basically needs to find out the settings for the document and reads the settings from Preferences, which is slow. It means that for every line the options are read and this have impact on the time of the formatting 

The php formatter for this reason use method 
IndentOptions.createIndentString(int indent, boolean expandTabs, int tabSize), where the options are read only once before the formatting. But it's true that the php formatter call this almost for every whitespace, the html only for every line.
Comment 3 Marek Fukala 2011-04-05 10:23:59 UTC
I'm not even sure if I understand the mentioned problem correctly.

My observations:
1) before fiddling with the "expand tabs to spaces" the text was reformatted correctly, it contained only space chars, not tabs,
2) after disabling the option and reformatting, some of the lines' leading whitespaces have been replaced by tabs. The formatting still correct, so far so good,
3) however if I add or remove some whitespaces at the lines leading with tab char, these lines are not formatted anymore regardless how the "ETTS" option is set.

To me this looks like apparent bug in the formatter being "confused" by the tabs. Cannot this be caused by some code reading the whitespaces "length" and not distinguishing the tab and space size???
Comment 4 Marek Fukala 2011-04-05 10:26:56 UTC
Actually the line doesn't have to start with the tab, it's just enough it contains it.
Comment 5 Marek Fukala 2011-04-05 11:21:35 UTC
fixed in web-main#a6455efa2d44 

...though I'm not 100% sure whether this fix is safe since it replaces if(char == ' ') by Character.isWhitespace(char) which considers much more tokens as whitespaces than just the space and tab. Davide, please think through whether this change cannot cause regressions especially in terms of end line chars being now considered as WS.

Possibly more proper fix would be to use document.isWhitespace() or extend the api so AbstractIndenter has isWhitespace(char). Maybe just adding || char == '\t' would be fine.
Comment 6 David Konecny 2011-04-05 19:15:02 UTC
I do not think I ever tested my indenter code on a text containing a tab characters.

re. "Character.isWhitespace(char)" - with changes in indenter code nothing is guaranteed. :-) It may or may not be OK. "|| char == '\t'" would be safer but again who knows. :-) I will have a look. And add this testcase to unit test suites.

Thanks for fixing it Marek.
Comment 7 Quality Engineering 2011-04-06 08:46:10 UTC
Integrated into 'main-golden', will be available in build *201104060400* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main/rev/a6455efa2d44
User: Marek Fukala <mfukala@netbeans.org>
Log: #197204 - HTML formating doesn't format line without a tag in some cases.
Comment 8 David Konecny 2011-04-06 23:45:46 UTC
Re. "Character.isWhitespace(char)" - this just looks too scary for me. :-)  100% correct but scary. I changed it to check only for space and tab characters. And added the test case provided to the unit tests. In indentation things can go so wrong that the less changes the better. :-)

32ac8b5ddb30
Comment 9 Marek Fukala 2011-04-07 08:10:06 UTC
(In reply to comment #8)
> Re. "Character.isWhitespace(char)" - this just looks too scary for me. :-) 
> 100% correct but scary. I changed it to check only for space and tab
> characters. And added the test case provided to the unit tests. In indentation
> things can go so wrong that the less changes the better. :-)
> 
> 32ac8b5ddb30

I completely agree. If you are not 100% sure the end line chars or possibly other weird whitespace chars may not be somehow taken into account and cause an unexpected behavior than this is definitively better.
Comment 10 Quality Engineering 2011-04-08 08:52:16 UTC
Integrated into 'main-golden', will be available in build *201104080400* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main/rev/32ac8b5ddb30
User: David Konecny <dkonecny@netbeans.org>
Log: #197204 - HTML formating doesn't format line without a tag in some cases.
adding unit test and restricting whitespace check only to space and tab character