mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-06-19 00:28:03 +02:00
Add integration test for commit highlighting on focus
A better refactor would be to allow matchers to assert against either a string or a slice of cells, so that I could have the same ergonomics that I have elsewhere, but this is a start.
This commit is contained in:
36
vendor/github.com/jesseduffield/gocui/view.go
generated
vendored
36
vendor/github.com/jesseduffield/gocui/view.go
generated
vendored
@ -13,6 +13,7 @@ import (
|
||||
"unicode"
|
||||
"unicode/utf8"
|
||||
|
||||
"github.com/gdamore/tcell/v2"
|
||||
"github.com/go-errors/errors"
|
||||
"github.com/mattn/go-runewidth"
|
||||
)
|
||||
@ -1461,3 +1462,38 @@ func (v *View) scrollMargin() int {
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
// Returns true if the view contains a line containing the given text with the given
|
||||
// foreground color
|
||||
func (v *View) ContainsColoredText(fgColor string, text string) bool {
|
||||
for _, line := range v.lines {
|
||||
if containsColoredTextInLine(fgColor, text, line) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func containsColoredTextInLine(fgColorStr string, text string, line []cell) bool {
|
||||
fgColor := tcell.GetColor(fgColorStr)
|
||||
|
||||
currentMatch := ""
|
||||
for i := 0; i < len(line); i++ {
|
||||
cell := line[i]
|
||||
|
||||
// stripping attributes by converting to and from hex
|
||||
cellColor := tcell.NewHexColor(cell.fgColor.Hex())
|
||||
|
||||
if cellColor == fgColor {
|
||||
currentMatch += string(cell.chr)
|
||||
} else if currentMatch != "" {
|
||||
if strings.Contains(currentMatch, text) {
|
||||
return true
|
||||
}
|
||||
currentMatch = ""
|
||||
}
|
||||
}
|
||||
|
||||
return strings.Contains(currentMatch, text)
|
||||
}
|
||||
|
Reference in New Issue
Block a user