From 79349562b20d1109902513efa1ccbeb44492b5ba Mon Sep 17 00:00:00 2001 From: Zachary Yedidia Date: Sat, 20 Jan 2018 12:36:22 -0500 Subject: [PATCH] Improve unicode softwrap drawing Ref #1002 Ref #909 --- cmd/micro/cellview.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/cmd/micro/cellview.go b/cmd/micro/cellview.go index e8813a79..7a6c13cd 100644 --- a/cmd/micro/cellview.go +++ b/cmd/micro/cellview.go @@ -152,7 +152,9 @@ func (c *CellView) Draw(buf *Buffer, top, height, left, width int) { if colN == matchingBrace.X && lineN == matchingBrace.Y && !buf.Cursor.HasSelection() { st = curStyle.Reverse(true) } - c.lines[viewLine][viewCol] = &Char{Loc{viewCol, viewLine}, Loc{colN, lineN}, char, char, st, 1} + if viewCol < len(c.lines[viewLine]) { + c.lines[viewLine][viewCol] = &Char{Loc{viewCol, viewLine}, Loc{colN, lineN}, char, char, st, 1} + } } if char == '\t' { charWidth := tabsize - (viewCol+left)%tabsize @@ -171,7 +173,7 @@ func (c *CellView) Draw(buf *Buffer, top, height, left, width int) { for i := 1; i < charWidth; i++ { viewCol++ - if viewCol >= 0 && viewCol < lineLength { + if viewCol >= 0 && viewCol < lineLength && viewCol < len(c.lines[viewLine]) { c.lines[viewLine][viewCol] = &Char{Loc{viewCol, viewLine}, Loc{colN, lineN}, char, ' ', curStyle, 1} } } @@ -183,7 +185,7 @@ func (c *CellView) Draw(buf *Buffer, top, height, left, width int) { } for i := 1; i < charWidth; i++ { viewCol++ - if viewCol >= 0 && viewCol < lineLength { + if viewCol >= 0 && viewCol < lineLength && viewCol < len(c.lines[viewLine]) { c.lines[viewLine][viewCol] = &Char{Loc{viewCol, viewLine}, Loc{colN, lineN}, char, ' ', curStyle, 1} } }