From ad91aa2b83168eb36b0506e16464e61ed41a802a Mon Sep 17 00:00:00 2001 From: Roi Martin Date: Fri, 18 Aug 2017 09:21:00 +0200 Subject: [PATCH] Refactoring of *View.writeRune --- edit.go | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/edit.go b/edit.go index 63e9332..ffa1b33 100644 --- a/edit.go +++ b/edit.go @@ -245,25 +245,24 @@ func (v *View) writeRune(x, y int, ch rune) error { v.lines = append(v.lines, s...) } - c := cell{ - fgColor: v.FgColor, - bgColor: v.BgColor, - chr: ch, - } - olen := len(v.lines[y]) + var s []cell if x >= len(v.lines[y]) { - s := make([]cell, x-len(v.lines[y])+1) - v.lines[y] = append(v.lines[y], s...) + s = make([]cell, x-len(v.lines[y])+1) } else if !v.Overwrite { - v.lines[y] = append(v.lines[y], c) + s = make([]cell, 1) } + v.lines[y] = append(v.lines[y], s...) if !v.Overwrite || (v.Overwrite && x >= olen-1) { copy(v.lines[y][x+1:], v.lines[y][x:]) } - v.lines[y][x] = c + v.lines[y][x] = cell{ + fgColor: v.FgColor, + bgColor: v.BgColor, + chr: ch, + } return nil }