Properly highlight numbers
All checks were successful
timw4mail/gilo/pipeline/head This commit looks good

This commit is contained in:
Timothy Warren 2021-04-13 14:43:31 -04:00
parent fe1c54317e
commit 9735d9b252
3 changed files with 22 additions and 8 deletions

View File

@ -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
}

View File

@ -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 (

View File

@ -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"