on main help sign in
refactor(ui): replace hardcoded cursor offset with style-based calculation (#2530)

Remove FIXME workaround in onboarding dialogs that used hardcoded cur.Y -= 1 / cur.X -= 1 to adjust cursor position. Extract a new AdjustOnboardingInputCursor helper that computes the correct offset from Dialog.View border/padding/margin, eliminating code duplication between api_key_input.go and models.go.

commit97c9f4b0f555af501fd56f87f5710dbad72cff71 authorhuaiyuWangh <34158348+huaiyuWangh@users.noreply.github.com> dateWed 1 Apr 2026, 03:26 (7 months ago) parentf416931
3 files changed+20−12
internal/ui/dialog/api_key_input.go+1−6 internal/ui/dialog/common.go+18 internal/ui/dialog/models.go+1−6
internal/ui/dialog/api_key_input.go+1−6
@@ -182,13 +182,8 @@ func (m *APIKeyInput) Draw(scr uv.Screen, area uv.Rectangle) *tea.Cursor {
182182
183183 if m.isOnboarding {
184184 view := content
185+ cur = adjustOnboardingInputCursor(t, cur)
185186 DrawOnboardingCursor(scr, area, view, cur)
186−
187− // FIXME(@andreynering): Figure it out how to properly fix this
188− if cur != nil {
189− cur.Y -= 1
190− cur.X -= 1
191− }
192187 } else {
193188 view := dialogStyle.Render(content)
194189 DrawCenterCursor(scr, area, view, cur)
internal/ui/dialog/common.go+18
@@ -38,6 +38,24 @@ func InputCursor(t *styles.Styles, cur *tea.Cursor) *tea.Cursor {
3838 return cur
3939}
4040
41+// adjustOnboardingInputCursor removes the dialog view frame offset from an
42+// input cursor. Onboarding dialogs render without Dialog.View frame, while
43+// InputCursor includes that frame offset for regular dialogs.
44+func adjustOnboardingInputCursor(t *styles.Styles, cur *tea.Cursor) *tea.Cursor {
45+ if cur == nil {
46+ return nil
47+ }
48+
49+ dialogStyle := t.Dialog.View
50+ cur.X -= dialogStyle.GetBorderLeftSize() +
51+ dialogStyle.GetPaddingLeft() +
52+ dialogStyle.GetMarginLeft()
53+ cur.Y -= dialogStyle.GetBorderTopSize() +
54+ dialogStyle.GetPaddingTop() +
55+ dialogStyle.GetMarginTop()
56+ return cur
57+}
58+
4159// RenderContext is a dialog rendering context that can be used to render
4260// common dialog layouts.
4361type RenderContext struct {
internal/ui/dialog/models.go+1−6
@@ -292,13 +292,8 @@ func (m *Models) Draw(scr uv.Screen, area uv.Rectangle) *tea.Cursor {
292292 rc.TitleInfo = ""
293293 rc.IsOnboarding = true
294294 view := rc.Render()
295+ cur = adjustOnboardingInputCursor(t, cur)
295296 DrawOnboardingCursor(scr, area, view, cur)
296−
297− // FIXME(@andreynering): Figure it out how to properly fix this
298− if cur != nil {
299− cur.Y -= 1
300− cur.X -= 1
301− }
302297 } else {
303298 view := rc.Render()
304299 DrawCenterCursor(scr, area, view, cur)