ruco 0.1.8 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
data/Readme.md CHANGED
@@ -15,7 +15,7 @@ Features:
15
15
  - stays at last position when reopening a file
16
16
  - opens file at line with `ruco foo/bar.rb:32` syntax
17
17
  - keeps whatever newline format you use (\r \n \r\n)
18
- - working backspace and delete key on Termial.app
18
+ - surrounds selection with quotes/braces (select abc + " --> "abc")
19
19
  - (optional) remove trailing whitespace on save
20
20
  - (optional) blank line before eof on save
21
21
  - (optional) line numbers
@@ -82,6 +82,7 @@ TIPS
82
82
 
83
83
  TODO
84
84
  =====
85
+ - do not fall back to 0:0 after undoing the first change
85
86
  - slow when opening file with 10,000+ short lines -> investigate
86
87
  - check writable status every x seconds (e.g. in background) -> faster while typing
87
88
  - search help e.g. 'Nothing found' '#4 of 6 hits' 'no more hits, start from beginning ?'
@@ -98,6 +99,7 @@ TODO
98
99
  - add auto-confirm to 'replace?' dialog -> type s == skip, no enter needed
99
100
  - 1.8: unicode support <-> already finished but unusable due to Curses (see encoding branch)
100
101
  - shorten long file names in the middle/start, not at the end
102
+ - add double quotes/braces when typing one + skip over quote/brace when its already typed at current position
101
103
 
102
104
  Authors
103
105
  =======
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.8
1
+ 0.1.9
@@ -13,7 +13,7 @@ def #{method}(*args, &block)
13
13
  end
14
14
  EOS
15
15
  end
16
- end
16
+ end unless defined? delegate
17
17
  end
18
18
 
19
19
  class Object
@@ -44,3 +44,9 @@ class Object
44
44
  end
45
45
  end
46
46
  end
47
+
48
+ class Object
49
+ def deep_copy
50
+ Marshal.load(Marshal.dump(self))
51
+ end unless defined? deep_copy
52
+ end
@@ -36,6 +36,12 @@ class String
36
36
  bytes.first
37
37
  end
38
38
  end
39
+
40
+ def surrounded_in?(*words)
41
+ first = words.first
42
+ last = words.last
43
+ slice(0,first.size) == first and slice(-last.size,last.size) == last
44
+ end
39
45
  end
40
46
 
41
47
  # http://grosser.it/2010/12/31/ruby-string-indexes-indices-find-all-indexes-in-a-string
@@ -1,5 +1,15 @@
1
1
  module Ruco
2
2
  class TextArea
3
+ SURROUNDING_CHARS = {
4
+ '<' => '>',
5
+ '(' => ')',
6
+ '[' => ']',
7
+ '{' => '}',
8
+ '"' => '"',
9
+ "'" => "'",
10
+ '/' => '/'
11
+ }
12
+
3
13
  attr_reader :lines, :selection, :column, :line
4
14
 
5
15
  def initialize(content, options)
@@ -78,7 +88,13 @@ module Ruco
78
88
  end
79
89
 
80
90
  def insert(text)
81
- delete_content_in_selection if @selection
91
+ if @selection
92
+ if SURROUNDING_CHARS[text]
93
+ return surround_selection_with(text)
94
+ else
95
+ delete_content_in_selection
96
+ end
97
+ end
82
98
 
83
99
  text.tabs_to_spaces!
84
100
  if text == "\n" and @column >= current_line.leading_whitespace.size
@@ -269,5 +285,22 @@ module Ruco
269
285
  sanitize_position
270
286
  @window.set_position(position, :max_lines => @lines.size)
271
287
  end
288
+
289
+ def surround_selection_with(text)
290
+ open_char = text
291
+ close_char = SURROUNDING_CHARS[text]
292
+ old_selection = @selection.deep_copy
293
+ selected = text_in_selection
294
+
295
+ replace_surrounding_chars = SURROUNDING_CHARS.any?{|chars| selected.surrounded_in?(*chars) }
296
+ if replace_surrounding_chars
297
+ selected = selected[1..-2]
298
+ else
299
+ old_selection.last.column += 2
300
+ end
301
+
302
+ insert("#{open_char}#{selected}#{close_char}")
303
+ @selection = old_selection
304
+ end
272
305
  end
273
306
  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.1.8"
8
+ s.version = "0.1.9"
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-08-05}
12
+ s.date = %q{2011-08-24}
13
13
  s.default_executable = %q{ruco}
14
14
  s.email = %q{michael@grosser.it}
15
15
  s.executables = ["ruco"]
@@ -14,4 +14,19 @@ describe String do
14
14
  "".naive_split('a').should == ['']
15
15
  end
16
16
  end
17
- end
17
+
18
+ describe :surrounded_in? do
19
+ [
20
+ ['aba','a',true],
21
+ ['abcab','ab',true],
22
+ ['acc','a',false],
23
+ ['cca','a',false],
24
+ ['(cca)',['(',')'],true],
25
+ ['(cca',['(',')'],false],
26
+ ].each do |text, word, success|
27
+ it "is #{success} for #{word} in #{text}" do
28
+ text.surrounded_in?(*[*word]).should == success
29
+ end
30
+ end
31
+ end
32
+ end
@@ -54,4 +54,100 @@ describe Ruco::TextArea do
54
54
  end
55
55
  end
56
56
  end
57
+
58
+ describe :insert do
59
+ let(:text){Ruco::TextArea.new("", :lines => 3, :columns => 10)}
60
+
61
+ describe "inserting surrounding characters" do
62
+ xit "does nothing special when pasting" do
63
+ text.insert("'bar'")
64
+ text.view.should == "'bar'\n\n"
65
+ text.cursor.should == [0,5]
66
+ end
67
+
68
+ xit "inserts a pair when just typing" do
69
+ text.insert("'")
70
+ text.view.should == "''\n\n"
71
+ text.cursor.should == [0,1]
72
+ end
73
+
74
+ xit "closes the surround if only char in surround" do
75
+ text.insert("'")
76
+ text.insert("'")
77
+ text.view.should == "''\n\n"
78
+ text.cursor.should == [0,2]
79
+ end
80
+
81
+ xit "overwrites next if its the same" do
82
+ text.insert("'bar'")
83
+ text.move(:relative, 0,-1)
84
+ text.insert("'")
85
+ text.view.should == "'bar'\n\n"
86
+ text.cursor.should == [0,5]
87
+ end
88
+
89
+ it "surrounds text when selecting" do
90
+ text.insert('bar')
91
+ text.move(:to, 0,0)
92
+ text.selecting{ move(:to, 0,2) }
93
+ text.insert("{")
94
+ text.view.should == "{ba}r\n\n"
95
+ text.cursor.should == [0,4]
96
+ end
97
+
98
+ it "does not surround text with closing char when selecting" do
99
+ text.insert('bar')
100
+ text.move(:to, 0,0)
101
+ text.selecting{ move(:to, 0,2) }
102
+ text.insert("}")
103
+ text.view.should == "}r\n\n"
104
+ text.cursor.should == [0,1]
105
+ end
106
+
107
+ it "replaces surrounding quotes" do
108
+ text.insert('"bar"')
109
+ text.move(:to, 0,0)
110
+ text.selecting{ move(:to, 0,5) }
111
+ text.insert("'")
112
+ text.view.should == "'bar'\n\n"
113
+ text.cursor.should == [0,5]
114
+ end
115
+
116
+ it "replace surrounding braces" do
117
+ text.insert('(bar)')
118
+ text.move(:to, 0,0)
119
+ text.selecting{ move(:to, 0,5) }
120
+ text.insert("'")
121
+ text.view.should == "'bar'\n\n"
122
+ text.cursor.should == [0,5]
123
+ end
124
+
125
+ it "does not replace when only one side has surrounding char" do
126
+ text.insert("\"bar\"")
127
+ text.move(:to, 0,0)
128
+ text.selecting{ move(:to, 0,3) }
129
+ text.insert("'")
130
+ text.view.should == "'\"ba'r\"\n\n"
131
+ text.cursor.should == [0,5]
132
+ end
133
+
134
+ it "expands selection when surrounding" do
135
+ text.insert('bar')
136
+ text.move(:to, 0,0)
137
+ text.selecting{ move(:to, 0,2) }
138
+ text.insert("{")
139
+ text.view.should == "{ba}r\n\n"
140
+ text.selection.should == ([0,0]..[0,4])
141
+ end
142
+
143
+ it "keeps selection when replacing surround" do
144
+ text.insert('"bar"')
145
+ text.move(:to, 0,0)
146
+ text.selecting{ move(:to, 0,5) }
147
+ text.insert("'")
148
+ text.view.should == "'bar'\n\n"
149
+ text.selection.should == ([0,0]..[0,5])
150
+ end
151
+ end
152
+ end
57
153
  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: 11
4
+ hash: 9
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 8
10
- version: 0.1.8
9
+ - 9
10
+ version: 0.1.9
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-08-05 00:00:00 +02:00
18
+ date: 2011-08-24 00:00:00 +02:00
19
19
  default_executable: ruco
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency