mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-08-08 22:36:49 +02:00
Extract helper function
This doesn't improve the code much in the current state, but we'll add some more code to this helper function in the next commit, which makes it worth it.
This commit is contained in:
@ -124,6 +124,10 @@ func WrapViewLinesToWidth(wrap bool, text string, width int) []string {
|
||||
}
|
||||
}
|
||||
|
||||
appendWrappedLine := func(str string) {
|
||||
wrappedLines = append(wrappedLines, str)
|
||||
}
|
||||
|
||||
n := 0
|
||||
offset := 0
|
||||
lastWhitespaceIndex := -1
|
||||
@ -133,23 +137,23 @@ func WrapViewLinesToWidth(wrap bool, text string, width int) []string {
|
||||
|
||||
if n > width {
|
||||
if currChr == ' ' {
|
||||
wrappedLines = append(wrappedLines, line[offset:i])
|
||||
appendWrappedLine(line[offset:i])
|
||||
offset = i + 1
|
||||
n = 0
|
||||
} else if currChr == '-' {
|
||||
wrappedLines = append(wrappedLines, line[offset:i])
|
||||
appendWrappedLine(line[offset:i])
|
||||
offset = i
|
||||
n = rw
|
||||
} else if lastWhitespaceIndex != -1 {
|
||||
if line[lastWhitespaceIndex] == '-' {
|
||||
wrappedLines = append(wrappedLines, line[offset:lastWhitespaceIndex+1])
|
||||
appendWrappedLine(line[offset : lastWhitespaceIndex+1])
|
||||
} else {
|
||||
wrappedLines = append(wrappedLines, line[offset:lastWhitespaceIndex])
|
||||
appendWrappedLine(line[offset:lastWhitespaceIndex])
|
||||
}
|
||||
offset = lastWhitespaceIndex + 1
|
||||
n = runewidth.StringWidth(line[offset : i+1])
|
||||
} else {
|
||||
wrappedLines = append(wrappedLines, line[offset:i])
|
||||
appendWrappedLine(line[offset:i])
|
||||
offset = i
|
||||
n = rw
|
||||
}
|
||||
@ -159,7 +163,7 @@ func WrapViewLinesToWidth(wrap bool, text string, width int) []string {
|
||||
}
|
||||
}
|
||||
|
||||
wrappedLines = append(wrappedLines, line[offset:])
|
||||
appendWrappedLine(line[offset:])
|
||||
}
|
||||
|
||||
return wrappedLines
|
||||
|
Reference in New Issue
Block a user