Skip to content

Commit 33fede4

Browse files
committed
Don't skip indentation in flex groups
1 parent fb10a49 commit 33fede4

File tree

3 files changed

+46
-16
lines changed

3 files changed

+46
-16
lines changed

src/Dodo.purs

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -343,22 +343,16 @@ print (Printer printer) opts = flip go initState <<< pure <<< Doc
343343
{ position { line = state.position.line + 1, column = 0 }
344344
, buffer = Buffer.modify printer.writeBreak state.buffer
345345
}
346-
Indent doc1
347-
| isJust state.flexGroup ->
348-
go (Doc doc1 : stk) state
349-
| otherwise ->
350-
go (Doc doc1 : Dedent state.indentSpaces state.indent : stk) state
351-
{ indent = state.indent + opts.indentWidth
352-
, indentSpaces = state.indentSpaces <> opts.indentUnit
353-
}
354-
Align width doc1
355-
| isJust state.flexGroup ->
356-
go (Doc doc1 : stk) state
357-
| otherwise ->
358-
go (Doc doc1 : Dedent state.indentSpaces state.indent : stk) state
359-
{ indent = state.indent + width
360-
, indentSpaces = state.indentSpaces <> power " " width
361-
}
346+
Indent doc1 ->
347+
go (Doc doc1 : Dedent state.indentSpaces state.indent : stk) state
348+
{ indent = state.indent + opts.indentWidth
349+
, indentSpaces = state.indentSpaces <> opts.indentUnit
350+
}
351+
Align width doc1 ->
352+
go (Doc doc1 : Dedent state.indentSpaces state.indent : stk) state
353+
{ indent = state.indent + width
354+
, indentSpaces = state.indentSpaces <> power " " width
355+
}
362356
FlexGroup doc1
363357
-- We only track the first flex group. This is equivalent to
364358
-- end-of-line lookahead.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
a b c
2+
a
3+
b
4+
c
5+
a b c
6+
a
7+
b
8+
c
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
module DodoFlexGroupIndent where
2+
3+
import Prelude
4+
5+
import Dodo (Doc, align, flexGroup, fourSpaces, indent, paragraph, plainText, print, text)
6+
import Effect (Effect)
7+
import Effect.Class.Console as Console
8+
9+
test1 :: forall a. Doc a
10+
test1 = flexGroup $ indent $ paragraph
11+
[ text "a"
12+
, text "b"
13+
, text "c"
14+
]
15+
16+
test2 :: forall a. Doc a
17+
test2 = flexGroup $ align 20 $ paragraph
18+
[ text "a"
19+
, text "b"
20+
, text "c"
21+
]
22+
23+
main :: Effect Unit
24+
main = do
25+
Console.log $ print plainText fourSpaces test1
26+
Console.log $ print plainText (fourSpaces { pageWidth = 0 }) test1
27+
Console.log $ print plainText fourSpaces test2
28+
Console.log $ print plainText (fourSpaces { pageWidth = 0 }) test2

0 commit comments

Comments
 (0)