mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-08-08 22:36:49 +02:00
Convert tabs to spaces in WrapViewLinesToWidth
We haven't needed this before since we were only using the function for text in confirmations and menus, which is unlikely to contain tabs. We are going to use it for patches in the staging view though, which often do.
This commit is contained in:
@ -115,6 +115,15 @@ func WrapViewLinesToWidth(wrap bool, text string, width int) []string {
|
|||||||
wrappedLines := make([]string, 0, len(lines))
|
wrappedLines := make([]string, 0, len(lines))
|
||||||
|
|
||||||
for _, line := range lines {
|
for _, line := range lines {
|
||||||
|
// convert tabs to spaces
|
||||||
|
for i := 0; i < len(line); i++ {
|
||||||
|
if line[i] == '\t' {
|
||||||
|
numSpaces := 4 - (i % 4)
|
||||||
|
line = line[:i] + " "[:numSpaces] + line[i+1:]
|
||||||
|
i += numSpaces - 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
n := 0
|
n := 0
|
||||||
offset := 0
|
offset := 0
|
||||||
lastWhitespaceIndex := -1
|
lastWhitespaceIndex := -1
|
||||||
|
@ -334,6 +334,15 @@ func TestWrapViewLinesToWidth(t *testing.T) {
|
|||||||
"drifting blah blah",
|
"drifting blah blah",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "Tabs",
|
||||||
|
wrap: true,
|
||||||
|
text: "\ta\tbb\tccc\tdddd\teeeee",
|
||||||
|
width: 50,
|
||||||
|
expectedWrappedLines: []string{
|
||||||
|
" a bb ccc dddd eeeee",
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
Reference in New Issue
Block a user