Fix indent selection

This commit is contained in:
Vicente Bergas 2023-12-27 00:11:27 +01:00
parent 2d82362a66
commit caad5b4856

View file

@ -606,37 +606,32 @@ func (h *BufPane) Delete() bool {
// IndentSelection indents the current selection // IndentSelection indents the current selection
func (h *BufPane) IndentSelection() bool { func (h *BufPane) IndentSelection() bool {
if h.Cursor.HasSelection() { if !h.Cursor.HasSelection() {
start := h.Cursor.CurSelection[0] return false
end := h.Cursor.CurSelection[1] }
if end.Y < start.Y {
start, end = end, start
h.Cursor.SetSelectionStart(start)
h.Cursor.SetSelectionEnd(end)
}
startY := start.Y start := h.Cursor.CurSelection[0]
endY := end.Move(-1, h.Buf).Y end := h.Cursor.CurSelection[1]
endX := end.Move(-1, h.Buf).X if end.Y < start.Y {
tabsize := int(h.Buf.Settings["tabsize"].(float64)) start, end = end, start
indentsize := len(h.Buf.IndentString(tabsize)) h.Cursor.SetSelectionStart(start)
for y := startY; y <= endY; y++ { h.Cursor.SetSelectionEnd(end)
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 { end = end.Move(-1, h.Buf)
h.Cursor.SetSelectionStart(start.Move(indentsize, h.Buf)) tabsize := int(h.Buf.Settings["tabsize"].(float64))
} for y := start.Y; y <= end.Y; y++ {
if y == endY { if len(h.Buf.LineBytes(y)) > 0 {
h.Cursor.SetSelectionEnd(buffer.Loc{X: endX + indentsize + 1, Y: endY}) h.Buf.Insert(buffer.Loc{X: 0, Y: y}, h.Buf.IndentString(tabsize))
} if y == start.Y && start.X == 0 {
h.Cursor.SetSelectionStart(buffer.Loc{Y: start.Y})
} }
} }
h.Buf.RelocateCursors()
h.Relocate()
return true
} }
return false h.Buf.RelocateCursors()
h.Relocate()
return true
} }
// IndentLine moves the current line forward one indentation // IndentLine moves the current line forward one indentation