ruco 0.0.27 → 0.0.28

Sign up to get free protection for your applications and to get access to all the features.
data/Readme.md CHANGED
@@ -7,7 +7,7 @@ Finished:
7
7
  - viewing / scrolling / editing / saving / creating
8
8
  - selecting via Shift+left/right/up/down and Ctrl+a(all)
9
9
  - Home/End + Page up/down
10
- - basic Tab support (tab == 2 space)
10
+ - Tab -> indent / Shift+Tab -> unindent (tab == 2 space)
11
11
  - change-indicator (*)
12
12
  - writable indicator (!)
13
13
  - backspace / delete
@@ -60,6 +60,7 @@ TIPS
60
60
  ====
61
61
  - [Ruby1.9] Unicode support -> install libncursesw5-dev before installing ruby (does not work for 1.8)
62
62
  - [ssh vs clipboard] access your desktops clipboard by installing `xauth` on the server and then using `ssh -X`
63
+ - [Alt key] if Alt does not work try your Meta/Win/Cmd key
63
64
 
64
65
  TODO
65
66
  =====
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.27
1
+ 0.0.28
@@ -64,7 +64,13 @@ module Ruco
64
64
  end
65
65
 
66
66
  # modify
67
- when :tab then @focused.insert("\t")
67
+ when :tab then
68
+ if @editor.selection
69
+ @editor.indent
70
+ else
71
+ @focused.insert("\t")
72
+ end
73
+ when :"Shift+tab" then @editor.unindent
68
74
  when :enter then
69
75
  @focused.insert("\n")
70
76
  when :backspace then @focused.delete(-1)
@@ -16,10 +16,20 @@ class String
16
16
  gsub!("\t",' ' * Ruco::TAB_SIZE)
17
17
  end
18
18
 
19
+ def leading_whitespace
20
+ match(/^\s*/)[0]
21
+ end
22
+
19
23
  # stub for 1.8
20
24
  unless method_defined?(:force_encoding)
21
25
  def force_encoding(encoding)
22
26
  self
23
27
  end
24
28
  end
29
+
30
+ unless method_defined?(:ord)
31
+ def ord
32
+ bytes.first
33
+ end
34
+ end
25
35
  end
data/lib/ruco/editor.rb CHANGED
@@ -3,7 +3,10 @@ module Ruco
3
3
  attr_reader :file
4
4
  attr_reader :text_area
5
5
  private :text_area
6
- delegate :view, :selection, :text_in_selection, :color_mask, :selecting, :move, :cursor, :resize, :to => :text_area
6
+ delegate :view, :color_mask, :cursor,
7
+ :selecting, :selection, :text_in_selection,
8
+ :move, :resize,
9
+ :to => :text_area
7
10
 
8
11
  def initialize(file, options)
9
12
  @file = file
@@ -33,6 +36,16 @@ module Ruco
33
36
  @modified = true
34
37
  end
35
38
 
39
+ def indent(*args)
40
+ text_area.indent(*args)
41
+ @modified = true
42
+ end
43
+
44
+ def unindent(*args)
45
+ text_area.unindent(*args)
46
+ @modified = true
47
+ end
48
+
36
49
  def delete(*args)
37
50
  text_area.delete(*args)
38
51
  @modified = true
data/lib/ruco/keyboard.rb CHANGED
@@ -56,6 +56,7 @@ class Keyboard
56
56
 
57
57
  # modify
58
58
  when 9 then :tab
59
+ when 353 then :"Shift+tab"
59
60
  when ENTER then :enter # shadows Ctrl+m
60
61
  when 263, 127 then :backspace # ubuntu / mac
61
62
  when Curses::KEY_DC then :delete
@@ -93,8 +93,8 @@ module Ruco
93
93
 
94
94
  text.tabs_to_spaces!
95
95
  if text == "\n" and @column >= after_last_word
96
- current_whitespace = current_line.match(/^\s*/)[0]
97
- next_whitespace = lines[@line+1].to_s.match(/^\s*/)[0]
96
+ current_whitespace = current_line.leading_whitespace
97
+ next_whitespace = lines[@line+1].to_s.leading_whitespace
98
98
  text = text + [current_whitespace, next_whitespace].max
99
99
  end
100
100
  insert_into_content text
@@ -120,11 +120,34 @@ module Ruco
120
120
  end
121
121
  end
122
122
 
123
+ # TODO should be on editor
123
124
  def delete_line
124
125
  lines.slice!(@line, 1)
125
126
  adjust_view
126
127
  end
127
128
 
129
+ # TODO should be on editor
130
+ def indent
131
+ selected_lines.each do |line|
132
+ @lines[line].insert(0, ' ' * Ruco::TAB_SIZE)
133
+ end
134
+ adjust_to_indentation Ruco::TAB_SIZE
135
+ adjust_view
136
+ end
137
+
138
+ # TODO should be on editor
139
+ def unindent
140
+ lines_to_unindent = (selection ? selected_lines : [@line])
141
+ removed = lines_to_unindent.map do |line|
142
+ remove = [@lines[line].leading_whitespace.size, Ruco::TAB_SIZE].min
143
+ @lines[line].slice!(0, remove)
144
+ remove
145
+ end
146
+
147
+ adjust_to_indentation -removed.first, -removed.last
148
+ adjust_view
149
+ end
150
+
128
151
  def cursor
129
152
  Cursor.new @cursor_line, @cursor_column
130
153
  end
@@ -294,5 +317,21 @@ module Ruco
294
317
  end_of_line = [line, last_visible_column]
295
318
  start_of_line..end_of_line
296
319
  end
320
+
321
+ def adjust_to_indentation(first, last=nil)
322
+ last ||= first
323
+ if selection
324
+ adjust_cursor = selection.first == position ? first : last
325
+ selection.first[1] = [selection.first[1] + first, 0].max
326
+ selection.last[1] = [selection.last[1] + last, 0].max
327
+ @column += adjust_cursor
328
+ else
329
+ @column += first
330
+ end
331
+ end
332
+
333
+ def selected_lines
334
+ selection.first[0].upto(selection.last[0])
335
+ end
297
336
  end
298
337
  end
data/ruco.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{ruco}
8
- s.version = "0.0.27"
8
+ s.version = "0.0.28"
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"]
@@ -154,6 +154,19 @@ describe Ruco::Application do
154
154
  app.key('c')
155
155
  editor_part(app.view).should == "a\ncb\n b"
156
156
  end
157
+
158
+ it "indents when tabbing on selection" do
159
+ write("ab")
160
+ app.key(:"Shift+right")
161
+ app.key(:tab)
162
+ editor_part(app.view).should == " ab\n\n"
163
+ end
164
+
165
+ it "unindents on Shift+tab" do
166
+ write(" ab\n cd\n")
167
+ app.key(:"Shift+tab")
168
+ editor_part(app.view).should == "ab\n cd\n"
169
+ end
157
170
  end
158
171
 
159
172
  describe '.ruco.rb' do
@@ -463,6 +463,121 @@ describe Ruco::Editor do
463
463
  end
464
464
  end
465
465
 
466
+ describe :indent do
467
+ it "indents selected lines" do
468
+ write("a\nb\nc\n")
469
+ editor.selecting{move(:to, 1,1)}
470
+ editor.indent
471
+ editor.view.should == " a\n b\nc\n"
472
+ end
473
+
474
+ it "moves the selection" do
475
+ write("a\nb\nc\n")
476
+ editor.selecting{move(:to, 1,1)}
477
+ editor.indent
478
+ editor.selection.should == ([0,2]..[1,3])
479
+ end
480
+
481
+ it "moves the cursor" do
482
+ write("a\nb\nc\n")
483
+ editor.selecting{move(:to, 1,1)}
484
+ editor.indent
485
+ editor.cursor.should == [1,3]
486
+ end
487
+
488
+ it "moves the cursor when selecting backward" do
489
+ write("a\nb\nc\n")
490
+ editor.move(:to, 1,1)
491
+ editor.selecting{move(:to, 0,1)}
492
+ editor.indent
493
+ editor.cursor.should == [0,3]
494
+ end
495
+
496
+ it "marks as modified" do
497
+ editor.selecting{move(:to, 0,1)}
498
+ editor.indent
499
+ editor.modified?.should == true
500
+ end
501
+ end
502
+
503
+ describe :unindent do
504
+ it "unindents single lines" do
505
+ write(" a\n\n")
506
+ editor.unindent
507
+ editor.view.should == " a\n\n\n"
508
+ end
509
+
510
+ it "unindents single lines by one" do
511
+ write(" a\n\n")
512
+ editor.unindent
513
+ editor.view.should == "a\n\n\n"
514
+ end
515
+
516
+ it "does not unindents single lines when not unindentable" do
517
+ write("a\n\n")
518
+ editor.unindent
519
+ editor.view.should == "a\n\n\n"
520
+ end
521
+
522
+ it "move the cursor when unindenting single line" do
523
+ write(" a\n\n")
524
+ editor.move(:to, 0,1)
525
+ editor.unindent
526
+ editor.cursor.should == [0,0]
527
+ end
528
+
529
+ it "unindents selected lines" do
530
+ write("a\n b\n c")
531
+ editor.selecting{ move(:to, 2,1) }
532
+ editor.unindent
533
+ editor.view.should == "a\nb\n c\n"
534
+ end
535
+
536
+ it "moves the selection" do
537
+ write(" abcd\n b\n c")
538
+ editor.move(:to, 0,3)
539
+ editor.selecting{ move(:to, 2,1) }
540
+ editor.unindent
541
+ editor.selection.should == ([0,1]..[2,0])
542
+ end
543
+
544
+ it "moves the selection when unindenting one space" do
545
+ write(" abcd\n b\n c")
546
+ editor.move(:to, 0,3)
547
+ editor.selecting{ move(:to, 2,1) }
548
+ editor.unindent
549
+ editor.selection.should == ([0,2]..[2,0])
550
+ end
551
+
552
+ it "does not move the selection when unindent is not possible" do
553
+ write("abcd\n b\n c")
554
+ editor.move(:to, 0,3)
555
+ editor.selecting{ move(:to, 2,1) }
556
+ editor.unindent
557
+ editor.selection.should == ([0,3]..[2,0])
558
+ end
559
+
560
+ it "moves the cursor when selecting forward" do
561
+ write("\n abcd\n")
562
+ editor.selecting{ move(:to, 1,3) }
563
+ editor.unindent
564
+ editor.cursor.should == [1,2]
565
+ end
566
+
567
+ it "moves the cursor when selecting backward" do
568
+ write(" x\n abcd\n")
569
+ editor.move(:to, 1,3)
570
+ editor.selecting{ move(:to, 0,1) }
571
+ editor.unindent
572
+ editor.cursor.should == [0,0]
573
+ end
574
+
575
+ it "marks as modified" do
576
+ editor.unindent
577
+ editor.modified?.should == true
578
+ end
579
+ end
580
+
466
581
  describe :save do
467
582
  it 'stores the file' do
468
583
  write('xxx')
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 27
9
- version: 0.0.27
8
+ - 28
9
+ version: 0.0.28
10
10
  platform: ruby
11
11
  authors:
12
12
  - Michael Grosser
@@ -89,7 +89,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
89
89
  requirements:
90
90
  - - ">="
91
91
  - !ruby/object:Gem::Version
92
- hash: 926649455
92
+ hash: 712420077
93
93
  segments:
94
94
  - 0
95
95
  version: "0"