Class: Ruco::EditorArea

Inherits:
TextArea show all
Includes:
Ruco::Editor::Colors, 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

Constants included from Ruco::Editor::Colors

Ruco::Editor::Colors::DEFAULT_THEME, Ruco::Editor::Colors::STYLING_TIMEOUT

Constants inherited from TextArea

TextArea::SURROUNDING_CHARS

Instance Attribute Summary

Attributes included from Ruco::Editor::History

#history

Attributes inherited from TextArea

#column, #line, #lines, #selection

Instance Method Summary collapse

Methods included from Ruco::Editor::History

#initialize, #redo, #undo, #view

Methods included from Ruco::Editor::LineNumbers

#cursor, #initialize, #style_map, #view

Methods included from Ruco::Editor::Colors

#style_map

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_lineObject



9
10
11
12
# File 'lib/ruco/editor_area.rb', line 9

def delete_line
  lines.slice!(line, 1)
  sanitize_position
end

#indentObject



24
25
26
27
28
29
# File 'lib/ruco/editor_area.rb', line 24

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



14
15
16
17
18
19
20
21
22
# File 'lib/ruco/editor_area.rb', line 14

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

#stateObject



42
43
44
45
46
47
48
# File 'lib/ruco/editor_area.rb', line 42

def state
  {
    :content => content,
    :position => position,
    :screen_position => screen_position
  }
end

#state=(data) ⇒ Object



50
51
52
53
54
55
# File 'lib/ruco/editor_area.rb', line 50

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

#unindentObject



31
32
33
34
35
36
37
38
39
40
# File 'lib/ruco/editor_area.rb', line 31

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