mirror of
https://github.com/charmbracelet/gum
synced 2024-06-08 16:52:17 +02:00
fixed issue with single letter matches in next
This commit is contained in:
parent
582000fa04
commit
111c897007
|
@ -65,17 +65,22 @@ func (s *search) NextMatch(m *model) {
|
|||
// Find the string to highlight.
|
||||
nextMatch := s.query.FindString(m.content[s.lastMatchLoc:])
|
||||
s.prevMatch = nextMatch
|
||||
if nextMatch == "" {
|
||||
// Start the search from the beginning of the document.
|
||||
s.lastMatchLoc = 0
|
||||
m.viewport.GotoTop()
|
||||
return
|
||||
}
|
||||
m.content = m.content[:s.lastMatchLoc] + strings.Replace(m.content[s.lastMatchLoc:], nextMatch, m.matchHighlightStyle.Render(nextMatch), 1)
|
||||
|
||||
// Update the postion of the last found match.
|
||||
nextMatchI := s.query.FindStringIndex(m.content[s.lastMatchLoc:])
|
||||
s.lastMatchLoc += nextMatchI[1]
|
||||
leftPadding, _ := utils.LipglossLengthPadding(s.prevMatch, m.matchHighlightStyle)
|
||||
allMatches := s.query.FindAllSubmatchIndex([]byte(m.content), -1)
|
||||
for i, subm := range allMatches {
|
||||
if subm[1]+leftPadding == s.lastMatchLoc {
|
||||
// Highliht the current match.
|
||||
m.content = m.content[:allMatches[i+1][0]] + strings.Replace(m.content[allMatches[i+1][0]:], m.content[allMatches[i+1][0]:allMatches[i+1][1]], m.matchHighlightStyle.Render(m.content[allMatches[i+1][0]:allMatches[i+1][1]]), 1)
|
||||
s.lastMatchLoc = allMatches[i+1][1] + leftPadding
|
||||
break
|
||||
}
|
||||
if i == len(allMatches)-1 {
|
||||
m.content = m.content[:allMatches[0][0]] + strings.Replace(m.content[allMatches[0][0]:], m.content[allMatches[0][0]:allMatches[0][1]], m.matchHighlightStyle.Render(m.content[allMatches[0][0]:allMatches[0][1]]), 1)
|
||||
s.lastMatchLoc = allMatches[0][1] + leftPadding
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
// Update the viewport position.
|
||||
line := 0
|
||||
|
|
Loading…
Reference in a new issue