keep_line_breaks: Compare with the token end line
This commit is contained in:
parent
394da5d02a
commit
ef83514541
|
|
@ -2151,10 +2151,22 @@ const pure @safe @nogc:
|
|||
bool onNextLine() @nogc nothrow pure @safe
|
||||
{
|
||||
import dfmt.editorconfig : OptionalBoolean;
|
||||
import std.algorithm.searching : count;
|
||||
import std.string : representation;
|
||||
|
||||
return config.dfmt_keep_line_breaks == OptionalBoolean.t
|
||||
&& index > 0
|
||||
&& tokens[index - 1].line < tokens[index].line;
|
||||
if (config.dfmt_keep_line_breaks == OptionalBoolean.f || index <= 0)
|
||||
{
|
||||
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
|
||||
|
|
|
|||
|
|
@ -25,6 +25,11 @@ int[] func(int argument_1_1, int argument_1_2,
|
|||
this.argument_2_1, this.argument_2_2,
|
||||
argument_3_1, argument_3_2);
|
||||
|
||||
`
|
||||
<html>
|
||||
</html>
|
||||
`.format!"%s";
|
||||
|
||||
return [
|
||||
3, 5,
|
||||
5, 7,
|
||||
|
|
|
|||
|
|
@ -25,6 +25,11 @@ int[] func(int argument_1_1, int argument_1_2,
|
|||
this.argument_2_1, this.argument_2_2,
|
||||
argument_3_1, argument_3_2);
|
||||
|
||||
`
|
||||
<html>
|
||||
</html>
|
||||
`.format!"%s";
|
||||
|
||||
return [
|
||||
3, 5,
|
||||
5, 7,
|
||||
|
|
|
|||
|
|
@ -21,6 +21,11 @@ int[] func(int argument_1_1, int argument_1_2,
|
|||
this.argument_2_1, this.argument_2_2,
|
||||
argument_3_1, argument_3_2);
|
||||
|
||||
`
|
||||
<html>
|
||||
</html>
|
||||
`.format!"%s";
|
||||
|
||||
return [
|
||||
3, 5,
|
||||
5, 7,
|
||||
|
|
|
|||
Loading…
Reference in New Issue