fix: finish profile editor preview scrolling
This commit is contained in:
@@ -27,7 +27,7 @@ type formState struct {
|
||||
profile profile.Profile
|
||||
inputs []formInput
|
||||
field int
|
||||
viewportOffset int
|
||||
bypassPreviewLine int
|
||||
validation profile.Validation
|
||||
advancedInitialized bool
|
||||
probing bool
|
||||
@@ -48,7 +48,7 @@ func newFormState(originalName string, value profile.Profile) formState {
|
||||
}
|
||||
|
||||
func (f *formState) rebuildInputs(focus int) tea.Cmd {
|
||||
f.viewportOffset = 0
|
||||
f.bypassPreviewLine = 0
|
||||
definitions := []formDefinition{{"Name", profile.NameField, f.profile.Name}}
|
||||
if f.profile.Mode == profile.AdvancedMode {
|
||||
definitions = append(definitions,
|
||||
@@ -95,7 +95,7 @@ func (f *formState) move(delta int) tea.Cmd {
|
||||
}
|
||||
f.inputs[f.field].input.Blur()
|
||||
f.field = (f.field + delta + len(f.inputs)) % len(f.inputs)
|
||||
f.viewportOffset = 0
|
||||
f.bypassPreviewLine = 0
|
||||
return f.inputs[f.field].input.Focus()
|
||||
}
|
||||
|
||||
@@ -124,7 +124,7 @@ func (f *formState) updateInput(key tea.KeyMsg) tea.Cmd {
|
||||
commands = append(commands, command)
|
||||
}
|
||||
if f.inputs[f.field].input.Value() != previous {
|
||||
f.viewportOffset = 0
|
||||
f.bypassPreviewLine = 0
|
||||
f.syncFocusedValue()
|
||||
f.refreshValidation()
|
||||
}
|
||||
@@ -181,6 +181,17 @@ func (f formState) currentField() profile.Field {
|
||||
return f.inputs[f.field].field
|
||||
}
|
||||
|
||||
func (f *formState) scrollBypassPreview(delta int) {
|
||||
if f.currentField() != profile.BypassField {
|
||||
return
|
||||
}
|
||||
// Line zero is the preview heading; each following line represents one
|
||||
// normalized or invalid validation item. Anchoring the viewport to that
|
||||
// item keeps Page navigation stable across terminal resizes.
|
||||
maximum := len(f.bypassAnalysis())
|
||||
f.bypassPreviewLine = min(maximum, max(0, f.bypassPreviewLine+delta))
|
||||
}
|
||||
|
||||
func (f formState) renderedInput(index, width int) string {
|
||||
if index < 0 || index >= len(f.inputs) {
|
||||
return ""
|
||||
|
||||
Reference in New Issue
Block a user