Skip to content

Commit

Permalink
fix: cursor location on long lines
Browse files Browse the repository at this point in the history
  • Loading branch information
cfoust committed Dec 1, 2024
1 parent b4570c2 commit ce16c4b
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/emu/wrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ findNew:
isLast := false

for col := 0; col < numChars; col++ {
newCursor.location.C = line.C0 + col
newCursor.location.C = newOffset
newCursor.cursor.C = col

// The cursor is within the line (not at the end)
Expand Down
45 changes: 45 additions & 0 deletions pkg/emu/wrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,51 @@ func TestTranslateCursor(t *testing.T) {
Cursor{Vec2: geom.Vec2{R: 2, C: 1}, State: cursorWrapNext},
"foobar",
)

// Correct location across lines
{
term := New()
term.Resize(geom.Size{R: 3, C: 5})
term.Write([]byte(LineFeedMode))
term.Write([]byte("fooba"))
term.Write([]byte("rbaz"))

cursor := term.Cursor()
require.Equal(t, geom.Vec2{R: 1, C: 4}, cursor.Vec2)

lines := term.Screen()

physical := []physicalLine{
{
{R: 0, C0: 0, C1: 5},
{R: 1, C0: 0, C1: 4},
},
{
{R: 2, C0: 0, C1: 0},
},
}

newCursor := translateCursor(
lines, lines,
physical, physical,
cursor,
5,
)
require.True(
t,
newCursor.isEnd,
)
require.Equal(
t,
geom.Vec2{R: 1, C: 4},
newCursor.cursor.Vec2,
)
require.Equal(
t,
geom.Vec2{R: 0, C: 8},
newCursor.location,
)
}
}

// Double-width characters cannot occupy the last column in a row. Instead, we
Expand Down

0 comments on commit ce16c4b

Please sign in to comment.