editor_core 0.2.0 → 0.3.0

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
  SHA256:
3
- metadata.gz: ec52d9db82e48638cbc82762edbfc019f825beda5eafa66475f18254c69e1f4e
4
- data.tar.gz: 354a5ae6fb35b9bb195df0ace5c579a1643b61dbd0e8449ce7428c62b9fefd98
3
+ metadata.gz: 8bbf8d36bb4ce04088ab0a8343dffd83be278692e585c0d4e31999a3480d2e3a
4
+ data.tar.gz: 280aa2304b7495ff16202d2c49de3c72d6b9d509f93fa8d2f1a2ffca2402eecd
5
5
  SHA512:
6
- metadata.gz: 1d65ef8b4ca8ca3138a67e0684bd3f315569423d715fc6fff022edb2d1c3b717db1efedfb4892711992107056c9afe29e30114beef2fb7c4d3c5350ea3ea8ba1
7
- data.tar.gz: 483e3d2feb7dda1c78b5634612b92eb3f946c86921ae7898a81a3c73b665fd2d26c1edac0a724faed232b4ee190fcc1c3a1f37f72e979862132c95c400262775
6
+ metadata.gz: 796e196320ad8607cce128794403a764d277085461b40c24b4c61177e376816e886d52f8b66ec5b7cf2163ae9eeede6057ef3f36ad14b34af72bb262caebe6e2
7
+ data.tar.gz: c905cc8eb1acb375947adc5b9d36187c8c6522d489ae97b71ae8a989fd3dfcd7093a0ed1e0759a3c351e6374404d9c0f2bc592ae7774677c3896e27ccc9da1d7
data/README.md CHANGED
@@ -28,7 +28,11 @@ TODO: Write usage instructions here
28
28
 
29
29
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
30
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
31
+ To install this gem onto your local machine, run `bundle exec rake
32
+ install`. To release a new version, update the version number in
33
+ `version.rb`, and then run `bundle exec rake release`, which will create
34
+ a git tag for the version, push git commits and tags, and push the `.gem`
35
+ file to [rubygems.org](https://rubygems.org).
32
36
 
33
37
  ## Contributing
34
38
 
@@ -58,7 +58,7 @@ module EditorCore
58
58
 
59
59
  def page_down
60
60
  lines = view_down(view.height-1)
61
- @cursor = cursor.down(buffer, lines)
61
+ #@cursor = cursor.down(buffer, lines)
62
62
  end
63
63
 
64
64
  def page_up
@@ -70,6 +70,7 @@ module EditorCore
70
70
  oldtop = view.top
71
71
  view.top -= offset
72
72
  view.top = 0 if view.top < 0
73
+ up(offset)
73
74
  oldtop - view.top
74
75
  end
75
76
 
@@ -79,6 +80,7 @@ module EditorCore
79
80
  if view.top > buffer.lines_count
80
81
  view.top = buffer.lines_count
81
82
  end
83
+ down(offset)
82
84
  view.top - oldtop
83
85
  end
84
86
 
@@ -91,6 +93,8 @@ module EditorCore
91
93
  end
92
94
 
93
95
  # ## Complex navigation ##
96
+
97
+ # FIXME: Rewrite like prev_word
94
98
  def next_word
95
99
  line = current_line
96
100
  c = cursor.col
@@ -115,24 +119,40 @@ module EditorCore
115
119
  end
116
120
 
117
121
 
118
- def prev_word
119
- return if cursor.col == 0
120
- line = current_line
121
- c = cursor.col
122
- if c > 0
123
- c -= 1
124
- end
125
- while c > 0 && line[c] && line[c].match(/[ \t]/)
126
- c -= 1
122
+ def beginning_of_file?
123
+ cursor&.beginning_of_file?
124
+ end
125
+
126
+ def current_char
127
+ current_line[cursor.col]
128
+ end
129
+
130
+ def left_until_match(r)
131
+ off = -1
132
+ loop do
133
+ left
134
+ off +=1
135
+ break if beginning_of_file? || current_char&.match(r)
127
136
  end
128
- while c > 0 && !(line[c-1].match(/[ \t\-]/))
129
- c -= 1
137
+ off
138
+ end
139
+
140
+ def left_while_match(r)
141
+ off = 0
142
+ while !beginning_of_file? && current_char&.match(r)
143
+ left
144
+ off +=1
130
145
  end
131
- off = cursor.col - c
132
- @cursor = Cursor.new(cursor.row, c)
146
+ # Because we'll advance once too far left
147
+ right if !current_char&.match(r)
133
148
  off
134
149
  end
135
150
 
151
+ def prev_word
152
+ word = /[A-Za-z]/
153
+ left_until_match(word) + left_while_match(word)
154
+ end
155
+
136
156
  # ## Mutation ##
137
157
 
138
158
  def delete_before
@@ -1,3 +1,3 @@
1
1
  module EditorCore
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: editor_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vidar Hokstad
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-11-26 00:00:00.000000000 Z
11
+ date: 2021-11-28 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: