1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-08-06 11:02:41 +03:00

Add a tabWidth parameter to WrapViewLinesToWidth to match gocui

This commit is contained in:
Stefan Haller
2025-02-19 18:23:35 +01:00
parent ac3824bd7c
commit e5137b86cf
4 changed files with 41 additions and 19 deletions

View File

@@ -173,6 +173,7 @@ func TestWrapViewLinesToWidth(t *testing.T) {
editable bool
text string
width int
tabWidth int
expectedWrappedLines []string
expectedWrappedLinesIndices []int
expectedOriginalLinesIndices []int
@@ -353,14 +354,25 @@ func TestWrapViewLinesToWidth(t *testing.T) {
},
},
{
name: "Tabs",
wrap: true,
text: "\ta\tbb\tccc\tdddd\teeeee",
width: 50,
name: "Tabs, width 4",
wrap: true,
text: "\ta\tbb\tccc\tdddd\teeeee",
width: 50,
tabWidth: 4,
expectedWrappedLines: []string{
" a bb ccc dddd eeeee",
},
},
{
name: "Tabs, width 8",
wrap: true,
text: "\ta\tbb\tccc\tdddddddd\teeeee",
width: 100,
tabWidth: 8,
expectedWrappedLines: []string{
" a bb ccc dddddddd eeeee",
},
},
{
name: "Multiple lines",
wrap: true,
@@ -425,7 +437,11 @@ func TestWrapViewLinesToWidth(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
wrappedLines, wrappedLinesIndices, originalLinesIndices := WrapViewLinesToWidth(tt.wrap, tt.editable, tt.text, tt.width)
tabWidth := tt.tabWidth
if tabWidth == 0 {
tabWidth = 4
}
wrappedLines, wrappedLinesIndices, originalLinesIndices := WrapViewLinesToWidth(tt.wrap, tt.editable, tt.text, tt.width, tabWidth)
assert.Equal(t, tt.expectedWrappedLines, wrappedLines)
if tt.expectedWrappedLinesIndices != nil {
assert.Equal(t, tt.expectedWrappedLinesIndices, wrappedLinesIndices)
@@ -436,6 +452,7 @@ func TestWrapViewLinesToWidth(t *testing.T) {
// As a sanity check, also test that gocui's line wrapping behaves the same way
view := gocui.NewView("", 0, 0, tt.width+1, 1000, gocui.OutputNormal)
view.TabWidth = tabWidth
assert.Equal(t, tt.width, view.InnerWidth())
view.Wrap = tt.wrap
view.Editable = tt.editable