Class: Redcar::FilterCommand::ReplaceInput

Inherits:
OutputFormat show all
Defined in:
lib/filter_command/formats/replace.rb

Overview

Output formats for replacing text in the current document Currently supported outputs are ‘Replace Selection’ and ‘Replace 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



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/filter_command/formats/replace.rb', line 9

def format text, type
  if edit_tab_focussed?
    case type
    when "Replace Selection"
      doc = tab.edit_view.document
      if doc.selection?
        doc.replace_selection text
      else
        text= text+newline unless text.to_java.ends_with newline
        doc.replace_line(doc.cursor_line,text)
      end
    when "Replace Document"
      tab.edit_view.document.text = text
    end
  else
    missing_edit_tab(type)
  end
end