mirror of
https://github.com/zyedidia/micro.git
synced 2026-02-05 14:40:20 +09:00
Start implementing syntax highlighting optimizations
This commit is contained in:
@@ -47,6 +47,7 @@ type Buffer struct {
|
||||
|
||||
syntaxDef *highlight.Def
|
||||
highlighter *highlight.Highlighter
|
||||
matches []highlight.LineMatch
|
||||
|
||||
// Buffer local settings
|
||||
Settings map[string]interface{}
|
||||
@@ -189,6 +190,7 @@ func (b *Buffer) UpdateRules() {
|
||||
if b.highlighter == nil || b.Settings["filetype"].(string) != b.syntaxDef.FileType {
|
||||
b.Settings["filetype"] = b.syntaxDef.FileType
|
||||
b.highlighter = highlight.NewHighlighter(b.syntaxDef)
|
||||
b.matches = b.highlighter.Highlight(b, 0)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/mattn/go-runewidth"
|
||||
"github.com/zyedidia/tcell"
|
||||
)
|
||||
@@ -45,7 +47,14 @@ func (c *CellView) Draw(buf *Buffer, top, height, left, width int) {
|
||||
softwrap := buf.Settings["softwrap"].(bool)
|
||||
indentchar := []rune(buf.Settings["indentchar"].(string))[0]
|
||||
|
||||
matches := buf.highlighter.Highlight(buf.String())
|
||||
start := buf.Cursor.Y
|
||||
startTime := time.Now()
|
||||
matches := buf.highlighter.ReHighlight(buf, start)
|
||||
elapsed := time.Since(startTime)
|
||||
for i, m := range matches {
|
||||
buf.matches[start+i] = m
|
||||
}
|
||||
messenger.Message("Rehighlighted ", len(matches), " lines in ", elapsed)
|
||||
|
||||
c.lines = make([][]*Char, 0)
|
||||
|
||||
@@ -81,7 +90,7 @@ func (c *CellView) Draw(buf *Buffer, top, height, left, width int) {
|
||||
if colN >= len(line) {
|
||||
break
|
||||
}
|
||||
if group, ok := matches[lineN][colN]; ok {
|
||||
if group, ok := buf.matches[lineN][colN]; ok {
|
||||
curStyle = GetColor(group)
|
||||
}
|
||||
|
||||
@@ -116,7 +125,7 @@ func (c *CellView) Draw(buf *Buffer, top, height, left, width int) {
|
||||
}
|
||||
|
||||
}
|
||||
if group, ok := matches[lineN][len(line)]; ok {
|
||||
if group, ok := buf.matches[lineN][len(line)]; ok {
|
||||
curStyle = GetColor(group)
|
||||
}
|
||||
|
||||
|
||||
@@ -173,3 +173,19 @@ func (la *LineArray) Substr(start, end Loc) string {
|
||||
str += string(la.lines[end.Y].data[:endX])
|
||||
return str
|
||||
}
|
||||
|
||||
func (la *LineArray) LineData() [][]byte {
|
||||
lines := make([][]byte, len(la.lines))
|
||||
for i, l := range la.lines {
|
||||
lines[i] = l.data
|
||||
}
|
||||
return lines
|
||||
}
|
||||
|
||||
func (la *LineArray) State(lineN int) highlight.State {
|
||||
return la.lines[lineN].state
|
||||
}
|
||||
|
||||
func (la *LineArray) SetState(lineN int, s highlight.State) {
|
||||
la.lines[lineN].state = s
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/mitchellh/go-homedir"
|
||||
"github.com/zyedidia/highlight"
|
||||
"github.com/zyedidia/tcell"
|
||||
)
|
||||
|
||||
@@ -87,9 +86,6 @@ type View struct {
|
||||
// Same here, just to keep track for mouse move events
|
||||
tripleClick bool
|
||||
|
||||
// Syntax highlighting matches
|
||||
matches []highlight.LineMatch
|
||||
|
||||
cellview *CellView
|
||||
|
||||
splitNode *LeafNode
|
||||
|
||||
Reference in New Issue
Block a user