Documentation
¶
Overview ¶
Package search finds a literal substring across parsed diffs and tracks the cursor over the hits, including the view position to restore when a search is canceled.
Index ¶
- type MatchLocation
- type NavigationState
- type State
- func (s *State) ExecuteSearch(files []diff.FileChange)
- func (s *State) GetCurrentMatch() *MatchLocation
- func (s *State) GetMatchesForLine(fileIdx, hunkIdx, lineIdx int) []MatchLocation
- func (s *State) IsCurrentMatch(fileIdx, hunkIdx, lineIdx int) bool
- func (s *State) IsLineMatch(fileIdx, hunkIdx, lineIdx int) bool
- func (s *State) MatchCount() int
- func (s *State) NextMatch() *MatchLocation
- func (s *State) PrevMatch() *MatchLocation
- func (s *State) RestoreOriginalState() NavigationState
- func (s *State) SaveOriginalState(nav NavigationState)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MatchLocation ¶
type MatchLocation struct {
FileIdx int
HunkIdx int
LineIdx int
FilePath string
StartCol int
EndCol int
MatchText string
}
MatchLocation is one hit. StartCol and EndCol are byte offsets into MatchText with EndCol exclusive, and HunkIdx and LineIdx are -1 on a hit in a file path rather than a diff line.
type NavigationState ¶
type NavigationState struct {
}
NavigationState is the view position a search moves away from, held so canceling can put the cursor, scroll offset, and focused panel back where they were.
type State ¶ added in v0.1.2
type State struct {
Query string
Matches []MatchLocation
CurrentIdx int
OriginalState NavigationState
IsActive bool
IsCaseSensitive bool
}
State carries a query and the hits it produced. Query and IsCaseSensitive are inputs, and Matches and CurrentIdx only reflect them once ExecuteSearch runs, so editing a field alone leaves the match list stale.
func NewState ¶ added in v0.1.2
func NewState() *State
NewState returns an inactive, case-insensitive state with CurrentIdx at -1, which is the "nothing selected" value every match accessor checks for.
func (*State) ExecuteSearch ¶ added in v0.1.2
func (s *State) ExecuteSearch(files []diff.FileChange)
ExecuteSearch rebuilds the match list by scanning every file path and diff line, then points CurrentIdx at the first hit (or -1 when there is none). Overlapping hits are all reported, because the scan resumes one byte past each one, and an empty Query clears the list.
func (*State) GetCurrentMatch ¶ added in v0.1.2
func (s *State) GetCurrentMatch() *MatchLocation
GetCurrentMatch returns the match CurrentIdx points at, or nil when the index is out of range, which covers both a fresh state and a query that found nothing.
func (*State) GetMatchesForLine ¶ added in v0.1.2
func (s *State) GetMatchesForLine(fileIdx, hunkIdx, lineIdx int) []MatchLocation
GetMatchesForLine returns every hit on one diff line in ascending column order, which is the order a renderer needs to highlight the spans in one pass. The result is nil when the line has no hit.
func (*State) IsCurrentMatch ¶ added in v0.1.2
IsCurrentMatch reports whether the hit CurrentIdx points at falls on one diff line, which lets a renderer style the active hit apart from the rest. It is false whenever there is no current hit.
func (*State) IsLineMatch ¶ added in v0.1.2
IsLineMatch reports whether any hit falls on one diff line. All three indices are 0-based, and a hunkIdx and lineIdx of -1 tests a file-path hit. It walks the whole match list, so cost grows with matches times rendered lines.
func (*State) MatchCount ¶ added in v0.1.2
MatchCount reports how many hits the last ExecuteSearch found, counting occurrences rather than lines, so one line with two hits counts twice.
func (*State) NextMatch ¶ added in v0.1.2
func (s *State) NextMatch() *MatchLocation
NextMatch advances one match and wraps past the last, returning nil when there are no matches. The pointer refers into the match slice, which the next ExecuteSearch replaces.
func (*State) PrevMatch ¶ added in v0.1.2
func (s *State) PrevMatch() *MatchLocation
PrevMatch steps back one match and wraps past the first, returning nil when there are no matches.
func (*State) RestoreOriginalState ¶ added in v0.1.2
func (s *State) RestoreOriginalState() NavigationState
RestoreOriginalState returns the position saved when the search opened, leaving it saved so a repeated cancel is harmless.
func (*State) SaveOriginalState ¶ added in v0.1.2
func (s *State) SaveOriginalState(nav NavigationState)
SaveOriginalState records where to return if the search is canceled, overwriting any earlier save. Call it when the search opens, because calling it after the cursor has jumped to a match saves the match instead of the origin.