From 97c9f4b0f555af501fd56f87f5710dbad72cff71 Mon Sep 17 00:00:00 2001 From: huaiyuWangh <34158348+huaiyuWangh@users.noreply.github.com> Date: Wed, 1 Apr 2026 03:26:03 +0800 Subject: [PATCH] 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. --- internal/ui/dialog/api_key_input.go | 7 +------ internal/ui/dialog/common.go | 18 ++++++++++++++++++ internal/ui/dialog/models.go | 7 +------ 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/internal/ui/dialog/api_key_input.go b/internal/ui/dialog/api_key_input.go index cc37d742903d5a80bbcffcf1ff24fb24596dfccd..928cbd411a99aff600991d22d4cf869acefa49ec 100644 --- a/internal/ui/dialog/api_key_input.go +++ b/internal/ui/dialog/api_key_input.go @@ -182,13 +182,8 @@ func (m *APIKeyInput) Draw(scr uv.Screen, area uv.Rectangle) *tea.Cursor { if m.isOnboarding { view := content + cur = adjustOnboardingInputCursor(t, cur) DrawOnboardingCursor(scr, area, view, cur) - - // FIXME(@andreynering): Figure it out how to properly fix this - if cur != nil { - cur.Y -= 1 - cur.X -= 1 - } } else { view := dialogStyle.Render(content) DrawCenterCursor(scr, area, view, cur) diff --git a/internal/ui/dialog/common.go b/internal/ui/dialog/common.go index 339b9033dbf384760f3a1d42facb1823ba5a66ba..e427a6e3b75d7c5e9c2b24d671bd761ad0a5adec 100644 --- a/internal/ui/dialog/common.go +++ b/internal/ui/dialog/common.go @@ -38,6 +38,24 @@ func InputCursor(t *styles.Styles, cur *tea.Cursor) *tea.Cursor { return cur } +// adjustOnboardingInputCursor removes the dialog view frame offset from an +// input cursor. Onboarding dialogs render without Dialog.View frame, while +// InputCursor includes that frame offset for regular dialogs. +func adjustOnboardingInputCursor(t *styles.Styles, cur *tea.Cursor) *tea.Cursor { + if cur == nil { + return nil + } + + dialogStyle := t.Dialog.View + cur.X -= dialogStyle.GetBorderLeftSize() + + dialogStyle.GetPaddingLeft() + + dialogStyle.GetMarginLeft() + cur.Y -= dialogStyle.GetBorderTopSize() + + dialogStyle.GetPaddingTop() + + dialogStyle.GetMarginTop() + return cur +} + // RenderContext is a dialog rendering context that can be used to render // common dialog layouts. type RenderContext struct { diff --git a/internal/ui/dialog/models.go b/internal/ui/dialog/models.go index 434f699e91b4c227c4e54f6ff553affff76a1c43..51a1766cb7a94db942c7957cd82494cc49a46c94 100644 --- a/internal/ui/dialog/models.go +++ b/internal/ui/dialog/models.go @@ -292,13 +292,8 @@ func (m *Models) Draw(scr uv.Screen, area uv.Rectangle) *tea.Cursor { rc.TitleInfo = "" rc.IsOnboarding = true view := rc.Render() + cur = adjustOnboardingInputCursor(t, cur) DrawOnboardingCursor(scr, area, view, cur) - - // FIXME(@andreynering): Figure it out how to properly fix this - if cur != nil { - cur.Y -= 1 - cur.X -= 1 - } } else { view := rc.Render() DrawCenterCursor(scr, area, view, cur)