Class: Redcar::FilterCommand::InsertOutput
- Inherits:
-
OutputFormat
- Object
- OutputFormat
- Redcar::FilterCommand::InsertOutput
- Defined in:
- lib/filter_command/formats/insert.rb
Overview
Output formats for inserting command output into a document. Currently supported formats are ‘Insert as Text’ and ‘Create new Document’
Instance Method Summary collapse
Methods inherited from OutputFormat
#edit_tab_focussed?, formats, #missing_edit_tab, #newline, supported_types, #tab, #type
Instance Method Details
#format(text, type) ⇒ Object
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 |
# File 'lib/filter_command/formats/insert.rb', line 10 def format text, type case type when "Insert as Text" if edit_tab_focussed? if doc = tab.edit_view.document if doc.selection? line = doc.line_at_offset(doc.selection_range.last) offset = doc.offset_at_line_end(line) else offset = doc.cursor_line_end_offset end unless doc.get_line(doc.line_at_offset(offset)).to_java.ends_with newline text = "#{newline}#{text}" end doc.insert(offset,text) doc.cursor_offset = offset + text.length end else missing_edit_tab(type) end when "Create new Document" win = Redcar.app.focussed_window tab = win.new_tab(Redcar::EditTab) tab.edit_view.document.text = text tab.edit_view.reset_undo tab.focus end end |