mirror of
https://github.com/rwinkhart/go-highlite.git
synced 2026-09-06 08:57:15 -04:00
Set matches in the input
This commit is contained in:
+28
-13
@@ -24,6 +24,7 @@ type LineStates interface {
|
|||||||
LineData() [][]byte
|
LineData() [][]byte
|
||||||
State(lineN int) State
|
State(lineN int) State
|
||||||
SetState(lineN int, s State)
|
SetState(lineN int, s State)
|
||||||
|
SetMatch(lineN int, m LineMatch)
|
||||||
}
|
}
|
||||||
|
|
||||||
type Highlighter struct {
|
type Highlighter struct {
|
||||||
@@ -190,30 +191,45 @@ func (h *Highlighter) HighlightString(input string) []LineMatch {
|
|||||||
return lineMatches
|
return lineMatches
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Highlighter) Highlight(input LineStates, startline int) []LineMatch {
|
func (h *Highlighter) Highlight(input LineStates, startline int) {
|
||||||
lines := input.LineData()
|
lines := input.LineData()
|
||||||
var lineMatches []LineMatch
|
|
||||||
|
|
||||||
for i := startline; i < len(lines); i++ {
|
for i := startline; i < len(lines); i++ {
|
||||||
line := []byte(lines[i])
|
line := []byte(lines[i])
|
||||||
|
|
||||||
|
var match LineMatch
|
||||||
if i == 0 || h.lastRegion == nil {
|
if i == 0 || h.lastRegion == nil {
|
||||||
lineMatches = append(lineMatches, h.highlightEmptyRegion(0, true, i, line))
|
match = h.highlightEmptyRegion(0, true, i, line)
|
||||||
} else {
|
} else {
|
||||||
lineMatches = append(lineMatches, h.highlightRegion(0, true, i, line, h.lastRegion))
|
match = h.highlightRegion(0, true, i, line, h.lastRegion)
|
||||||
}
|
}
|
||||||
|
|
||||||
curState := h.lastRegion
|
curState := h.lastRegion
|
||||||
|
|
||||||
|
input.SetMatch(i, match)
|
||||||
input.SetState(i, curState)
|
input.SetState(i, curState)
|
||||||
}
|
}
|
||||||
|
|
||||||
return lineMatches
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Highlighter) ReHighlight(input LineStates, startline int) []LineMatch {
|
func (h *Highlighter) ReHighlightLine(input LineStates, lineN int) {
|
||||||
|
lines := input.LineData()
|
||||||
|
|
||||||
|
line := []byte(lines[lineN])
|
||||||
|
|
||||||
|
var match LineMatch
|
||||||
|
if lineN == 0 || h.lastRegion == nil {
|
||||||
|
match = h.highlightEmptyRegion(0, true, lineN, line)
|
||||||
|
} else {
|
||||||
|
match = h.highlightRegion(0, true, lineN, line, h.lastRegion)
|
||||||
|
}
|
||||||
|
curState := h.lastRegion
|
||||||
|
|
||||||
|
input.SetMatch(lineN, match)
|
||||||
|
input.SetState(lineN, curState)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *Highlighter) ReHighlight(input LineStates, startline int) {
|
||||||
lines := input.LineData()
|
lines := input.LineData()
|
||||||
var lineMatches []LineMatch
|
|
||||||
|
|
||||||
h.lastRegion = nil
|
h.lastRegion = nil
|
||||||
if startline > 0 {
|
if startline > 0 {
|
||||||
@@ -222,12 +238,12 @@ func (h *Highlighter) ReHighlight(input LineStates, startline int) []LineMatch {
|
|||||||
for i := startline; i < len(lines); i++ {
|
for i := startline; i < len(lines); i++ {
|
||||||
line := []byte(lines[i])
|
line := []byte(lines[i])
|
||||||
|
|
||||||
|
var match LineMatch
|
||||||
if i == 0 || h.lastRegion == nil {
|
if i == 0 || h.lastRegion == nil {
|
||||||
lineMatches = append(lineMatches, h.highlightEmptyRegion(0, true, i, line))
|
match = h.highlightEmptyRegion(0, true, i, line)
|
||||||
} else {
|
} else {
|
||||||
lineMatches = append(lineMatches, h.highlightRegion(0, true, i, line, h.lastRegion))
|
match = h.highlightRegion(0, true, i, line, h.lastRegion)
|
||||||
}
|
}
|
||||||
|
|
||||||
curState := h.lastRegion
|
curState := h.lastRegion
|
||||||
lastState := input.State(i)
|
lastState := input.State(i)
|
||||||
|
|
||||||
@@ -235,8 +251,7 @@ func (h *Highlighter) ReHighlight(input LineStates, startline int) []LineMatch {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
input.SetMatch(i, match)
|
||||||
input.SetState(i, curState)
|
input.SetState(i, curState)
|
||||||
}
|
}
|
||||||
|
|
||||||
return lineMatches
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user