func (v *View) onDelete(a *buffer.Action) { v.onDeleteAdjustTopLine(a) if v.topLineNum+v.height() <= a.Cursor.LineNum { // deleted something below the view, don't care return } if a.Cursor.LineNum < v.topLineNum { // deletion above the top line if len(a.Lines) == 0 { return } _, last := a.DeletedLines() if last < v.topLineNum { // no need to worry v.cursor.LineNum -= len(a.Lines) v.dirty |= dirtyStatus return } } c := v.cursor c.OnDeleteAdjust(a) v.MoveCursorTo(c) v.lastCursorVoffset = v.cursorVoffset v.dirty = dirtyEverything }
func (v *View) onDeleteAdjustTopLine(a *buffer.Action) { if a.Cursor.LineNum < v.topLineNum { // deletion above the top line if len(a.Lines) == 0 { return } topnum := v.topLineNum first, last := a.DeletedLines() if first <= topnum && topnum <= last { // deleted the top line, adjust the pointers if a.Cursor.Line.Next != nil { v.topLine = a.Cursor.Line.Next v.topLineNum = a.Cursor.LineNum + 1 } else { v.topLine = a.Cursor.Line v.topLineNum = a.Cursor.LineNum } v.dirty = dirtyEverything } else { // no need to worry v.topLineNum -= len(a.Lines) v.dirty |= dirtyStatus } } }