on main help sign in
fix(tui): make permissions dialog height responsive to resize (#877)
7b4cb40James Trew
internal/tui/components/dialogs/permissions/permissions.go+6−7
@@ -698,15 +698,14 @@ func (p *permissionDialogCmp) render() string {
698
698
699 p.contentViewPort.SetWidth(p.width - 4)
699 p.contentViewPort.SetWidth(p.width - 4)
700
700
701− // Get cached or generate content
702− contentFinal := p.getOrGenerateContent()
703−
704 // Always set viewport content (the caching is handled in getOrGenerateContent)
701 // Always set viewport content (the caching is handled in getOrGenerateContent)
705 const minContentHeight = 9
702 const minContentHeight = 9
706− contentHeight := min(
703+
707− max(minContentHeight, p.height-minContentHeight),
704+ availableDialogHeight := max(minContentHeight, p.height-minContentHeight)
705+ p.contentViewPort.SetHeight(availableDialogHeight)
706+ contentFinal := p.getOrGenerateContent()
708− lipgloss.Height(contentFinal),
707+ contentHeight := min(availableDialogHeight, lipgloss.Height(contentFinal))
709− )
708+
710 p.contentViewPort.SetHeight(contentHeight)
709 p.contentViewPort.SetHeight(contentHeight)
711 p.contentViewPort.SetContent(contentFinal)
710 p.contentViewPort.SetContent(contentFinal)
712
711
internal/tui/exp/diffview/diffview.go−29
@@ -500,19 +500,6 @@ outer:
500 }
500 }
501 }
501 }
502
502
503− for printedLines < dv.height {
504− if shouldWrite() {
505− ls := dv.style.MissingLine
506− if dv.lineNumbers {
507− b.WriteString(ls.LineNumber.Render(pad(" ", dv.beforeNumDigits)))
508− b.WriteString(ls.LineNumber.Render(pad(" ", dv.afterNumDigits)))
509− }
510− b.WriteString(ls.Code.Width(dv.fullCodeWidth).Render(" "))
511− b.WriteRune('\n')
512− }
513− printedLines++
514− }
515−
516 return b.String()
503 return b.String()
517}
504}
518
505
@@ -670,22 +657,6 @@ outer:
670 }
657 }
671 }
658 }
672
659
673− for printedLines < dv.height {
674− if shouldWrite() {
675− ls := dv.style.MissingLine
676− if dv.lineNumbers {
677− b.WriteString(ls.LineNumber.Render(pad(" ", dv.beforeNumDigits)))
678− }
679− b.WriteString(ls.Code.Width(dv.fullCodeWidth).Render(" "))
680− if dv.lineNumbers {
681− b.WriteString(ls.LineNumber.Render(pad(" ", dv.afterNumDigits)))
682− }
683− b.WriteString(ls.Code.Width(dv.fullCodeWidth + btoi(dv.extraColOnAfter)).Render(" "))
684− b.WriteRune('\n')
685− }
686− printedLines++
687− }
688−
689 return b.String()
660 return b.String()
690}
661}
691
662
internal/tui/exp/diffview/diffview_test.go−6
@@ -249,8 +249,6 @@ func TestDiffViewHeight(t *testing.T) {
249
249
250 output := dv.String()
250 output := dv.String()
251 golden.RequireEqual(t, []byte(output))
251 golden.RequireEqual(t, []byte(output))
252−
253− assertHeight(t, height, output)
254 })
252 })
255 }
253 }
256 })
254 })
@@ -301,8 +299,6 @@ func TestDiffViewYOffset(t *testing.T) {
301
299
302 output := dv.String()
300 output := dv.String()
303 golden.RequireEqual(t, []byte(output))
301 golden.RequireEqual(t, []byte(output))
304−
305− assertHeight(t, 5, output)
306 })
302 })
307 }
303 }
308 })
304 })
@@ -328,8 +324,6 @@ func TestDiffViewYOffsetInfinite(t *testing.T) {
328
324
329 output := dv.String()
325 output := dv.String()
330 golden.RequireEqual(t, []byte(output))
326 golden.RequireEqual(t, []byte(output))
331−
332− assertHeight(t, 5, output)
333 })
327 })
334 }
328 }
335 })
329 })
internal/tui/exp/diffview/testdata/TestDiffViewHeight/Split/HeightOf016.golden+1−2
@@ -12,5 +12,4 @@
12 11  func getContent() string {  12  func getContent() string { 
12 11  func getContent() string {  12  func getContent() string { 
13 12 -  return "Hello, world!"  13 +  content := strings.ToUpper("Hello, World!") 
13 12 -  return "Hello, world!"  13 +  content := strings.ToUpper("Hello, World!") 
14      14 +  return content 
14      14 +  return content 
15− 13  }  15  } 
15+ 13  }  15  } 
16−          
internal/tui/exp/diffview/testdata/TestDiffViewHeight/Split/HeightOf017.golden+1−3
@@ -12,6 +12,4 @@
12 11  func getContent() string {  12  func getContent() string { 
12 11  func getContent() string {  12  func getContent() string { 
13 12 -  return "Hello, world!"  13 +  content := strings.ToUpper("Hello, World!") 
13 12 -  return "Hello, world!"  13 +  content := strings.ToUpper("Hello, World!") 
14      14 +  return content 
14      14 +  return content 
15− 13  }  15  } 
15+ 13  }  15  } 
16−          
17−          
internal/tui/exp/diffview/testdata/TestDiffViewHeight/Split/HeightOf018.golden+1−4
@@ -12,7 +12,4 @@
12 11  func getContent() string {  12  func getContent() string { 
12 11  func getContent() string {  12  func getContent() string { 
13 12 -  return "Hello, world!"  13 +  content := strings.ToUpper("Hello, World!") 
13 12 -  return "Hello, world!"  13 +  content := strings.ToUpper("Hello, World!") 
14      14 +  return content 
14      14 +  return content 
15− 13  }  15  } 
15+ 13  }  15  } 
16−          
17−          
18−          
internal/tui/exp/diffview/testdata/TestDiffViewHeight/Split/HeightOf019.golden+1−5
@@ -12,8 +12,4 @@
12 11  func getContent() string {  12  func getContent() string { 
12 11  func getContent() string {  12  func getContent() string { 
13 12 -  return "Hello, world!"  13 +  content := strings.ToUpper("Hello, World!") 
13 12 -  return "Hello, world!"  13 +  content := strings.ToUpper("Hello, World!") 
14      14 +  return content 
14      14 +  return content 
15− 13  }  15  } 
15+ 13  }  15  } 
16−          
17−          
18−          
19−          
internal/tui/exp/diffview/testdata/TestDiffViewHeight/Split/HeightOf020.golden+1−6
@@ -12,9 +12,4 @@
12 11  func getContent() string {  12  func getContent() string { 
12 11  func getContent() string {  12  func getContent() string { 
13 12 -  return "Hello, world!"  13 +  content := strings.ToUpper("Hello, World!") 
13 12 -  return "Hello, world!"  13 +  content := strings.ToUpper("Hello, World!") 
14      14 +  return content 
14      14 +  return content 
15− 13  }  15  } 
15+ 13  }  15  } 
16−          
17−          
18−          
19−          
20−          
internal/tui/exp/diffview/testdata/TestDiffViewHeight/Unified/HeightOf017.golden+1−2
@@ -13,5 +13,4 @@
13 12    -  return "Hello, world!" 
13 12    -  return "Hello, world!" 
14    13 +  content := strings.ToUpper("Hello, World!") 
14    13 +  content := strings.ToUpper("Hello, World!") 
15    14 +  return content 
15    14 +  return content 
16− 13  15  } 
16+ 13  15  } 
17−        
internal/tui/exp/diffview/testdata/TestDiffViewHeight/Unified/HeightOf018.golden+1−3
@@ -13,6 +13,4 @@
13 12    -  return "Hello, world!" 
13 12    -  return "Hello, world!" 
14    13 +  content := strings.ToUpper("Hello, World!") 
14    13 +  content := strings.ToUpper("Hello, World!") 
15    14 +  return content 
15    14 +  return content 
16− 13  15  } 
16+ 13  15  } 
17−        
18−        
internal/tui/exp/diffview/testdata/TestDiffViewHeight/Unified/HeightOf019.golden+1−4
@@ -13,7 +13,4 @@
13 12    -  return "Hello, world!" 
13 12    -  return "Hello, world!" 
14    13 +  content := strings.ToUpper("Hello, World!") 
14    13 +  content := strings.ToUpper("Hello, World!") 
15    14 +  return content 
15    14 +  return content 
16− 13  15  } 
16+ 13  15  } 
17−        
18−        
19−        
internal/tui/exp/diffview/testdata/TestDiffViewHeight/Unified/HeightOf020.golden+1−5
@@ -13,8 +13,4 @@
13 12    -  return "Hello, world!" 
13 12    -  return "Hello, world!" 
14    13 +  content := strings.ToUpper("Hello, World!") 
14    13 +  content := strings.ToUpper("Hello, World!") 
15    14 +  return content 
15    14 +  return content 
16− 13  15  } 
16+ 13  15  } 
17−        
18−        
19−        
20−        
internal/tui/exp/diffview/testdata/TestDiffViewYOffsetInfinite/Split/YOffsetOf11.golden+1−2
@@ -1,5 +1,4 @@
1 11  func getContent() string {  12  func getContent() string { 
1 11  func getContent() string {  12  func getContent() string { 
2 12 -  return "Hello, world!"  13 +  content := strings.ToUpper("Hello, World!") 
2 12 -  return "Hello, world!"  13 +  content := strings.ToUpper("Hello, World!") 
3      14 +  return content 
3      14 +  return content 
4− 13  }  15  } 
4+ 13  }  15  } 
5−          
internal/tui/exp/diffview/testdata/TestDiffViewYOffsetInfinite/Split/YOffsetOf12.golden+1−3
@@ -1,5 +1,3 @@
1 12 -  return "Hello, world!"  13 +  content := strings.ToUpper("Hello, World!") 
1 12 -  return "Hello, world!"  13 +  content := strings.ToUpper("Hello, World!") 
2      14 +  return content 
2      14 +  return content 
3− 13  }  15  } 
3+ 13  }  15  } 
4−          
5−          
internal/tui/exp/diffview/testdata/TestDiffViewYOffsetInfinite/Split/YOffsetOf13.golden+1−4
@@ -1,5 +1,2 @@
1      14 +  return content 
1      14 +  return content 
2− 13  }  15  } 
2+ 13  }  15  } 
3−          
4−          
5−          
internal/tui/exp/diffview/testdata/TestDiffViewYOffsetInfinite/Split/YOffsetOf14.golden+1−5
@@ -1,5 +1 @@
1− 13  }  15  } 
1+ 13  }  15  } 
2−          
3−          
4−          
5−          
internal/tui/exp/diffview/testdata/TestDiffViewYOffsetInfinite/Split/YOffsetOf15.golden−5
@@ -1,5 +0,0 @@
1−          
2−          
3−          
4−          
5−          
internal/tui/exp/diffview/testdata/TestDiffViewYOffsetInfinite/Split/YOffsetOf16.golden−5
@@ -1,5 +0,0 @@
1−          
2−          
3−          
4−          
5−          
internal/tui/exp/diffview/testdata/TestDiffViewYOffsetInfinite/Unified/YOffsetOf12.golden+1−2
@@ -1,5 +1,4 @@
1 12    -  return "Hello, world!" 
1 12    -  return "Hello, world!" 
2    13 +  content := strings.ToUpper("Hello, World!") 
2    13 +  content := strings.ToUpper("Hello, World!") 
3    14 +  return content 
3    14 +  return content 
4− 13  15  } 
4+ 13  15  } 
5−        
internal/tui/exp/diffview/testdata/TestDiffViewYOffsetInfinite/Unified/YOffsetOf13.golden+1−3
@@ -1,5 +1,3 @@
1    13 +  content := strings.ToUpper("Hello, World!") 
1    13 +  content := strings.ToUpper("Hello, World!") 
2    14 +  return content 
2    14 +  return content 
3− 13  15  } 
3+ 13  15  } 
4−        
5−        
internal/tui/exp/diffview/testdata/TestDiffViewYOffsetInfinite/Unified/YOffsetOf14.golden+1−4
@@ -1,5 +1,2 @@
1    14 +  return content 
1    14 +  return content 
2− 13  15  } 
2+ 13  15  } 
3−        
4−        
5−        
internal/tui/exp/diffview/testdata/TestDiffViewYOffsetInfinite/Unified/YOffsetOf15.golden+1−5
@@ -1,5 +1 @@
1− 13  15  } 
1+ 13  15  } 
2−        
3−        
4−        
5−        
internal/tui/exp/diffview/testdata/TestDiffViewYOffsetInfinite/Unified/YOffsetOf16.golden−5
@@ -1,5 +0,0 @@
1−        
2−        
3−        
4−        
5−