Class: Redcar::Top::ChangeIndentCommand

Inherits:
DocumentCommand show all
Defined in:
plugins/redcar/redcar.rb

Direct Known Subclasses

DecreaseIndentCommand, IncreaseIndentCommand

Constant Summary

Constants included from Observable

Observable::ASPECTS

Instance Attribute Summary

Attributes inherited from Command

#error

Instance Method Summary (collapse)

Methods inherited from DocumentCommand

#_finished, #run_in_focussed_tab_edit_view

Methods inherited from Command

active_changed, #environment, inherited, #inspect, norecord, record?, #run

Methods included from Sensitive

#active?, #sensitivities, #sensitivity_names, #sensitize

Methods included from Observable

#add_listener, #notify_listeners, #remove_listener

Instance Method Details

- (Object) execute



284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
# File 'plugins/redcar/redcar.rb', line 284

def execute
  doc.compound do
    doc.edit_view.delay_parsing do
      indenters = edit_view.document.controllers(Redcar::AutoIndenter::DocumentController).first
      indenters.disable do
        if doc.selection?
          first_line_ix = doc.line_at_offset(doc.selection_range.begin)
          last_line_ix  = doc.line_at_offset(doc.selection_range.end)
          if doc.selection_range.end == doc.offset_at_line(last_line_ix)
            last_line_ix -= 1
          end
          first_line_ix.upto(last_line_ix) do |line_ix|
            indent_line(doc, line_ix)
          end
          start_selection = doc.offset_at_line(first_line_ix)
          if last_line_ix == doc.line_count - 1
            end_selection = doc.length
          else
            end_selection = doc.offset_at_line(last_line_ix + 1)
          end
          doc.set_selection_range(start_selection, end_selection)
        else
          indent_line(doc, doc.cursor_line)
        end
      end
    end
  end
end