InsertNewline inserts a newline plus possible some whitespace if autoindent is on
()
| 688 | |
| 689 | // InsertNewline inserts a newline plus possible some whitespace if autoindent is on |
| 690 | func (h *BufPane) InsertNewline() bool { |
| 691 | // Insert a newline |
| 692 | if h.Cursor.HasSelection() { |
| 693 | h.Cursor.DeleteSelection() |
| 694 | h.Cursor.ResetSelection() |
| 695 | } |
| 696 | |
| 697 | ws := util.GetLeadingWhitespace(h.Buf.LineBytes(h.Cursor.Y)) |
| 698 | cx := h.Cursor.X |
| 699 | h.Buf.Insert(h.Cursor.Loc, "\n") |
| 700 | // h.Cursor.Right() |
| 701 | |
| 702 | if h.Buf.Settings["autoindent"].(bool) { |
| 703 | if cx < len(ws) { |
| 704 | ws = ws[0:cx] |
| 705 | } |
| 706 | h.Buf.Insert(h.Cursor.Loc, string(ws)) |
| 707 | // for i := 0; i < len(ws); i++ { |
| 708 | // h.Cursor.Right() |
| 709 | // } |
| 710 | |
| 711 | // Remove the whitespaces if keepautoindent setting is off |
| 712 | if util.IsSpacesOrTabs(h.Buf.LineBytes(h.Cursor.Y-1)) && !h.Buf.Settings["keepautoindent"].(bool) { |
| 713 | line := h.Buf.LineBytes(h.Cursor.Y - 1) |
| 714 | h.Buf.Remove(buffer.Loc{X: 0, Y: h.Cursor.Y - 1}, buffer.Loc{X: util.CharacterCount(line), Y: h.Cursor.Y - 1}) |
| 715 | } |
| 716 | } |
| 717 | h.Cursor.StoreVisualX() |
| 718 | h.Relocate() |
| 719 | return true |
| 720 | } |
| 721 | |
| 722 | // Backspace deletes the previous character |
| 723 | func (h *BufPane) Backspace() bool { |
nothing calls this directly
no test coverage detected