Class: Ruco::EditorArea
- Includes:
- Ruco::Editor::History, Ruco::Editor::LineNumbers
- Defined in:
- lib/ruco/editor_area.rb
Overview
everything that does not belong to a text-area but is needed for Ruco::Editor
Constant Summary
Constants included from Ruco::Editor::LineNumbers
Ruco::Editor::LineNumbers::LINE_NUMBERS_SPACE
Instance Attribute Summary
Attributes inherited from TextArea
#column, #line, #lines, #selection
Instance Method Summary collapse
- #delete_line ⇒ Object
- #indent ⇒ Object
- #move_line(direction) ⇒ Object
- #state ⇒ Object
- #state=(data) ⇒ Object
- #unindent ⇒ Object
Methods included from Ruco::Editor::History
#initialize, #redo, #undo, #view
Methods included from Ruco::Editor::LineNumbers
#cursor, #initialize, #style_map, #view
Methods inherited from TextArea
#content, #cursor, #delete, #index_for_position, #initialize, #insert, #move, #position, #reset, #resize, #selecting, #style_map, #text_in_selection, #view
Instance Method Details
#delete_line ⇒ Object
8 9 10 11 |
# File 'lib/ruco/editor_area.rb', line 8 def delete_line lines.slice!(line, 1) sanitize_position end |
#indent ⇒ Object
23 24 25 26 27 28 |
# File 'lib/ruco/editor_area.rb', line 23 def indent selected_lines.each do |line| lines[line].insert(0, ' ' * Ruco::TAB_SIZE) end adjust_to_indentation Ruco::TAB_SIZE end |
#move_line(direction) ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/ruco/editor_area.rb', line 13 def move_line(direction) old = line new = line + direction return if new < 0 return if new >= lines.size lines[old].leading_whitespace = lines[new].leading_whitespace lines[old], lines[new] = lines[new], lines[old] @line += direction end |
#state ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/ruco/editor_area.rb', line 41 def state { :content => content, :position => position, :screen_position => screen_position } end |
#state=(data) ⇒ Object
49 50 51 52 53 54 |
# File 'lib/ruco/editor_area.rb', line 49 def state=(data) @selection = nil @lines = data[:content].naive_split("\n") if data[:content] self.position = data[:position] self.screen_position = data[:screen_position] end |
#unindent ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/ruco/editor_area.rb', line 30 def unindent lines_to_unindent = (selection ? selected_lines : [line]) removed = lines_to_unindent.map do |line| remove = [lines[line].leading_whitespace.size, Ruco::TAB_SIZE].min lines[line].slice!(0, remove) remove end adjust_to_indentation -removed.first, -removed.last end |