keep_line_breaks: Compare with the token end line

This commit is contained in:
Eugen Wissner 2020-03-24 10:33:56 +01:00
parent 394da5d02a
commit ef83514541
4 changed files with 30 additions and 3 deletions

View File

@ -2151,10 +2151,22 @@ const pure @safe @nogc:
bool onNextLine() @nogc nothrow pure @safe bool onNextLine() @nogc nothrow pure @safe
{ {
import dfmt.editorconfig : OptionalBoolean; import dfmt.editorconfig : OptionalBoolean;
import std.algorithm.searching : count;
import std.string : representation;
return config.dfmt_keep_line_breaks == OptionalBoolean.t if (config.dfmt_keep_line_breaks == OptionalBoolean.f || index <= 0)
&& index > 0 {
&& tokens[index - 1].line < tokens[index].line; return false;
}
// To compare whether 2 tokens are on same line, we need the end line
// of the first token (tokens[index - 1]) and the start line of the
// second one (tokens[index]). If a token takes multiple lines (e.g. a
// multi-line string), we can sum the number of the newlines in the
// token and tokens[index - 1].line, the start line.
const previousTokenEndLineNo = tokens[index - 1].line
+ tokens[index - 1].text.representation.count('\n');
return previousTokenEndLineNo < tokens[index].line;
} }
/// Bugs: not unicode correct /// Bugs: not unicode correct

View File

@ -25,6 +25,11 @@ int[] func(int argument_1_1, int argument_1_2,
this.argument_2_1, this.argument_2_2, this.argument_2_1, this.argument_2_2,
argument_3_1, argument_3_2); argument_3_1, argument_3_2);
`
<html>
</html>
`.format!"%s";
return [ return [
3, 5, 3, 5,
5, 7, 5, 7,

View File

@ -25,6 +25,11 @@ int[] func(int argument_1_1, int argument_1_2,
this.argument_2_1, this.argument_2_2, this.argument_2_1, this.argument_2_2,
argument_3_1, argument_3_2); argument_3_1, argument_3_2);
`
<html>
</html>
`.format!"%s";
return [ return [
3, 5, 3, 5,
5, 7, 5, 7,

View File

@ -21,6 +21,11 @@ int[] func(int argument_1_1, int argument_1_2,
this.argument_2_1, this.argument_2_2, this.argument_2_1, this.argument_2_2,
argument_3_1, argument_3_2); argument_3_1, argument_3_2);
`
<html>
</html>
`.format!"%s";
return [ return [
3, 5, 3, 5,
5, 7, 5, 7,