MCPcopy
hub / github.com/micro-editor/micro / InsertNewline

Method InsertNewline

internal/action/actions.go:690–720  ·  view source on GitHub ↗

InsertNewline inserts a newline plus possible some whitespace if autoindent is on

()

Source from the content-addressed store, hash-verified

688
689// InsertNewline inserts a newline plus possible some whitespace if autoindent is on
690func (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
723func (h *BufPane) Backspace() bool {

Callers

nothing calls this directly

Calls 11

GetLeadingWhitespaceFunction · 0.92
IsSpacesOrTabsFunction · 0.92
CharacterCountFunction · 0.92
DeleteSelectionMethod · 0.80
ResetSelectionMethod · 0.80
StoreVisualXMethod · 0.80
LineBytesMethod · 0.65
RelocateMethod · 0.65
HasSelectionMethod · 0.45
InsertMethod · 0.45
RemoveMethod · 0.45

Tested by

no test coverage detected