Fix indent selection
This commit is contained in:
parent
2d82362a66
commit
caad5b4856
1 changed files with 22 additions and 27 deletions
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue