]> git.lizzy.rs Git - micro.git/blobdiff - cmd/micro/highlighter.go
Fix draw ordering
[micro.git] / cmd / micro / highlighter.go
index d1d46a1664d8e70c49abe3e98a9ad525de1a5bb7..32fe656324b4f54739f2c724f10a61ea709f1bd4 100644 (file)
@@ -51,6 +51,7 @@ var preInstalledSynFiles = []string{
        "erb",
        "fish",
        "fortran",
+       "gdscript",
        "gentoo-ebuild",
        "gentoo-etc-portage",
        "git-commit",
@@ -138,8 +139,23 @@ func LoadSyntaxFiles() {
 // This involves finding the regex for syntax and if it exists, the regex
 // for the header. Then we must get the text for the file and the filetype.
 func LoadSyntaxFilesFromDir(dir string) {
+       colorscheme = make(Colorscheme)
        InitColorscheme()
 
+       // Default style
+       defStyle = tcell.StyleDefault.
+               Foreground(tcell.ColorDefault).
+               Background(tcell.ColorDefault)
+
+       // There may be another default style defined in the colorscheme
+       // In that case we should use that one
+       if style, ok := colorscheme["default"]; ok {
+               defStyle = style
+       }
+       if screen != nil {
+               screen.SetStyle(defStyle)
+       }
+
        syntaxFiles = make(map[[2]*regexp.Regexp]FileTypeRules)
        files, _ := ioutil.ReadDir(dir)
        for _, f := range files {
@@ -301,8 +317,20 @@ func LoadRulesFromFile(text, filename string) []SyntaxRule {
                        // in which case we should look that up in the colorscheme
                        // They can also just give us a straight up color
                        st := defStyle
-                       if _, ok := colorscheme[color]; ok {
-                               st = colorscheme[color]
+                       groups := strings.Split(color, ".")
+                       if len(groups) > 1 {
+                               curGroup := ""
+                               for i, g := range groups {
+                                       if i != 0 {
+                                               curGroup += "."
+                                       }
+                                       curGroup += g
+                                       if style, ok := colorscheme[curGroup]; ok {
+                                               st = style
+                                       }
+                               }
+                       } else if style, ok := colorscheme[color]; ok {
+                               st = style
                        } else {
                                st = StringToStyle(color)
                        }
@@ -366,7 +394,7 @@ func GetRules(buf *Buffer) ([]SyntaxRule, string) {
                if r[0] != nil && r[0].MatchString(buf.Path) {
                        // Check if the syntax statement matches the extension
                        return LoadRulesFromFile(syntaxFiles[r].text, syntaxFiles[r].filename), syntaxFiles[r].filetype
-               } else if r[1] != nil && r[1].MatchString(buf.Lines[0]) {
+               } else if r[1] != nil && r[1].MatchString(buf.Line(0)) {
                        // Check if the header statement matches the first line
                        return LoadRulesFromFile(syntaxFiles[r].text, syntaxFiles[r].filename), syntaxFiles[r].filetype
                }
@@ -390,11 +418,14 @@ func Match(v *View) SyntaxMatches {
                viewEnd = buf.NumLines
        }
 
-       lines := buf.Lines[viewStart:viewEnd]
+       lines := buf.Lines(viewStart, viewEnd)
        matches := make(SyntaxMatches, len(lines))
 
        for i, line := range lines {
                matches[i] = make([]tcell.Style, len(line)+1)
+               for j, _ := range matches[i] {
+                       matches[i][j] = defStyle
+               }
        }
 
        // We don't actually check the entire buffer, just from synLinesUp to synLinesDown
@@ -407,10 +438,10 @@ func Match(v *View) SyntaxMatches {
                totalEnd = buf.NumLines
        }
 
-       str := strings.Join(buf.Lines[totalStart:totalEnd], "\n")
-       startNum := ToCharPos(0, totalStart, v.Buf)
+       str := strings.Join(buf.Lines(totalStart, totalEnd), "\n")
+       startNum := ToCharPos(Loc{0, totalStart}, v.Buf)
 
-       toplineNum := ToCharPos(0, v.Topline, v.Buf)
+       toplineNum := ToCharPos(Loc{0, v.Topline}, v.Buf)
 
        for _, rule := range rules {
                if rule.startend {
@@ -422,7 +453,8 @@ func Match(v *View) SyntaxMatches {
                                                if i < toplineNum {
                                                        continue
                                                }
-                                               colNum, lineNum := FromCharPosStart(toplineNum, 0, v.Topline, i, buf)
+                                               loc := FromCharPos(i, buf)
+                                               colNum, lineNum := loc.X, loc.Y
                                                if lineNum == -1 || colNum == -1 {
                                                        continue
                                                }