The Delete key removes the character at the cursor rather than behind it - and at the end of a line, it pulls the next line up. Today you add forward deletion, backspace's mirror image.
Delete the character at the cursor; at the end of a line, delete the newline so the next line joins this one.
Forward delete is backspace reflected. Where backspace removes what is behind the
cursor, DeleteForward removes what is at it - the character the cursor sits on
Offset().The line-boundary case flips too: at the end of a line the character “at” the
cursor is really the newline that separates this line from the next, so deleting it
joins the following line onto this one, again with the cursor staying put. And at
the very end of the buffer there is nothing ahead to delete, so it is a no-op.
Notice both edits reuse the exact same Buf.Delete and line-join behavior from
chapter one - backspace and forward delete differ only in which offset they target
and whether the cursor moves. With these two, plus typing and Enter, the editor can
make any change to the text.
func (e *Editor) DeleteForward() {if e.Col < e.Buf.LineLen(e.Row) {e.Buf.Delete(e.Offset(), 1) // the char under the cursor} else if e.Row < e.Buf.LineCount()-1 {e.Buf.Delete(e.Offset(), 1) // the newline ahead -> join} // at the buffer's end: nothing to delete}