on main help sign in
refactor(ui): replace hardcoded cursor offset with style-based calculation (#2530)
97c9f4bhuaiyuWangh
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 {
182
182
183 if m.isOnboarding {
183 if m.isOnboarding {
184 view := content
184 view := content
185+ cur = adjustOnboardingInputCursor(t, cur)
185 DrawOnboardingCursor(scr, area, view, cur)
186 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− }
192 } else {
187 } else {
193 view := dialogStyle.Render(content)
188 view := dialogStyle.Render(content)
194 DrawCenterCursor(scr, area, view, cur)
189 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 {
38 return cur
38 return cur
39}
39}
40
40
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+
41// RenderContext is a dialog rendering context that can be used to render
59// RenderContext is a dialog rendering context that can be used to render
42// common dialog layouts.
60// common dialog layouts.
43type RenderContext struct {
61type 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 {
292 rc.TitleInfo = ""
292 rc.TitleInfo = ""
293 rc.IsOnboarding = true
293 rc.IsOnboarding = true
294 view := rc.Render()
294 view := rc.Render()
295+ cur = adjustOnboardingInputCursor(t, cur)
295 DrawOnboardingCursor(scr, area, view, cur)
296 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− }
302 } else {
297 } else {
303 view := rc.Render()
298 view := rc.Render()
304 DrawCenterCursor(scr, area, view, cur)
299 DrawCenterCursor(scr, area, view, cur)