1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-10-26 16:31:18 +03:00

Bump gocui

The main change here is https://github.com/jesseduffield/gocui/pull/85, which
avoids breaking lines after footnote symbols in commit messages (e.g. [1]).

[1]: https://www.example.com/this-is-a-really-long-url-that-lazy-git-automatically-wraps-and-is-an-issue
This commit is contained in:
Stefan Haller
2025-10-02 17:25:46 +02:00
parent cb2b5c3738
commit ef92e30315
119 changed files with 3883 additions and 17382 deletions

View File

@@ -1,6 +1,7 @@
package gocui
import (
"regexp"
"strings"
"github.com/mattn/go-runewidth"
@@ -33,14 +34,16 @@ func AutoWrapContent(content []rune, autoWrapWidth int) ([]rune, []CursorMapping
wrappedContent := make([]rune, 0, len(content)+estimatedNumberOfSoftLineBreaks)
startOfLine := 0
indexOfLastWhitespace := -1
var footNoteMatcher footNoteMatcher
for currentPos, r := range content {
if r == '\n' {
wrappedContent = append(wrappedContent, content[startOfLine:currentPos+1]...)
startOfLine = currentPos + 1
indexOfLastWhitespace = -1
footNoteMatcher.reset()
} else {
if r == ' ' {
if r == ' ' && !footNoteMatcher.isFootNote() {
indexOfLastWhitespace = currentPos + 1
} else if currentPos-startOfLine >= autoWrapWidth && indexOfLastWhitespace >= 0 {
wrapAt := indexOfLastWhitespace
@@ -49,7 +52,9 @@ func AutoWrapContent(content []rune, autoWrapWidth int) ([]rune, []CursorMapping
cursorMapping = append(cursorMapping, CursorMapping{wrapAt, len(wrappedContent)})
startOfLine = wrapAt
indexOfLastWhitespace = -1
footNoteMatcher.reset()
}
footNoteMatcher.addRune(r)
}
}
@@ -58,6 +63,50 @@ func AutoWrapContent(content []rune, autoWrapWidth int) ([]rune, []CursorMapping
return wrappedContent, cursorMapping
}
var footNoteRe = regexp.MustCompile(`^\[\d+\]:\s*$`)
type footNoteMatcher struct {
lineStr strings.Builder
didFailToMatch bool
}
func (self *footNoteMatcher) addRune(r rune) {
if self.didFailToMatch {
// don't bother tracking the rune if we know it can't possibly match any more
return
}
if self.lineStr.Len() == 0 && r != '[' {
// fail early if the first rune of a line isn't a '['; this is mainly to avoid a (possibly
// expensive) regex match
self.didFailToMatch = true
return
}
self.lineStr.WriteRune(r)
}
func (self *footNoteMatcher) isFootNote() bool {
if self.didFailToMatch {
return false
}
if footNoteRe.MatchString(self.lineStr.String()) {
// it's a footnote, so treat spaces as non-breaking. It's important not to reset the matcher
// here, because there could be multiple spaces after a footnote.
return true
}
// no need to check again for this line
self.didFailToMatch = true
return false
}
func (self *footNoteMatcher) reset() {
self.lineStr.Reset()
self.didFailToMatch = false
}
func (self *TextArea) autoWrapContent() {
if self.AutoWrap {
self.wrappedContent, self.cursorMapping = AutoWrapContent(self.content, self.AutoWrapWidth)