Fix change-header-label+change-header

Fix #4227
This commit is contained in:
Junegunn Choi
2025-02-07 20:56:15 +09:00
parent fcd2baa945
commit 818d0be436
2 changed files with 48 additions and 52 deletions

View File

@@ -5043,34 +5043,52 @@ func (t *Terminal) Loop() error {
} else { } else {
req(reqHeader) req(reqHeader)
} }
case actChangeHeaderLabel: case actChangeHeaderLabel, actTransformHeaderLabel:
t.headerLabelOpts.label = a.a label := a.a
if t.headerBorder != nil { if a.t == actTransformHeaderLabel {
t.headerLabel, t.headerLabelLen = t.ansiLabelPrinter(a.a, &tui.ColHeaderLabel, false) label = t.captureLine(a.a)
req(reqRedrawHeaderLabel)
} }
case actChangeInputLabel: t.headerLabelOpts.label = label
t.inputLabelOpts.label = a.a t.headerLabel, t.headerLabelLen = t.ansiLabelPrinter(label, &tui.ColHeaderLabel, false)
req(reqRedrawHeaderLabel)
case actChangeInputLabel, actTransformInputLabel:
label := a.a
if a.t == actTransformInputLabel {
label = t.captureLine(a.a)
}
t.inputLabelOpts.label = label
if t.inputBorder != nil { if t.inputBorder != nil {
t.inputLabel, t.inputLabelLen = t.ansiLabelPrinter(a.a, &tui.ColInputLabel, false) t.inputLabel, t.inputLabelLen = t.ansiLabelPrinter(label, &tui.ColInputLabel, false)
req(reqRedrawInputLabel) req(reqRedrawInputLabel)
} }
case actChangeListLabel: case actChangeListLabel, actTransformListLabel:
t.listLabelOpts.label = a.a label := a.a
if a.t == actTransformListLabel {
label = t.captureLine(a.a)
}
t.listLabelOpts.label = label
if t.wborder != nil { if t.wborder != nil {
t.listLabel, t.listLabelLen = t.ansiLabelPrinter(a.a, &tui.ColListLabel, false) t.listLabel, t.listLabelLen = t.ansiLabelPrinter(label, &tui.ColListLabel, false)
req(reqRedrawListLabel) req(reqRedrawListLabel)
} }
case actChangeBorderLabel: case actChangeBorderLabel, actTransformBorderLabel:
t.borderLabelOpts.label = a.a label := a.a
if a.t == actTransformBorderLabel {
label = t.captureLine(a.a)
}
t.borderLabelOpts.label = label
if t.border != nil { if t.border != nil {
t.borderLabel, t.borderLabelLen = t.ansiLabelPrinter(a.a, &tui.ColBorderLabel, false) t.borderLabel, t.borderLabelLen = t.ansiLabelPrinter(label, &tui.ColBorderLabel, false)
req(reqRedrawBorderLabel) req(reqRedrawBorderLabel)
} }
case actChangePreviewLabel: case actChangePreviewLabel, actTransformPreviewLabel:
t.previewLabelOpts.label = a.a label := a.a
if a.t == actTransformPreviewLabel {
label = t.captureLine(a.a)
}
t.previewLabelOpts.label = label
if t.pborder != nil { if t.pborder != nil {
t.previewLabel, t.previewLabelLen = t.ansiLabelPrinter(a.a, &tui.ColPreviewLabel, false) t.previewLabel, t.previewLabelLen = t.ansiLabelPrinter(label, &tui.ColPreviewLabel, false)
req(reqRedrawPreviewLabel) req(reqRedrawPreviewLabel)
} }
case actTransform: case actTransform:
@@ -5078,41 +5096,6 @@ func (t *Terminal) Loop() error {
if actions, err := parseSingleActionList(strings.Trim(body, "\r\n")); err == nil { if actions, err := parseSingleActionList(strings.Trim(body, "\r\n")); err == nil {
return doActions(actions) return doActions(actions)
} }
case actTransformHeaderLabel:
label := t.captureLine(a.a)
t.headerLabelOpts.label = label
if t.headerBorder != nil {
t.headerLabel, t.headerLabelLen = t.ansiLabelPrinter(label, &tui.ColHeaderLabel, false)
req(reqRedrawHeaderLabel)
}
case actTransformInputLabel:
label := t.captureLine(a.a)
t.inputLabelOpts.label = label
if t.inputBorder != nil {
t.inputLabel, t.inputLabelLen = t.ansiLabelPrinter(label, &tui.ColInputLabel, false)
req(reqRedrawInputLabel)
}
case actTransformListLabel:
label := t.captureLine(a.a)
t.listLabelOpts.label = label
if t.wborder != nil {
t.listLabel, t.listLabelLen = t.ansiLabelPrinter(label, &tui.ColListLabel, false)
req(reqRedrawListLabel)
}
case actTransformBorderLabel:
label := t.captureLine(a.a)
t.borderLabelOpts.label = label
if t.border != nil {
t.borderLabel, t.borderLabelLen = t.ansiLabelPrinter(label, &tui.ColBorderLabel, false)
req(reqRedrawBorderLabel)
}
case actTransformPreviewLabel:
label := t.captureLine(a.a)
t.previewLabelOpts.label = label
if t.pborder != nil {
t.previewLabel, t.previewLabelLen = t.ansiLabelPrinter(label, &tui.ColPreviewLabel, false)
req(reqRedrawPreviewLabel)
}
case actChangePrompt: case actChangePrompt:
t.promptString = a.a t.promptString = a.a
t.prompt, t.promptLen = t.parsePrompt(a.a) t.prompt, t.promptLen = t.parsePrompt(a.a)

View File

@@ -978,4 +978,17 @@ class TestLayout < TestInteractive
setup setup
end end
end end
def test_change_header_and_label_at_once
tmux.send_keys %(seq 10 | #{FZF} --border sharp --header-border sharp --header-label-pos 3 --bind 'focus:change-header(header)+change-header-label(label)'), :Enter
block = <<~BLOCK
label
header
10/10
>
BLOCK
tmux.until { assert_block(block, it) }
end
end end