mirror of
https://github.com/felixangell/phi.git
synced 2024-09-11 15:55:25 +03:00
editor only renders whats on screen
This commit is contained in:
parent
39c7d19bf3
commit
93069dc50b
@ -686,7 +686,7 @@ func (b *Buffer) renderAt(ctx *strife.Renderer, rx int, ry int) {
|
|||||||
|
|
||||||
if b.cfg.Editor.Highlight_Line && b.HasFocus {
|
if b.cfg.Editor.Highlight_Line && b.HasFocus {
|
||||||
ctx.SetColor(strife.Black) // highlight_line_col?
|
ctx.SetColor(strife.Black) // highlight_line_col?
|
||||||
ctx.Rect(rx, (ry + b.curs.ry*last_h), b.w, last_h, strife.Fill)
|
ctx.Rect(rx, (ry+b.curs.ry*last_h)-(b.cam.y*last_h), b.w, last_h, strife.Fill)
|
||||||
}
|
}
|
||||||
|
|
||||||
// render the ol' cursor
|
// render the ol' cursor
|
||||||
@ -697,25 +697,28 @@ func (b *Buffer) renderAt(ctx *strife.Renderer, rx int, ry int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ctx.SetColor(strife.HexRGB(b.cfg.Theme.Cursor)) // caret colour
|
ctx.SetColor(strife.HexRGB(b.cfg.Theme.Cursor)) // caret colour
|
||||||
ctx.Rect((rx + b.curs.rx*last_w), (ry + b.curs.ry*last_h), cursorWidth, last_h, strife.Fill)
|
ctx.Rect((rx+b.curs.rx*last_w)-(b.cam.x*last_w), (ry+b.curs.ry*last_h)-(b.cam.y*last_h), cursorWidth, last_h, strife.Fill)
|
||||||
}
|
}
|
||||||
|
|
||||||
source := b.contents
|
var visibleLines int = 50
|
||||||
|
|
||||||
// last_h > 0 means we have done
|
// last_h > 0 means we have done
|
||||||
// a render.
|
// a render.
|
||||||
if int(last_h) > 0 && int(b.h) != 0 {
|
if int(last_h) > 0 && int(b.h) != 0 {
|
||||||
// work out how many lines can fit into
|
// render an extra three lines just
|
||||||
// the buffer, and set the source to
|
// so we dont cut anything off if its
|
||||||
// slice the line buffer accordingly
|
// not evenly divisible
|
||||||
visibleLines := int(b.h) / int(last_h)
|
visibleLines = (int(b.h) / int(last_h)) + 3
|
||||||
if len(b.contents) > visibleLines {
|
}
|
||||||
// nop
|
|
||||||
}
|
start := b.cam.y
|
||||||
|
upper := b.cam.y + visibleLines
|
||||||
|
if upper > len(b.contents) {
|
||||||
|
upper = len(b.contents)
|
||||||
}
|
}
|
||||||
|
|
||||||
var y_col int
|
var y_col int
|
||||||
for _, rope := range source {
|
for _, rope := range b.contents[start:upper] {
|
||||||
// this is because if we had the following
|
// this is because if we had the following
|
||||||
// text input:
|
// text input:
|
||||||
//
|
//
|
||||||
@ -732,7 +735,7 @@ func (b *Buffer) renderAt(ctx *strife.Renderer, rx int, ry int) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
source := []rune(rope.String())
|
currLine := []rune(rope.String())
|
||||||
|
|
||||||
// char index => colour
|
// char index => colour
|
||||||
matches := map[int]int{}
|
matches := map[int]int{}
|
||||||
@ -747,10 +750,10 @@ func (b *Buffer) renderAt(ctx *strife.Renderer, rx int, ry int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// HOLY SLOW BATMAN
|
// HOLY SLOW BATMAN
|
||||||
for idx, _ := range source {
|
for idx, _ := range currLine {
|
||||||
for syntaxIndex, syntax := range subjects {
|
for syntaxIndex, syntax := range subjects {
|
||||||
if syntax.Pattern != "" {
|
if syntax.Pattern != "" {
|
||||||
a := source[idx:]
|
a := currLine[idx:]
|
||||||
match, _ := regexp.MatchString(syntax.Pattern, string(a))
|
match, _ := regexp.MatchString(syntax.Pattern, string(a))
|
||||||
if match {
|
if match {
|
||||||
for i := 0; i < len(string(a)); i++ {
|
for i := 0; i < len(string(a)); i++ {
|
||||||
@ -759,10 +762,10 @@ func (b *Buffer) renderAt(ctx *strife.Renderer, rx int, ry int) {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for _, subject := range syntax.Match {
|
for _, subject := range syntax.Match {
|
||||||
if idx+len(subject) > len(source) {
|
if idx+len(subject) > len(currLine) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
a := source[idx : idx+len(subject)]
|
a := currLine[idx : idx+len(subject)]
|
||||||
if strings.Compare(string(a), subject) == 0 {
|
if strings.Compare(string(a), subject) == 0 {
|
||||||
for i := 0; i < len(subject); i++ {
|
for i := 0; i < len(subject); i++ {
|
||||||
if _, ok := matches[i+idx]; ok {
|
if _, ok := matches[i+idx]; ok {
|
||||||
@ -778,7 +781,7 @@ func (b *Buffer) renderAt(ctx *strife.Renderer, rx int, ry int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var x_col int
|
var x_col int
|
||||||
for idx, char := range source {
|
for idx, char := range currLine {
|
||||||
switch char {
|
switch char {
|
||||||
case '\n':
|
case '\n':
|
||||||
x_col = 0
|
x_col = 0
|
||||||
@ -811,5 +814,5 @@ func (b *Buffer) renderAt(ctx *strife.Renderer, rx int, ry int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (b *Buffer) OnRender(ctx *strife.Renderer) {
|
func (b *Buffer) OnRender(ctx *strife.Renderer) {
|
||||||
b.renderAt(ctx, b.x-(b.cam.x*last_w), b.y-(b.cam.y*last_h))
|
b.renderAt(ctx, b.x, b.y)
|
||||||
}
|
}
|
||||||
|
BIN
phi-editor
BIN
phi-editor
Binary file not shown.
Loading…
Reference in New Issue
Block a user