From 5da6b31b9c17f95e27194b378a848018bdade11d Mon Sep 17 00:00:00 2001 From: Zachary Yedidia Date: Tue, 2 Aug 2016 18:30:36 -0400 Subject: [PATCH] Pressing tab on a selection indents the selection See #203 --- cmd/micro/actions.go | 10 ++++++++++ cmd/micro/cursor.go | 1 - 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/cmd/micro/actions.go b/cmd/micro/actions.go index a8b8a7b8..58040a55 100644 --- a/cmd/micro/actions.go +++ b/cmd/micro/actions.go @@ -309,6 +309,16 @@ func (v *View) Delete() bool { func (v *View) InsertTab() bool { // Insert a tab if v.Cursor.HasSelection() { + if v.Cursor.CurSelection[0].Y != v.Cursor.CurSelection[1].Y { + for i := v.Cursor.CurSelection[0].Y; i <= v.Cursor.CurSelection[1].Y; i++ { + if settings["tabstospaces"].(bool) { + v.Buf.Insert(Loc{0, i}, Spaces(int(settings["tabsize"].(float64)))) + } else { + v.Buf.Insert(Loc{0, i}, "\t") + } + } + return true + } v.Cursor.DeleteSelection() v.Cursor.ResetSelection() } diff --git a/cmd/micro/cursor.go b/cmd/micro/cursor.go index 2caffae6..03ddf159 100644 --- a/cmd/micro/cursor.go +++ b/cmd/micro/cursor.go @@ -293,7 +293,6 @@ func (c *Cursor) Start() { func (c *Cursor) GetCharPosInLine(lineNum, visualPos int) int { // Get the tab size tabSize := int(settings["tabsize"].(float64)) - // This is the visual line -- every \t replaced with the correct number of spaces visualLineLen := StringWidth(c.buf.Line(lineNum)) if visualPos > visualLineLen { visualPos = visualLineLen