From 3252324d2486a38a86239398ae8ac112cb6c6a85 Mon Sep 17 00:00:00 2001 From: Zachary Yedidia Date: Sun, 26 Jan 2020 00:40:40 -0500 Subject: [PATCH] Don't indent empty lines Fixes #1472 --- internal/action/actions.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/internal/action/actions.go b/internal/action/actions.go index 5fe5c97d..7efb8135 100644 --- a/internal/action/actions.go +++ b/internal/action/actions.go @@ -549,12 +549,14 @@ func (h *BufPane) IndentSelection() bool { tabsize := int(h.Buf.Settings["tabsize"].(float64)) indentsize := len(h.Buf.IndentString(tabsize)) for y := startY; y <= endY; y++ { - h.Buf.Insert(buffer.Loc{X: 0, Y: y}, h.Buf.IndentString(tabsize)) - if y == startY && start.X > 0 { - h.Cursor.SetSelectionStart(start.Move(indentsize, h.Buf)) - } - if y == endY { - h.Cursor.SetSelectionEnd(buffer.Loc{X: endX + indentsize + 1, Y: endY}) + if len(h.Buf.LineBytes(y)) > 0 { + h.Buf.Insert(buffer.Loc{X: 0, Y: y}, h.Buf.IndentString(tabsize)) + if y == startY && start.X > 0 { + h.Cursor.SetSelectionStart(start.Move(indentsize, h.Buf)) + } + if y == endY { + h.Cursor.SetSelectionEnd(buffer.Loc{X: endX + indentsize + 1, Y: endY}) + } } } h.Buf.RelocateCursors()