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
|
# File 'lib/diakonos/line-mover.rb', line 7
def move_selected_lines(direction:)
case direction
when :up
from_row = start_row-1
return if from_row < 0
to_row = end_row-1
selection_delta = 0
when :down
from_row = end_row
to_row = start_row
return if to_row > @buffer.lines.count - 2
selection_delta = @buffer.selecting? ? 1 : 0
end
@buffer.take_snapshot(typing: true)
@buffer.lines.insert(
to_row,
@buffer.lines.delete_at(from_row)
)
if @buffer.selecting?
@buffer.set_selection to_row+selection_delta, 0, from_row+1+selection_delta, 0
@buffer.anchor_selection to_row+selection_delta
end
@buffer.go_to_line from_row+selection_delta
@buffer.set_modified modified_from_line: [to_row, from_row].min
end
|