From 5f82ed85277dccf4ea5f44e920c42af642430b64 Mon Sep 17 00:00:00 2001 From: Bradley Cicenas Date: Mon, 12 Feb 2018 14:23:00 +0000 Subject: [PATCH] skip line erasing on render when window size is not yet available --- render.go | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/render.go b/render.go index 98daa16..fa67a31 100644 --- a/render.go +++ b/render.go @@ -154,7 +154,7 @@ func (r *Render) renderCompletion(buf *Buffer, completions *CompletionManager) { // +1 means a width of scrollbar. r.out.CursorBackward(width + 1) } - if d == 0 && len(prefix) + len(buf.Text()) != 0 { // the cursor is on right end. + if d == 0 && len(prefix)+len(buf.Text()) != 0 { // the cursor is on right end. // DON'T CURSOR DOWN HERE. Because the line doesn't erase properly. r.out.CursorForward(width + 1) } else if d+width > int(r.col) { @@ -168,18 +168,20 @@ func (r *Render) renderCompletion(buf *Buffer, completions *CompletionManager) { // Render renders to the console. func (r *Render) Render(buffer *Buffer, completion *CompletionManager) { + line := buffer.Text() prefix := r.getCurrentPrefix() - // Erasing - r.out.CursorBackward(int(r.col) + len(buffer.Text()) + len(prefix)) - r.out.EraseDown() + if r.col > 0 { + // Erasing + r.out.CursorBackward(int(r.col) + len(line) + len(prefix)) + r.out.EraseDown() - // prepare area - line := buffer.Text() - h := ((len(prefix) + len(line)) / int(r.col)) + 1 + int(completion.max) - if h > int(r.row) || completionMargin > int(r.col) { - r.renderWindowTooSmall() - return + // prepare area + h := ((len(prefix) + len(line)) / int(r.col)) + 1 + int(completion.max) + if h > int(r.row) || completionMargin > int(r.col) { + r.renderWindowTooSmall() + return + } } // Rendering