Class: Diakonos::LineMover
Instance Method Summary collapse
-
#initialize(buffer:) ⇒ LineMover
constructor
A new instance of LineMover.
- #move_selected_lines(direction:) ⇒ Object
Constructor Details
#initialize(buffer:) ⇒ LineMover
Returns a new instance of LineMover.
3 4 5 |
# File 'lib/diakonos/line-mover.rb', line 3 def initialize(buffer:) @buffer = buffer end |
Instance Method Details
#move_selected_lines(direction:) ⇒ Object
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 |
# 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 Buffer::TYPING @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 end |