diff --git a/editor/document/row.go b/editor/document/row.go index 71a1c74..61a8149 100644 --- a/editor/document/row.go +++ b/editor/document/row.go @@ -3,7 +3,8 @@ package document import ( "strings" "timshome.page/gilo/editor/highlight" - gilo2 "timshome.page/gilo/internal/gilo" + "timshome.page/gilo/internal/gilo" + "timshome.page/gilo/key" "unicode" ) @@ -33,7 +34,7 @@ func (r *Row) RenderSize() int { return len(r.render) } -func (r *Row) Render(at *gilo2.Point) string { +func (r *Row) Render(at *gilo.Point) string { return string(r.render[at.X:]) } @@ -95,7 +96,7 @@ func (r *Row) deleteRune(at int) { func (r *Row) update() { r.render = r.render[:0] - replacement := strings.Repeat(" ", gilo2.TabSize) + replacement := strings.Repeat(" ", gilo.TabSize) str := strings.ReplaceAll(string(r.chars), "\t", replacement) for _, ch := range str { @@ -107,17 +108,30 @@ func (r *Row) update() { func (r *Row) updateSyntax() { i := 0 + prevSep := true r.Hl = make([]int, r.RenderSize()) + for i < r.RenderSize() { ch := r.render[i] - if unicode.IsDigit(ch) { + prevHl := highlight.Normal + + if i > 0 { + prevHl = r.Hl[i - 1] + } + + if (unicode.IsDigit(ch) && (prevSep || prevHl == highlight.Number)) || + (ch == '.' && prevHl == highlight.Number) { r.Hl[i] = highlight.Number + i += 1 + prevSep = false + continue } else { r.Hl[i] = highlight.Normal } + prevSep = key.IsSeparator(ch) i++ } } @@ -131,7 +145,7 @@ func (r *Row) CursorXToRenderX(cursorX int) (renderX int) { for i := 0; i < cursorX; i++ { if r.chars[i] == '\t' { - renderX += (gilo2.TabSize - 1) - (renderX % gilo2.TabSize) + renderX += (gilo.TabSize - 1) - (renderX % gilo.TabSize) } renderX += 1 @@ -146,7 +160,7 @@ func (r *Row) RenderXtoCursorX(renderX int) (cursorX int) { for cursorX = 0; cursorX < r.Size(); cursorX++ { if r.chars[cursorX] == '\t' { - currentRenderX += (gilo2.TabSize - 1) - (currentRenderX % gilo2.TabSize) + currentRenderX += (gilo.TabSize - 1) - (currentRenderX % gilo.TabSize) } else { currentRenderX += 1 } diff --git a/editor/editor.go b/editor/editor.go index e2ddac8..51fb37f 100644 --- a/editor/editor.go +++ b/editor/editor.go @@ -1,4 +1,4 @@ -// The main interface/implementation of the editor object +// Package editor The main interface/implementation of the editor object package editor import ( diff --git a/gilo.go b/gilo.go index 1282465..1770bdf 100644 --- a/gilo.go +++ b/gilo.go @@ -1,8 +1,8 @@ package main import ( - "golang.org/x/term" "fmt" + "golang.org/x/term" "os" "timshome.page/gilo/editor" "timshome.page/gilo/terminal"