Fix panic caused by incorrect update ordering
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Fix #4442 Make sure to prepare windows before rendering elements. Thanks to @nugged for the report.
authored by Junegunn Choi · committed by Junegunn Choi · parent ce95adc · Browse files · 2 files·+48 added−33 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+48 added−33 removed
- tests:+7 added−0 removed
- other:+41 added−33 removed
Provenance
- Commit
d34675d- Tree
68630d4- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
Junegunn Choi <junegunn.c@gmail.com>- Parent
ce95adc
2 files changed+48 added−33 removed
modified:src/terminal.go+41 added-33 removed
448 unmodified lines449 func (a byTimeOrder) Less(i, j int) bool {450 return a[i].at.Before(a[j].at)451 }452 453+// EventTypes are listed in the order of their priority.454 const (454- reqPrompt util.EventType = iota455+ reqResize util.EventType = iota456+ reqReinit457+ reqFullRedraw458+ reqRedraw459+460+ reqJump461+ reqPrompt462 reqInfo463 reqHeader464 reqFooter465 reqList459- reqJump460- reqActivate461- reqReinit462- reqFullRedraw463- reqResize464- reqRedraw466 reqRedrawInputLabel467 reqRedrawHeaderLabel468 reqRedrawFooterLabel469 reqRedrawListLabel470 reqRedrawBorderLabel471 reqRedrawPreviewLabel471- reqClose472- reqPrintQuery472+473 reqPreviewReady474 reqPreviewEnqueue475 reqPreviewDisplay476 reqPreviewRefresh477 reqPreviewDelayed478+479+ reqActivate480+ reqClose481+ reqPrintQuery482 reqBecome483 reqQuit484 reqFatal485 )1141 unmodified lines1627 t.clickHeaderColumn = 01628 return needFullRedraw1629 }1630 1627-func (t *Terminal) changeFooter(footer string) bool {1631+func (t *Terminal) changeFooter(footer string) {1632 var lines []string1633 if len(footer) > 0 {1634 lines = strings.Split(strings.TrimSuffix(footer, "\n"), "\n")1635 }1632- needFullRedraw := len(t.footer) != len(lines)1636 t.footer = lines1634- return needFullRedraw1637 }1638 1639 // UpdateHeader updates the header1640 func (t *Terminal) UpdateHeader(header []string) {1249 unmodified lines2890 t.printAll()2891 return true2892 }2893 2894+ // Check footer window2895+ if len(t.footer) > 0 && (t.footerWindow == nil || t.footerWindow.Height() != len(t.footer)) ||2896+ len(t.footer) == 0 && t.footerWindow != nil {2897+ t.printAll()2898+ return true2899+ }2900+2901 // Check if the header borders are used and header has changed2902 allHeaderLines := t.visibleHeaderLines()2903 primaryHeaderLines := allHeaderLines2904 if t.hasHeaderLinesWindow() {2219 unmodified lines5124 // U t.uiMutex |5125 t.uiMutex.Lock()5126 t.mutex.Lock()5127 info := false5128+ header := false5129+ footer := false5130 for _, key := range keys {5131 req := util.EventType(key)5132 value := (*events)[req]5133 switch req {29 unmodified lines5163 t.jumping = jumpDisabled5164 }5165 t.printList()5166 case reqHeader:5156- if !t.resizeIfNeeded() {5157- t.printHeader()5158- }5167+ header = true5168 case reqFooter:5160- if !t.resizeIfNeeded() {5161- t.printFooter()5162- }5169+ footer = true5170 case reqActivate:5171 t.suppress = false5172 if t.hasPreviewer() {5173 t.previewBox.Set(reqPreviewReady, nil)75 unmodified lines5249 exit(func() int { return ExitError })5250 return5251 }5252 }5246- if info && !t.resizeIfNeeded() {5247- t.printInfo()5253+ if (info || header || footer) && !t.resizeIfNeeded() {5254+ if info {5255+ t.printInfo()5256+ }5257+ if header {5258+ t.printHeader()5259+ }5260+ if footer {5261+ t.printFooter()5262+ }5263 }5264 t.flush()5265 t.mutex.Unlock()5266 t.uiMutex.Unlock()417 unmodified lines5684 t.input = []rune(a.a)5685 t.cx = len(t.input)5686 case actChangeHeader, actTransformHeader, actBgTransformHeader:5687 capture(false, func(header string) {5688+ // When a dedicated header window is not used, we may need to5689+ // update other elements as well.5690 if t.changeHeader(header) {5674- if t.headerWindow != nil {5675- // Need to resize header window5676- req(reqRedraw)5677- } else {5678- req(reqHeader, reqList, reqPrompt, reqInfo)5691+ req(reqList, reqPrompt, reqInfo)5679- }5680- } else {5681- req(reqHeader)5692 }5693+ req(reqHeader)5694 })5695 case actChangeFooter, actTransformFooter, actBgTransformFooter:5696 capture(false, func(footer string) {5686- if t.changeFooter(footer) {5687- req(reqRedraw)5688- } else {5689- req(reqFooter)5690- }5697+ t.changeFooter(footer)5698+ req(reqFooter)5699 })5700 case actChangeHeaderLabel, actTransformHeaderLabel, actBgTransformHeaderLabel:5701 capture(true, func(label string) {5702 t.headerLabelOpts.label = label1219 unmodified linesmodified:test/test_core.rb+7 added
1979 unmodified lines1980 assert lines.any_include?('[0]')1981 refute lines.any_include?('[1]')1982 end1983 end1984+1985+ def test_render_order1986+ tmux.send_keys %(seq 100 | #{FZF} --bind='focus:preview(echo boom)+change-footer(bam)'), :Enter1987+ tmux.until { assert_equal 100, it.match_count }1988+ tmux.until { assert it.any_include?('boom') }1989+ tmux.until { assert it.any_include?('bam') }1990+ end1991 end