package editor // MoveLineUp swaps the current line with the line above, keeping the cursor on // the moved line (same column). No-op at the top of the document. Returns true // if a swap happened (TASK-024). func (e *Editor) MoveLineUp() bool { r := e.Cursor.Row if r <= 0 { return false } e.Lines[r-1], e.Lines[r] = e.Lines[r], e.Lines[r-1] e.Cursor.Row = r - 1 e.afterMoveLine() return true } // MoveLineDown swaps the current line with the line below, keeping the cursor on // the moved line (same column). No-op at the bottom of the document. Returns // true if a swap happened (TASK-024). func (e *Editor) MoveLineDown() bool { r := e.Cursor.Row if r >= len(e.Lines)-1 { return false } e.Lines[r+1], e.Lines[r] = e.Lines[r], e.Lines[r+1] e.Cursor.Row = r + 1 e.afterMoveLine() return true } // afterMoveLine clamps the column to the moved line and refreshes editor state. func (e *Editor) afterMoveLine() { if n := len([]rune(e.Lines[e.Cursor.Row])); e.Cursor.Col > n { e.Cursor.Col = n } e.Dirty = true e.setGoal() e.followCursor() }