vedeu 0.6.46 → 0.6.47

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1ff740a5d8a382dc5f6e01353c52fc4c8785934d
4
- data.tar.gz: fdf167026d1ab0633c6e7dbc17e4f13c6ead54c7
3
+ metadata.gz: 9cde5fb2877e792b48f59abe6f024102949acc50
4
+ data.tar.gz: eb2865895d814e117ddcba9b4f1c33126e6e337f
5
5
  SHA512:
6
- metadata.gz: ecd1e62df7d6590cb80d159f749622495eab7984c34f3f880afdfa71ab1e790070915d09702e60d02778120d10c4b80cff864aced98e3cdf9882b922ea8a6d18
7
- data.tar.gz: 8b72b7cf6dea8fb4c4343405f295c68f67b920ddf4574d95ba06cb2360066b4d6462d850c471804bdc15d96dba12c6fcc66b4ba624e9e6946d499b1059173734
6
+ metadata.gz: 5d248827101d024fed9e434ea22bcf19ebbf7e810a6d7b122b7f94c9379e6b97ca98866dcbc60af52ff4e511bbc100f438e3f6caf031a440466e2ac3fd67758b
7
+ data.tar.gz: b87c4f2e854d3b7ecf0a2faca524fd9fef494b79502fe358a270ef264ee223f4f58523d39f930138c92207553068009286bca535a71e7f837efa2be6445a058c
data/.travis.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.2.2
3
+ - 2.2.3
4
4
  cache: bundler
5
5
  script: 'bundle exec rake'
6
6
  sudo: false
@@ -33,7 +33,7 @@ class EditorApp
33
33
  end
34
34
  end
35
35
 
36
- # When pressing Return/Enter in the editor view, the :_command_
36
+ # When pressing Escape in the editor view, the :_command_
37
37
  # event will be triggered with any typed content you have provided.
38
38
  #
39
39
  # The :_command_ event in turn triggers the :command event. Bind to
@@ -45,7 +45,8 @@ class EditorApp
45
45
  # end
46
46
  #
47
47
  Vedeu.keymap :editor_view do
48
- key(:enter) { Vedeu.trigger(:_editor_execute_, :editor_view) }
48
+ key(:escape) { Vedeu.trigger(:_editor_execute_, :editor_view) }
49
+ key(:enter) { Vedeu.trigger(:_editor_insert_line_, :editor_view) }
49
50
  key(:insert) do
50
51
  Vedeu.log(type: :debug,
51
52
  message: "Commands: #{Vedeu.all_commands.inspect}")
@@ -67,7 +68,7 @@ class EditorApp
67
68
  view(:help_view) do
68
69
  lines do
69
70
  line 'Type into the editor dialog above,'
70
- line 'and press Return. This will trigger the'
71
+ line 'and press Escape. This will trigger the'
71
72
  line ':command event with the contents of '
72
73
  line 'the view.'
73
74
 
@@ -10,6 +10,7 @@ end # Vedeu
10
10
 
11
11
  require 'vedeu/editor/capture'
12
12
  require 'vedeu/editor/cropper'
13
+ require 'vedeu/editor/delete'
13
14
  require 'vedeu/editor/editor'
14
15
  require 'vedeu/editor/insert'
15
16
  require 'vedeu/editor/line'
@@ -0,0 +1,65 @@
1
+ module Vedeu
2
+
3
+ module Editor
4
+
5
+ # Manipulate the lines of an Vedeu::Editor::Document.
6
+ #
7
+ class Delete
8
+
9
+ # @param (see #initialize)
10
+ # @return [Vedeu::Editor::Line|Vedeu::Editor::Lines]
11
+ def self.from(collection, index = nil, size = 0)
12
+ new(collection, index, size).delete
13
+ end
14
+
15
+ # Returns a new instance of Vedeu::Editor::Delete.
16
+ #
17
+ # @param collection [Vedeu::Editor::Line|Vedeu::Editor::Lines]
18
+ # @param index [Fixnum]
19
+ # @param size [Fixnum]
20
+ # @return [Vedeu::Editor::Delete]
21
+ def initialize(collection, index = nil, size = 0)
22
+ @collection = collection
23
+ @index = index
24
+ @size = size
25
+ end
26
+
27
+ # @return [Vedeu::Editor::Line|Vedeu::Editor::Lines]
28
+ def delete
29
+ return collection.dup.tap { |c| c.slice!(index) } if index
30
+
31
+ if collection.is_a?(Array)
32
+ collection.dup.tap(&:pop)
33
+
34
+ elsif collection.is_a?(String)
35
+ collection.chop
36
+
37
+ end
38
+ end
39
+
40
+ protected
41
+
42
+ # @!attribute [r] collection
43
+ # @return [Vedeu::Editor::Line|Vedeu::Editor::Lines]
44
+ attr_reader :collection
45
+
46
+ # @!attribute [r] size
47
+ # @return [Fixnum]
48
+ attr_reader :size
49
+
50
+ private
51
+
52
+ # @return [Fixnum]
53
+ def index
54
+ return nil unless @index
55
+
56
+ @index = 0 if @index < 0
57
+ @index = size - 1 if @index > size
58
+ @index
59
+ end
60
+
61
+ end # Delete
62
+
63
+ end # Editor
64
+
65
+ end # Vedeu
@@ -60,12 +60,16 @@ module Vedeu
60
60
  elsif x - 1 < 0 && y > 0
61
61
  delete_line
62
62
 
63
+ return
64
+
63
65
  else
64
66
  @lines = lines.delete_character(y, x - 1)
65
67
 
66
68
  left
67
69
 
68
70
  end
71
+
72
+ refresh
69
73
  end
70
74
 
71
75
  # Delete a line.
@@ -68,15 +68,8 @@ module Vedeu
68
68
  def delete_character(index = nil)
69
69
  return self if line.empty? || (index && index < 0)
70
70
 
71
- new_line = if index && index <= size
72
- line.dup.tap { |line| line.slice!(index) }
73
-
74
- else
75
- line.chop
76
-
77
- end
78
-
79
- Vedeu::Editor::Line.coerce(new_line)
71
+ Vedeu::Editor::Line.coerce(Vedeu::Editor::Delete
72
+ .from(line, index, size))
80
73
  end
81
74
 
82
75
  # Returns a boolean indicating whether there are characters on
@@ -73,15 +73,8 @@ module Vedeu
73
73
  def delete_line(index = nil)
74
74
  return self if lines.empty? || (index && index < 0)
75
75
 
76
- new_lines = if index && index <= size
77
- lines.dup.tap { |lines| lines.slice!(index) }
78
-
79
- else
80
- lines.dup.tap(&:pop)
81
-
82
- end
83
-
84
- Vedeu::Editor::Lines.coerce(new_lines)
76
+ Vedeu::Editor::Lines.coerce(Vedeu::Editor::Delete
77
+ .from(lines, index, size))
85
78
  end
86
79
 
87
80
  # Provides iteration over the collection.
data/lib/vedeu/version.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Vedeu
2
2
 
3
3
  # The current version of Vedeu.
4
- VERSION = '0.6.46'.freeze
4
+ VERSION = '0.6.47'.freeze
5
5
 
6
6
  end
@@ -0,0 +1,88 @@
1
+ require 'test_helper'
2
+
3
+ module Vedeu
4
+
5
+ module Editor
6
+
7
+ describe Delete do
8
+
9
+ let(:described) { Vedeu::Editor::Delete }
10
+ let(:instance) { described.new(collection, index, size) }
11
+ let(:collection) {}
12
+ let(:index) {}
13
+ let(:size) {}
14
+
15
+ describe '#initialize' do
16
+ it { instance.must_be_instance_of(described) }
17
+ it { instance.instance_variable_get('@collection').must_equal(collection) }
18
+ it { instance.instance_variable_get('@index').must_equal(index) }
19
+ it { instance.instance_variable_get('@size').must_equal(size) }
20
+ end
21
+
22
+ describe '.from' do
23
+ subject { described.from(collection, index, size) }
24
+
25
+ context 'when the collection is a String' do
26
+ let(:collection) { 'Some text' }
27
+
28
+ context 'when an index is given' do
29
+ let(:index) { 2 }
30
+ let(:size) { collection.size }
31
+
32
+ it { subject.must_equal('Soe text') }
33
+
34
+ context 'when the index > size' do
35
+ let(:index) { size + 3 }
36
+
37
+ it { subject.must_equal('Some tex') }
38
+ end
39
+
40
+ context 'when the index < 0' do
41
+ let(:index) { -3 }
42
+
43
+ it { subject.must_equal('ome text') }
44
+ end
45
+ end
46
+
47
+ context 'when an index is not given' do
48
+ it { subject.must_equal('Some tex') }
49
+ end
50
+ end
51
+
52
+ context 'when the collection is an Array' do
53
+ let(:collection) { [:hydrogen, :helium, :lithium, :beryllium] }
54
+
55
+ context 'when an index is given' do
56
+ let(:index) { 2 }
57
+ let(:size) { collection.size }
58
+
59
+ it { subject.must_equal([:hydrogen, :helium, :beryllium]) }
60
+
61
+ context 'when the index > size' do
62
+ let(:index) { size + 3 }
63
+
64
+ it { subject.must_equal([:hydrogen, :helium, :lithium]) }
65
+ end
66
+
67
+ context 'when the index < 0' do
68
+ let(:index) { -3 }
69
+
70
+ it { subject.must_equal([:helium, :lithium, :beryllium]) }
71
+ end
72
+ end
73
+
74
+ context 'when an index is not given' do
75
+ it { subject.must_equal([:hydrogen, :helium, :lithium]) }
76
+ end
77
+ end
78
+ end
79
+
80
+ describe '#delete' do
81
+ it { instance.must_respond_to(:delete) }
82
+ end
83
+
84
+ end # Delete
85
+
86
+ end # Editor
87
+
88
+ end # Vedeu
@@ -78,10 +78,10 @@ module Vedeu
78
78
  describe '#delete_character' do
79
79
  subject { instance.delete_character }
80
80
 
81
- it { subject.must_be_instance_of(Vedeu::Editor::Cursor) }
81
+ it { subject.must_be_instance_of(Vedeu::Editor::Document) }
82
82
 
83
83
  context 'when on the first column of the first row' do
84
- it { subject.must_be_instance_of(Vedeu::Editor::Cursor) }
84
+ it { subject.must_be_instance_of(Vedeu::Editor::Document) }
85
85
  end
86
86
 
87
87
  context 'when on the first column of not the first row' do
data/vedeu.gemspec CHANGED
@@ -24,7 +24,7 @@ Gem::Specification.new do |spec|
24
24
  spec.add_development_dependency 'guard-minitest', '2.4.4'
25
25
  spec.add_development_dependency 'guard-rubocop', '1.2.0'
26
26
  spec.add_development_dependency 'minitest', '5.8.2'
27
- spec.add_development_dependency 'minitest-reporters', '1.1.4'
27
+ spec.add_development_dependency 'minitest-reporters', '1.1.5'
28
28
  spec.add_development_dependency 'mocha', '1.1.0'
29
29
  spec.add_development_dependency 'pry', '0.10.3'
30
30
  spec.add_development_dependency 'rubocop', '0.34.2'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vedeu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.46
4
+ version: 0.6.47
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gavin Laking
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - '='
74
74
  - !ruby/object:Gem::Version
75
- version: 1.1.4
75
+ version: 1.1.5
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - '='
81
81
  - !ruby/object:Gem::Version
82
- version: 1.1.4
82
+ version: 1.1.5
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: mocha
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -383,6 +383,7 @@ files:
383
383
  - lib/vedeu/editor/capture.rb
384
384
  - lib/vedeu/editor/cropper.rb
385
385
  - lib/vedeu/editor/cursor.rb
386
+ - lib/vedeu/editor/delete.rb
386
387
  - lib/vedeu/editor/document.rb
387
388
  - lib/vedeu/editor/editor.rb
388
389
  - lib/vedeu/editor/insert.rb
@@ -560,6 +561,7 @@ files:
560
561
  - test/lib/vedeu/editor/capture_test.rb
561
562
  - test/lib/vedeu/editor/cropper_test.rb
562
563
  - test/lib/vedeu/editor/cursor_test.rb
564
+ - test/lib/vedeu/editor/delete_test.rb
563
565
  - test/lib/vedeu/editor/document_test.rb
564
566
  - test/lib/vedeu/editor/editor_test.rb
565
567
  - test/lib/vedeu/editor/insert_test.rb
@@ -762,6 +764,7 @@ test_files:
762
764
  - test/lib/vedeu/editor/capture_test.rb
763
765
  - test/lib/vedeu/editor/cropper_test.rb
764
766
  - test/lib/vedeu/editor/cursor_test.rb
767
+ - test/lib/vedeu/editor/delete_test.rb
765
768
  - test/lib/vedeu/editor/document_test.rb
766
769
  - test/lib/vedeu/editor/editor_test.rb
767
770
  - test/lib/vedeu/editor/insert_test.rb