mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-01-04 03:48:07 +02:00
Take removed columns into account when applying column alignments
This commit is contained in:
parent
aa493d3a9e
commit
7a8df7795c
@ -38,7 +38,7 @@ func WithPadding(str string, padding int, alignment Alignment) string {
|
||||
// defaults to left-aligning each column. If you want to set the alignment of
|
||||
// each column, pass in a slice of Alignment values.
|
||||
func RenderDisplayStrings(displayStringsArr [][]string, columnAlignments []Alignment) []string {
|
||||
displayStringsArr = excludeBlankColumns(displayStringsArr)
|
||||
displayStringsArr, columnAlignments = excludeBlankColumns(displayStringsArr, columnAlignments)
|
||||
padWidths := getPadWidths(displayStringsArr)
|
||||
columnConfigs := make([]ColumnConfig, len(padWidths))
|
||||
for i, padWidth := range padWidths {
|
||||
@ -57,9 +57,9 @@ func RenderDisplayStrings(displayStringsArr [][]string, columnAlignments []Align
|
||||
}
|
||||
|
||||
// NOTE: this mutates the input slice for the sake of performance
|
||||
func excludeBlankColumns(displayStringsArr [][]string) [][]string {
|
||||
func excludeBlankColumns(displayStringsArr [][]string, columnAlignments []Alignment) ([][]string, []Alignment) {
|
||||
if len(displayStringsArr) == 0 {
|
||||
return displayStringsArr
|
||||
return displayStringsArr, columnAlignments
|
||||
}
|
||||
|
||||
// if all rows share a blank column, we want to remove that column
|
||||
@ -75,7 +75,7 @@ outer:
|
||||
}
|
||||
|
||||
if len(toRemove) == 0 {
|
||||
return displayStringsArr
|
||||
return displayStringsArr, columnAlignments
|
||||
}
|
||||
|
||||
// remove the columns
|
||||
@ -86,7 +86,13 @@ outer:
|
||||
displayStringsArr[i] = strings
|
||||
}
|
||||
|
||||
return displayStringsArr
|
||||
for j := len(toRemove) - 1; j >= 0; j-- {
|
||||
if columnAlignments != nil && toRemove[j] < len(columnAlignments) {
|
||||
columnAlignments = slices.Delete(columnAlignments, toRemove[j], toRemove[j]+1)
|
||||
}
|
||||
}
|
||||
|
||||
return displayStringsArr, columnAlignments
|
||||
}
|
||||
|
||||
func getPaddedDisplayStrings(stringArrays [][]string, columnConfigs []ColumnConfig) []string {
|
||||
|
@ -212,10 +212,7 @@ func TestRenderDisplayStrings(t *testing.T) {
|
||||
{
|
||||
input: [][]string{{"a", "", "bcd", "efg", "h"}, {"i", "", "j", "k", "l"}},
|
||||
columnAlignments: []Alignment{AlignLeft, AlignLeft, AlignRight, AlignLeft},
|
||||
expected: "a bcd efg h\ni j k l",
|
||||
/* Wrong, it should really be:
|
||||
expected: "a bcd efg h\ni j k l",
|
||||
*/
|
||||
},
|
||||
{
|
||||
input: [][]string{{"abc", "", "d", ""}, {"e", "", "f", ""}},
|
||||
|
Loading…
Reference in New Issue
Block a user