fancy_buff 3.0.0 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/fancy_buff.rb +66 -23
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 24ca22ff6ce4b91274d9158e71ddb51dbf78ed644bdc4eb0affc665e8fc7b9a9
4
- data.tar.gz: 8027d3a0e02558e96a7f12c4746b6f9b9ca8b3e896c121d64fb1e841e08da65a
3
+ metadata.gz: 195debbfecfec78a6e9efe04ca6b0cb0dcb828f3cc0f9a957f8342422f00c925
4
+ data.tar.gz: 0e2b2635f5330e5b7dd08a1135a0810d1e38d6695d289598826b0618798303ea
5
5
  SHA512:
6
- metadata.gz: 7c9f91c3e37fded5bb22351c276a47d2d0baa03e516d1eaa7bbc1ebe1ae85b48e00610e7ef3c75d04ffa11d5907bf7e1fcfc82be1d34b3bca987a55dd93c8340
7
- data.tar.gz: c707b62adb80e8506aaaf03d67eb7913caeb98ca03faa8cd9a6839e9b8dabf7d70fa9e83d2b6d6a736195bf26ff81ff2d1b3d9f35df0dfd3d5902c625fca29e1
6
+ metadata.gz: 6b5cef70ff2eee10fd6f7cd33af401b36fcf7478f5493795fd694c6446b0a52d5f7a598bc112b83711204ab0c835d91d1b2b6535a3320f91228a7d6848c2e6de
7
+ data.tar.gz: 90ad2a3a7148f2669a7b1274d482ca08bd17d7068622ebc19aaf6d827c283b18c7da6fe217aba91e0c501e0419f8b49099bbfdffa1ef920d6abe11fee5342fac
data/lib/fancy_buff.rb CHANGED
@@ -40,10 +40,30 @@ class FancyBuff
40
40
  def win=(coords)
41
41
  @win = coords
42
42
 
43
- reset_caret!
43
+ adjust_caret!
44
44
  end
45
45
 
46
- def reset_caret!
46
+ # index of first visible column
47
+ def c
48
+ @win[0]
49
+ end
50
+
51
+ # index of first visible row
52
+ def r
53
+ @win[1]
54
+ end
55
+
56
+ # width of the buffer window
57
+ def w
58
+ @win[2]
59
+ end
60
+
61
+ # height of the buffer window
62
+ def h
63
+ @win[3]
64
+ end
65
+
66
+ def adjust_caret!
47
67
  cx, cy = @caret
48
68
  new_cx = if cx < c
49
69
  c
@@ -64,33 +84,56 @@ class FancyBuff
64
84
  @caret = [new_cx, new_cy]
65
85
  end
66
86
 
67
- def visual_caret
68
- [
69
- caret[0] - c + line_no_width + 1, # '+ 1' is to account for a space between line numbers and caret
70
- caret[1] - r
71
- ]
87
+ def adjust_win!
88
+ cx, cy = visual_caret
89
+ wx, wy = @win[0], @win[1]
90
+
91
+ new_wx = if cx > (c + w - 1)
92
+ wx + 1
93
+ elsif cx < 0
94
+ wx - 1
95
+ else
96
+ wx
97
+ end
98
+
99
+ new_wy = if cy > (r + h - 1)
100
+ wy + 1
101
+ elsif cy < 0
102
+ wy - 1
103
+ else
104
+ wy
105
+ end
106
+
107
+ @win[0] = wx
108
+ @win[1] = wy
72
109
  end
73
110
 
74
- # index of first visible column
75
- def c
76
- @win[0]
111
+ def caret_down!
112
+ @caret[1] = [caret[1] + 1, @lines.length - 1].min
113
+ adjust_win!
77
114
  end
78
115
 
79
- # index of first visible row
80
- def r
81
- @win[1]
116
+ def caret_up!
117
+ @caret[1] = [caret[1] - 1, 0].max
118
+ adjust_win!
82
119
  end
83
120
 
84
- # width of the buffer window
85
- def w
86
- @win[2]
121
+ def caret_left!
122
+ @caret[0] = [caret[0] - 1, 0].max
123
+ adjust_win!
87
124
  end
88
125
 
89
- # height of the buffer window
90
- def h
91
- @win[3]
126
+ def caret_right!
127
+ @caret[0] = [caret[0] + 1, @lines[caret[1]].length - 1].min
128
+ adjust_win!
92
129
  end
93
130
 
131
+ def visual_caret
132
+ [
133
+ caret[0] - c + line_no_width + 1, # '+ 1' is to account for a space between line numbers and caret
134
+ caret[1] - r
135
+ ]
136
+ end
94
137
  # returns an array of strings representing the visible characters from this
95
138
  # FancyBuffer's @rect
96
139
  def win_s
@@ -155,25 +198,25 @@ class FancyBuff
155
198
  # scrolls the visible window up
156
199
  def win_up!(n=1)
157
200
  @win[1] = [@win[1] - n, 0].max
158
- reset_caret!
201
+ adjust_caret!
159
202
  end
160
203
 
161
204
  # scrolls the visible window down
162
205
  def win_down!(n=1)
163
206
  @win[1] = [@win[1] + n, @lines.length - 1].min
164
- reset_caret!
207
+ adjust_caret!
165
208
  end
166
209
 
167
210
  # scrolls the visible window left
168
211
  def win_left!(n=1)
169
212
  @win[0] = [@win[0] - n, 0].max
170
- reset_caret!
213
+ adjust_caret!
171
214
  end
172
215
 
173
216
  # scrolls the visible window right
174
217
  def win_right!(n=1)
175
218
  @win[0] = [@win[0] + n, max_char_width - 1].min
176
- reset_caret!
219
+ adjust_caret!
177
220
  end
178
221
 
179
222
  # set a mark, as in the Vim sense
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fancy_buff
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Lunt