Pressing tab on a selection indents the selection

See #203
This commit is contained in:
Zachary Yedidia 2016-08-02 18:30:36 -04:00
parent 204a763dff
commit 5da6b31b9c
2 changed files with 10 additions and 1 deletions

View file

@ -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()
}

View file

@ -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