Class: Ruco::EditorArea
Overview
everything that does not belong to a text-area but is needed for Ruco::Editor
Instance Attribute Summary
Attributes inherited from TextArea
#column, #line, #lines, #selection
Instance Method Summary
collapse
Methods inherited from TextArea
#content, #cursor, #delete, #index_for_position, #insert, #move, #reset, #resize, #selecting, #style_map, #text_in_selection
Constructor Details
#initialize(*args) ⇒ EditorArea
Returns a new instance of EditorArea.
5
6
7
8
|
# File 'lib/ruco/editor_area.rb', line 5
def initialize(*args)
super(*args)
@history = History.new((args.last[:history]||{}).reverse_merge(:state => state, :track => [:content], :entries => 100, :timeout => 2))
end
|
Instance Method Details
#delete_line ⇒ Object
25
26
27
28
|
# File 'lib/ruco/editor_area.rb', line 25
def delete_line
lines.slice!(line, 1)
sanitize_position
end
|
30
31
32
33
34
35
|
# File 'lib/ruco/editor_area.rb', line 30
def indent
selected_lines.each do |line|
lines[line].insert(0, ' ' * Ruco::TAB_SIZE)
end
adjust_to_indentation Ruco::TAB_SIZE
end
|
15
16
17
18
|
# File 'lib/ruco/editor_area.rb', line 15
def redo
@history.redo
self.state = @history.state
end
|
48
49
50
51
52
53
54
|
# File 'lib/ruco/editor_area.rb', line 48
def state
{
:content => content,
:position => position,
:screen_position => screen_position
}
end
|
#state=(data) ⇒ Object
56
57
58
59
60
61
|
# File 'lib/ruco/editor_area.rb', line 56
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
|
10
11
12
13
|
# File 'lib/ruco/editor_area.rb', line 10
def undo
@history.undo
self.state = @history.state
end
|
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/ruco/editor_area.rb', line 37
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
|
20
21
22
23
|
# File 'lib/ruco/editor_area.rb', line 20
def view
@history.add(state)
super
end
|