refactor(ui): replace hardcoded cursor offset with style-based calculation (#2530)
huaiyuWangh
created
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.
@@ -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 {