ruco 0.0.34 → 0.0.35
Sign up to get free protection for your applications and to get access to all the features.
- data/Readme.md +0 -2
- data/VERSION +1 -1
- data/lib/ruco/editor.rb +7 -13
- data/lib/ruco/editor_area.rb +1 -1
- data/lib/ruco/history.rb +19 -2
- data/ruco.gemspec +2 -2
- data/spec/ruco/editor_spec.rb +2 -0
- data/spec/ruco/history_spec.rb +40 -0
- metadata +4 -4
data/Readme.md
CHANGED
@@ -58,8 +58,6 @@ TIPS
|
|
58
58
|
|
59
59
|
TODO
|
60
60
|
=====
|
61
|
-
- make modified smarter <-> no manual addition of every action
|
62
|
-
- make history more efficient (e.g. no need to check when only moving / store only diffs)
|
63
61
|
- limit possible file size to e.g. 1MB (would hang/be too slow with big files)
|
64
62
|
- find next (Alt+n)
|
65
63
|
- add selection colors to forms in command_bar
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.35
|
data/lib/ruco/editor.rb
CHANGED
@@ -4,6 +4,8 @@ module Ruco
|
|
4
4
|
attr_reader :text_area
|
5
5
|
private :text_area
|
6
6
|
delegate :view, :color_mask, :cursor,
|
7
|
+
:insert, :indent, :unindent, :delete, :delete_line,
|
8
|
+
:redo, :undo,
|
7
9
|
:selecting, :selection, :text_in_selection, :reset,
|
8
10
|
:move, :resize,
|
9
11
|
:to => :text_area
|
@@ -18,8 +20,8 @@ module Ruco
|
|
18
20
|
raise "#{@file} contains tabs.\nRuco atm does not support tabs, but will happily convert them to spaces if started with --convert-tabs or -c"
|
19
21
|
end
|
20
22
|
end
|
23
|
+
@saved_content = content
|
21
24
|
@text_area = EditorArea.new(content, options)
|
22
|
-
@modified = false
|
23
25
|
end
|
24
26
|
|
25
27
|
def find(text)
|
@@ -31,22 +33,14 @@ module Ruco
|
|
31
33
|
true
|
32
34
|
end
|
33
35
|
|
34
|
-
%w[insert indent unindent delete delete_line redo undo].each do |modifying|
|
35
|
-
eval <<-RUBY
|
36
|
-
def #{modifying}(*args)
|
37
|
-
text_area.#{modifying}(*args)
|
38
|
-
@modified = true
|
39
|
-
end
|
40
|
-
RUBY
|
41
|
-
end
|
42
|
-
|
43
36
|
def modified?
|
44
|
-
@
|
37
|
+
@saved_content != text_area.content
|
45
38
|
end
|
46
39
|
|
47
40
|
def save
|
48
|
-
|
49
|
-
@
|
41
|
+
content = text_area.content
|
42
|
+
File.open(@file,'w'){|f| f.write(content) }
|
43
|
+
@saved_content = content
|
50
44
|
end
|
51
45
|
end
|
52
46
|
end
|
data/lib/ruco/editor_area.rb
CHANGED
@@ -4,7 +4,7 @@ module Ruco
|
|
4
4
|
class EditorArea < TextArea
|
5
5
|
def initialize(*args)
|
6
6
|
super(*args)
|
7
|
-
@history = History.new(:state => state, :track => [:content], :entries => 100)
|
7
|
+
@history = History.new(:state => state, :track => [:content], :entries => 100, :timeout => 2)
|
8
8
|
end
|
9
9
|
|
10
10
|
def undo
|
data/lib/ruco/history.rb
CHANGED
@@ -1,8 +1,12 @@
|
|
1
1
|
module Ruco
|
2
2
|
class History
|
3
|
+
attr_accessor :timeout
|
4
|
+
|
3
5
|
def initialize(options)
|
4
6
|
@options = options
|
5
7
|
@stack = [@options.delete(:state)]
|
8
|
+
@timeout = options.delete(:timeout) || 0
|
9
|
+
timeout!
|
6
10
|
@position = 0
|
7
11
|
end
|
8
12
|
|
@@ -13,16 +17,21 @@ module Ruco
|
|
13
17
|
def add(state)
|
14
18
|
return unless tracked_field_changes?(state)
|
15
19
|
remove_undone_states
|
16
|
-
|
17
|
-
|
20
|
+
if merge_timeout?
|
21
|
+
@position += 1
|
22
|
+
@last_merge = Time.now.to_f
|
23
|
+
end
|
24
|
+
@stack[@position] = state
|
18
25
|
limit_stack
|
19
26
|
end
|
20
27
|
|
21
28
|
def undo
|
29
|
+
timeout!
|
22
30
|
@position = [@position - 1, 0].max
|
23
31
|
end
|
24
32
|
|
25
33
|
def redo
|
34
|
+
timeout!
|
26
35
|
@position = [@position + 1, @stack.size - 1].min
|
27
36
|
end
|
28
37
|
|
@@ -44,5 +53,13 @@ module Ruco
|
|
44
53
|
@stack.slice!(0, to_remove)
|
45
54
|
@position -= to_remove
|
46
55
|
end
|
56
|
+
|
57
|
+
def timeout!
|
58
|
+
@last_merge = Time.now.to_f - @timeout
|
59
|
+
end
|
60
|
+
|
61
|
+
def merge_timeout?
|
62
|
+
(Time.now.to_f - @last_merge) > @timeout
|
63
|
+
end
|
47
64
|
end
|
48
65
|
end
|
data/ruco.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{ruco}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.35"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Michael Grosser"]
|
12
|
-
s.date = %q{2011-01-
|
12
|
+
s.date = %q{2011-01-29}
|
13
13
|
s.default_executable = %q{ruco}
|
14
14
|
s.email = %q{michael@grosser.it}
|
15
15
|
s.executables = ["ruco"]
|
data/spec/ruco/editor_spec.rb
CHANGED
data/spec/ruco/history_spec.rb
CHANGED
@@ -74,4 +74,44 @@ describe Ruco::History do
|
|
74
74
|
history.undo
|
75
75
|
history.state.should == {:x => 3}
|
76
76
|
end
|
77
|
+
|
78
|
+
describe 'with timeout' do
|
79
|
+
let(:history){ Ruco::History.new(:state => {:x => 1}, :track => [:x], :entries => 3, :timeout => 0.1) }
|
80
|
+
|
81
|
+
it "adds fast changes" do
|
82
|
+
history.add(:x => 2)
|
83
|
+
history.add(:x => 3)
|
84
|
+
history.add(:x => 4)
|
85
|
+
history.undo
|
86
|
+
history.state.should == {:x => 1}
|
87
|
+
end
|
88
|
+
|
89
|
+
it "does not modify undone states" do
|
90
|
+
history.undo
|
91
|
+
history.state.should == {:x => 1}
|
92
|
+
history.add(:x => 4)
|
93
|
+
history.undo
|
94
|
+
history.state.should == {:x => 1}
|
95
|
+
end
|
96
|
+
|
97
|
+
it "does not modify redone states" do
|
98
|
+
history.add(:x => 2)
|
99
|
+
history.undo
|
100
|
+
sleep 0.2
|
101
|
+
history.redo
|
102
|
+
history.state.should == {:x => 2}
|
103
|
+
history.add(:x => 3)
|
104
|
+
history.undo
|
105
|
+
history.state.should == {:x => 2}
|
106
|
+
end
|
107
|
+
|
108
|
+
it "does not add slow changes" do
|
109
|
+
history.add(:x => 2)
|
110
|
+
history.add(:x => 3)
|
111
|
+
sleep 0.2
|
112
|
+
history.add(:x => 4)
|
113
|
+
history.undo
|
114
|
+
history.state.should == {:x => 3}
|
115
|
+
end
|
116
|
+
end
|
77
117
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruco
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 89
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 35
|
10
|
+
version: 0.0.35
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Michael Grosser
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-01-
|
18
|
+
date: 2011-01-29 00:00:00 +01:00
|
19
19
|
default_executable: ruco
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|