Skip to content

Commit

Permalink
Don't skip indentation in flex groups
Browse files Browse the repository at this point in the history
  • Loading branch information
natefaubion committed Aug 23, 2020
1 parent fb10a49 commit 33fede4
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 16 deletions.
26 changes: 10 additions & 16 deletions src/Dodo.purs
Original file line number Diff line number Diff line change
Expand Up @@ -343,22 +343,16 @@ print (Printer printer) opts = flip go initState <<< pure <<< Doc
{ position { line = state.position.line + 1, column = 0 }
, buffer = Buffer.modify printer.writeBreak state.buffer
}
Indent doc1
| isJust state.flexGroup ->
go (Doc doc1 : stk) state
| otherwise ->
go (Doc doc1 : Dedent state.indentSpaces state.indent : stk) state
{ indent = state.indent + opts.indentWidth
, indentSpaces = state.indentSpaces <> opts.indentUnit
}
Align width doc1
| isJust state.flexGroup ->
go (Doc doc1 : stk) state
| otherwise ->
go (Doc doc1 : Dedent state.indentSpaces state.indent : stk) state
{ indent = state.indent + width
, indentSpaces = state.indentSpaces <> power " " width
}
Indent doc1 ->
go (Doc doc1 : Dedent state.indentSpaces state.indent : stk) state
{ indent = state.indent + opts.indentWidth
, indentSpaces = state.indentSpaces <> opts.indentUnit
}
Align width doc1 ->
go (Doc doc1 : Dedent state.indentSpaces state.indent : stk) state
{ indent = state.indent + width
, indentSpaces = state.indentSpaces <> power " " width
}
FlexGroup doc1
-- We only track the first flex group. This is equivalent to
-- end-of-line lookahead.
Expand Down
8 changes: 8 additions & 0 deletions test/snapshots/DodoFlexGroupIndent.output
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
a b c
a
b
c
a b c
a
b
c
28 changes: 28 additions & 0 deletions test/snapshots/DodoFlexGroupIndent.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module DodoFlexGroupIndent where

import Prelude

import Dodo (Doc, align, flexGroup, fourSpaces, indent, paragraph, plainText, print, text)
import Effect (Effect)
import Effect.Class.Console as Console

test1 :: forall a. Doc a
test1 = flexGroup $ indent $ paragraph
[ text "a"
, text "b"
, text "c"
]

test2 :: forall a. Doc a
test2 = flexGroup $ align 20 $ paragraph
[ text "a"
, text "b"
, text "c"
]

main :: Effect Unit
main = do
Console.log $ print plainText fourSpaces test1
Console.log $ print plainText (fourSpaces { pageWidth = 0 }) test1
Console.log $ print plainText fourSpaces test2
Console.log $ print plainText (fourSpaces { pageWidth = 0 }) test2

0 comments on commit 33fede4

Please sign in to comment.