Skip to content

Commit a84c93c

Browse files
committed
fixed indentation of anon function body, fixes #577
1 parent b1a9b15 commit a84c93c

File tree

5 files changed

+83
-8
lines changed

5 files changed

+83
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
- Fixed broken indentation after case with OpOr pattern, fixes [#576](https://github.com/HaxeCheckstyle/haxe-formatter/issues/576)
66
- Fixed missing linebreak between metadata and doc comment, fixes [#578](https://github.com/HaxeCheckstyle/haxe-formatter/issues/578)
7+
- Fixed indentation in anon function body, fixes [#577](https://github.com/HaxeCheckstyle/haxe-formatter/issues/577)
78
- Changed default wrapping location of `casePattern` to `afterLast`, fixes [#579](https://github.com/HaxeCheckstyle/haxe-formatter/issues/579)
89

910
## version 1.10.0 (2020-04-11)

src/formatter/marker/Indenter.hx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
package formatter.marker;
22

3+
import formatter.config.Config;
4+
import formatter.config.IndentationConfig;
35
#if debugIndent
4-
import haxe.PosInfos;
56
import sys.io.File;
67
import sys.io.FileOutput;
78
#end
8-
import formatter.config.IndentationConfig;
99

1010
class Indenter {
1111
var config:IndentationConfig;
1212
var parsedCode:Null<ParsedCode>;
1313

14-
public function new(config:IndentationConfig) {
15-
this.config = config;
14+
public function new(config:Config) {
15+
this.config = fconfig;
1616
if (config.character.toLowerCase() == "tab") {
1717
config.character = "\t";
1818
}
@@ -311,6 +311,12 @@ class Indenter {
311311
while (firstToken != null && !parsedCode.tokenList.isNewLineBefore(firstToken.token)) {
312312
firstToken = parsedCode.tokenList.getPreviousToken(firstToken.token);
313313
}
314+
var brOpen:Null<TokenTree> = prevToken.access().firstOf(BrOpen).token;
315+
if (brOpen != null) {
316+
if (!parsedCode.tokenList.isSameLineBetween(prevToken, brOpen, false)) {
317+
continue;
318+
}
319+
}
314320
return count + calcIndent(firstToken.token);
315321
}
316322
default:

src/formatter/marker/MarkTokenText.hx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
package formatter.marker;
22

3-
import haxe.zip.Entry;
43
import haxeparser.HaxeLexer;
4+
import tokentree.TokenStream;
55
import tokentree.TokenStreamProgress;
66
import tokentree.walk.WalkStatement;
7-
import tokentree.TokenStream;
87
import formatter.codedata.CodeLines;
98
import formatter.codedata.FormatterInputData;
10-
import formatter.codedata.ParseFile;
119
import formatter.codedata.ParsedCode;
12-
import formatter.codedata.TokenData;
1310

1411
class MarkTokenText extends MarkerBase {
1512
public function run() {
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{}
2+
3+
---
4+
5+
class PlayState extends FlxState
6+
{
7+
function createAttachmentControls():Void
8+
{
9+
add(attachmentDropDown = new FlxUIDropDownMenu(modelDropDownLoc.x, modelDropDownLoc.y - 30,
10+
FlxUIDropDownMenu.makeStrIdLabelArray(FlxGamepadAttachment.getConstructors()), function(attachment)
11+
{
12+
var gamepad = FlxG.gamepads.lastActive;
13+
if (gamepad != null)
14+
gamepad.attachment = FlxGamepadAttachment.createByName(attachment);
15+
updateConnectedGamepads(true);
16+
}, new FlxUIDropDownHeader(150)));
17+
}
18+
}
19+
20+
---
21+
22+
class PlayState extends FlxState {
23+
function createAttachmentControls():Void {
24+
add(attachmentDropDown = new FlxUIDropDownMenu(modelDropDownLoc.x, modelDropDownLoc.y - 30,
25+
FlxUIDropDownMenu.makeStrIdLabelArray(FlxGamepadAttachment.getConstructors()), function(attachment) {
26+
var gamepad = FlxG.gamepads.lastActive;
27+
if (gamepad != null)
28+
gamepad.attachment = FlxGamepadAttachment.createByName(attachment);
29+
updateConnectedGamepads(true);
30+
}, new FlxUIDropDownHeader(150)));
31+
}
32+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"lineEnds": {
3+
"leftCurly": "both"
4+
}
5+
}
6+
7+
---
8+
9+
class PlayState extends FlxState
10+
{
11+
function createAttachmentControls():Void
12+
{
13+
add(attachmentDropDown = new FlxUIDropDownMenu(modelDropDownLoc.x, modelDropDownLoc.y - 30,
14+
FlxUIDropDownMenu.makeStrIdLabelArray(FlxGamepadAttachment.getConstructors()), function(attachment)
15+
{
16+
var gamepad = FlxG.gamepads.lastActive;
17+
if (gamepad != null)
18+
gamepad.attachment = FlxGamepadAttachment.createByName(attachment);
19+
updateConnectedGamepads(true);
20+
}, new FlxUIDropDownHeader(150)));
21+
}
22+
}
23+
24+
---
25+
26+
class PlayState extends FlxState
27+
{
28+
function createAttachmentControls():Void
29+
{
30+
add(attachmentDropDown = new FlxUIDropDownMenu(modelDropDownLoc.x, modelDropDownLoc.y - 30,
31+
FlxUIDropDownMenu.makeStrIdLabelArray(FlxGamepadAttachment.getConstructors()), function(attachment)
32+
{
33+
var gamepad = FlxG.gamepads.lastActive;
34+
if (gamepad != null)
35+
gamepad.attachment = FlxGamepadAttachment.createByName(attachment);
36+
updateConnectedGamepads(true);
37+
}, new FlxUIDropDownHeader(150)));
38+
}
39+
}

0 commit comments

Comments
 (0)