Skip to content

Commit

Permalink
Fix indent position calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
natefaubion committed Aug 22, 2020
1 parent ea2b4bd commit 1aa759d
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/Dodo.purs
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,11 @@ print (Printer printer) opts = flip go initState <<< pure <<< Doc
Text len str
| state.position.column == 0 && state.indent > 0 ->
go stack state
{ position { column = state.indent }
{ position
{ column = state.indent
, indent = state.indent
, ribbonWidth = calcRibbonWidth (opts.pageWidth - state.indent)
}
, buffer = Buffer.modify (printer.writeIndent state.indent state.indentSpaces) state.buffer
}
| otherwise -> do
Expand Down Expand Up @@ -375,7 +379,7 @@ print (Printer printer) opts = flip go initState <<< pure <<< Doc
| otherwise ->
go (Doc doc1 : stk) state
WithPosition k
| state.position.column == 0 && state.indent > 0 -> do
| state.position.column == 0 && state.indent > state.position.indent -> do
let
renderPosition = state.position
{ column = state.indent
Expand Down
28 changes: 28 additions & 0 deletions test/snapshots/DodoRibbonRatio.output
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Quisque finibus tellus non molestie porta. In non posuere metus, vitae tincidunt
enim. Nam quis elit pharetra, elementum elit lacinia, efficitur nibh. Cras
lobortis neque sed ante ornare rutrum. Maecenas sed urna nisl. Phasellus aliquam
finibus ex vitae iaculis. Vestibulum ante ipsum primis in faucibus orci luctus
et ultrices posuere cubilia curae; Suspendisse eget tortor eget sapien tincidunt
vestibulum eu a velit. Pellentesque eu tortor ut lectus sodales ornare.
Quisque finibus tellus non molestie porta. In non posuere metus, vitae
tincidunt enim. Nam quis elit pharetra, elementum elit lacinia, efficitur
nibh. Cras lobortis neque sed ante ornare rutrum. Maecenas sed urna nisl.
Phasellus aliquam finibus ex vitae iaculis. Vestibulum ante ipsum primis in
faucibus orci luctus et ultrices posuere cubilia curae; Suspendisse eget
tortor eget sapien tincidunt vestibulum eu a velit. Pellentesque eu tortor
ut lectus sodales ornare.
Quisque finibus tellus non molestie porta. In non posuere metus, vitae
tincidunt enim. Nam quis elit pharetra, elementum elit lacinia,
efficitur nibh. Cras lobortis neque sed ante ornare rutrum. Maecenas sed
urna nisl. Phasellus aliquam finibus ex vitae iaculis. Vestibulum ante
ipsum primis in faucibus orci luctus et ultrices posuere cubilia curae;
Suspendisse eget tortor eget sapien tincidunt vestibulum eu a velit.
Pellentesque eu tortor ut lectus sodales ornare.
Quisque finibus tellus non molestie porta. In non posuere metus,
vitae tincidunt enim. Nam quis elit pharetra, elementum elit
lacinia, efficitur nibh. Cras lobortis neque sed ante ornare rutrum.
Maecenas sed urna nisl. Phasellus aliquam finibus ex vitae iaculis.
Vestibulum ante ipsum primis in faucibus orci luctus et ultrices
posuere cubilia curae; Suspendisse eget tortor eget sapien tincidunt
vestibulum eu a velit. Pellentesque eu tortor ut lectus sodales
ornare.
30 changes: 30 additions & 0 deletions test/snapshots/DodoRibbonRatio.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
module DodoRibbonRatio where

import Prelude

import Dodo (Doc, fourSpaces, indent, lines, plainText, print, textParagraph)
import Effect (Effect)
import Effect.Class.Console as Console

test :: forall a. Doc a
test = lines
[ latin
, indent $ indent latin
, indent $ indent $ indent $ indent latin
, indent $ indent $ indent $ indent $ indent $ indent latin
]
where
latin = textParagraph
"""
Quisque finibus tellus non molestie porta. In non posuere metus, vitae
tincidunt enim. Nam quis elit pharetra, elementum elit lacinia, efficitur
nibh. Cras lobortis neque sed ante ornare rutrum. Maecenas sed urna nisl.
Phasellus aliquam finibus ex vitae iaculis. Vestibulum ante ipsum primis
in faucibus orci luctus et ultrices posuere cubilia curae; Suspendisse
eget tortor eget sapien tincidunt vestibulum eu a velit. Pellentesque eu
tortor ut lectus sodales ornare.
"""

main :: Effect Unit
main = do
Console.log $ print plainText (fourSpaces { pageWidth = 160, ribbonRatio = 0.5 }) test

0 comments on commit 1aa759d

Please sign in to comment.