mirror of
https://github.com/zyedidia/micro.git
synced 2026-03-29 22:27:13 +09:00
Use the new cellview for displaying
Syntax highlighting is still not supported when using the new cellview.
This commit is contained in:
@@ -40,8 +40,8 @@ type CellView struct {
|
||||
lines [][]*Char
|
||||
}
|
||||
|
||||
func (c *CellView) Draw(buf *Buffer, start, top, height, left, width int) {
|
||||
tabsize := buf.Settings["tabsize"].(int)
|
||||
func (c *CellView) Draw(buf *Buffer, top, height, left, width int) {
|
||||
tabsize := int(buf.Settings["tabsize"].(float64))
|
||||
softwrap := buf.Settings["softwrap"].(bool)
|
||||
indentchar := []rune(buf.Settings["indentchar"].(string))[0]
|
||||
|
||||
@@ -61,23 +61,25 @@ func (c *CellView) Draw(buf *Buffer, start, top, height, left, width int) {
|
||||
|
||||
// We'll either draw the length of the line, or the width of the screen
|
||||
// whichever is smaller
|
||||
lineLength := min(len(line), width)
|
||||
lineLength := min(StringWidth(lineStr, tabsize), width)
|
||||
if len(c.lines[viewLine]) != lineLength {
|
||||
c.lines[viewLine] = make([]*Char, lineLength)
|
||||
}
|
||||
|
||||
wrap := false
|
||||
// We only need to wrap if the length of the line is greater than the width of the terminal screen
|
||||
if softwrap && len(line) > width {
|
||||
if softwrap && StringWidth(lineStr, tabsize) > width {
|
||||
wrap = true
|
||||
// We're going to draw the entire line now
|
||||
lineLength = len(line)
|
||||
lineLength = StringWidth(lineStr, tabsize)
|
||||
}
|
||||
|
||||
for viewCol < lineLength {
|
||||
if colN >= len(line) {
|
||||
break
|
||||
}
|
||||
char := line[colN]
|
||||
|
||||
colN++
|
||||
if char == '\t' {
|
||||
c.lines[viewLine][viewCol] = &Char{Loc{viewCol, viewLine}, Loc{colN, lineN}, indentchar, tcell.StyleDefault}
|
||||
// TODO: this always adds 4 spaces but it should really add just the remainder to the next tab location
|
||||
@@ -89,9 +91,17 @@ func (c *CellView) Draw(buf *Buffer, start, top, height, left, width int) {
|
||||
c.lines[viewLine][viewCol] = &Char{Loc{viewCol, viewLine}, Loc{colN, lineN}, char, tcell.StyleDefault}
|
||||
viewCol++
|
||||
}
|
||||
colN++
|
||||
|
||||
if wrap && viewCol > width {
|
||||
if wrap && viewCol >= width {
|
||||
viewLine++
|
||||
|
||||
nextLine := line[colN:]
|
||||
lineLength := min(StringWidth(string(nextLine), tabsize), width)
|
||||
if len(c.lines[viewLine]) != lineLength {
|
||||
c.lines[viewLine] = make([]*Char, lineLength)
|
||||
}
|
||||
|
||||
viewCol = 0
|
||||
|
||||
// If we go too far soft wrapping we have to cut off
|
||||
|
||||
Reference in New Issue
Block a user