Skip to content

Commit

Permalink
Fix jumpy content in area caused by wrong cursorPosY
Browse files Browse the repository at this point in the history
  • Loading branch information
lammel committed Jul 27, 2023
1 parent 7738fd3 commit d5f4f59
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
11 changes: 10 additions & 1 deletion area.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cursor

import (
"os"
"strings"
)

// Area displays content which can be updated on the fly.
Expand Down Expand Up @@ -48,6 +49,14 @@ func (area *Area) Clear() {
}
}

// Update overwrites the content of the Area and adjusts its height based on content.
func (area *Area) Update(content string) {
area.Clear()
area.writeArea(content)

Check failure on line 55 in area.go

View workflow job for this annotation

GitHub Actions / Build (windows-latest)

area.writeArea undefined (type *Area has no field or method writeArea)
area.cursorPosY = 0
area.height = strings.Count(content, "\n")

Check warning on line 57 in area.go

View check run for this annotation

Codecov / codecov/patch

area.go#L55-L57

Added lines #L55 - L57 were not covered by tests
}

// Up moves the cursor of the area up one line.
func (area *Area) Up(n int) {
if n > 0 {
Expand Down Expand Up @@ -88,7 +97,7 @@ func (area *Area) Top() {
if area.cursorPosY < area.height {
area.Up(area.height - area.cursorPosY - 1)
area.StartOfLine()
area.cursorPosY = 0
area.cursorPosY = area.height

Check warning on line 100 in area.go

View check run for this annotation

Codecov / codecov/patch

area.go#L97-L100

Added lines #L97 - L100 were not covered by tests
}
}

Expand Down
6 changes: 1 addition & 5 deletions area_other.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,9 @@ package cursor

import (
"fmt"
"strings"
)

// Update overwrites the content of the Area and adjusts its height based on content.
func (area *Area) Update(content string) {
area.Clear()
func (area *Area) writeArea(content string) {
fmt.Fprint(area.writer, content)

Check warning on line 12 in area_other.go

View check run for this annotation

Codecov / codecov/patch

area_other.go#L12

Added line #L12 was not covered by tests
// Detect height of cursor area
area.height = strings.Count(content, "\n")
}

0 comments on commit d5f4f59

Please sign in to comment.