summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHubert Hirtz <hubert@hirtzfr.eu>2020-06-13 11:34:50 +0200
committerHubert Hirtz <hubert@hirtzfr.eu>2020-06-13 11:34:50 +0200
commita4fd300c0c70d67c72e5d6d7855691ea41fffefa (patch)
treeb769e1619749d3f1c2857419f749c7454885ae9f
parentwip (diff)
Make renderedHeight correct
Diffstat (limited to '')
-rw-r--r--ui/buffers.go27
-rw-r--r--ui/buffers_test.go2
2 files changed, 24 insertions, 5 deletions
diff --git a/ui/buffers.go b/ui/buffers.go
index c717691..0141a04 100644
--- a/ui/buffers.go
+++ b/ui/buffers.go
@@ -63,12 +63,13 @@ func (line *Line) RenderedHeight(screenWidth int) (height int) {
return
}
+// TODO clean and understand the fucking function
func (line *Line) computeRenderedHeight(screenWidth int) {
var lastSP Point
line.renderedHeight = 1
x := 0
- fmt.Printf("\n%d %q\n", screenWidth, line.Content)
+ //fmt.Printf("\n%d %q\n", screenWidth, line.Content)
for _, sp := range line.SplitPoints {
l := sp.X - lastSP.X
@@ -77,16 +78,34 @@ func (line *Line) computeRenderedHeight(screenWidth int) {
} else if screenWidth < l {
line.renderedHeight += (x + l) / screenWidth
x = (x + l) % screenWidth
+ } else if screenWidth == l {
+ if x == 0 {
+ line.renderedHeight++
+ } else {
+ line.renderedHeight += 2
+ x = 0
+ }
} else if screenWidth < x+l {
line.renderedHeight++
- x = l % screenWidth
+ if sp.Split {
+ x = l % screenWidth
+ } else {
+ x = 0
+ }
+ } else if screenWidth == x+l {
+ line.renderedHeight++
+ x = 0
} else {
- x = (x + l) % screenWidth
+ x = x + l
}
- fmt.Printf("%d %d %t occupied by %q\n", line.renderedHeight, x, sp.Split, line.Content[:sp.I])
+ //fmt.Printf("%d %d %t occupied by %q\n", line.renderedHeight, x, sp.Split, line.Content[:sp.I])
lastSP = sp
}
+
+ if x == 0 && 1 < line.renderedHeight {
+ line.renderedHeight--
+ }
}
func (line *Line) computeSplitPoints() {
diff --git a/ui/buffers_test.go b/ui/buffers_test.go
index ca71864..e499203 100644
--- a/ui/buffers_test.go
+++ b/ui/buffers_test.go
@@ -104,7 +104,7 @@ func TestRenderedHeight(t *testing.T) {
assertRenderedHeight(t, "have a good day!", 2, 7) // |ha|ve|a |go|od|da|y!|
assertRenderedHeight(t, "have a good day!", 3, 5) // |hav|e a|goo|d d|ay!|
assertRenderedHeight(t, "have a good day!", 4, 4) // |have|a |good|day!|
- assertRenderedHeight(t, "have a good day!", 5, 3) // |have |a good|day! |
+ assertRenderedHeight(t, "have a good day!", 5, 4) // |have |a |good |day! |
assertRenderedHeight(t, "have a good day!", 6, 3) // |have a|good |day! |
assertRenderedHeight(t, "have a good day!", 7, 3) // |have a |good |day! |
assertRenderedHeight(t, "have a good day!", 8, 3) // |have a |good |day! |