1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
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()
}
|