Fix login dialog cursor alignment
Some checks failed
ci / test (macos-latest) (push) Has been cancelled
ci / test (ubuntu-latest) (push) Has been cancelled
ci / test (windows-latest) (push) Has been cancelled

This commit is contained in:
patriceckhart 2026-05-31 13:51:13 +02:00
parent 917da8c414
commit ea58887bfa
2 changed files with 30 additions and 1 deletions

View file

@ -490,7 +490,11 @@ func (d *loginDialog) CursorPos(width int) (row, col int) {
wrapW = 20
}
urlLines := len(tui.WrapANSILine(d.url, wrapW))
baseOffset := 1 /*frameHeader*/ + 1 /*hint*/ + urlLines + 1 /*blank*/ + 1 /*prompt*/
// interactive.redraw wraps dialog output with padDialogFrame, which
// injects a blank row after the frame header. Count that row here so
// the real terminal cursor lands on the editor input instead of the
// prompt above it.
baseOffset := 1 /*frameHeader*/ + 1 /*padDialogFrame blank*/ + 1 /*hint*/ + urlLines + 1 /*blank*/ + 1 /*prompt*/
return baseOffset + eRow, eCol
}

View file

@ -0,0 +1,25 @@
package modes
import (
"strings"
"testing"
"github.com/patriceckhart/zot/packages/tui"
)
func TestLoginDialogCursorPosMatchesPaddedInputRow(t *testing.T) {
d := newLoginDialog()
d.Open(t.TempDir())
d.method = "oauth"
d.provider = "anthropic"
d.ShowWaiting("https://example.com/oauth/authorize?code_challenge=abc&state=xyz")
lines := padDialogFrame(d.Render(tui.Theme{}, 80))
row, _ := d.CursorPos(80)
if row < 0 || row >= len(lines) {
t.Fatalf("CursorPos row = %d outside rendered lines %d", row, len(lines))
}
if got := stripANSIBytes(lines[row]); !strings.Contains(got, "▌") {
t.Fatalf("CursorPos row %d = %q; want editor input row", row, got)
}
}