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.
- checksums.yaml +4 -4
- data/lib/fancy_buff.rb +66 -23
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 195debbfecfec78a6e9efe04ca6b0cb0dcb828f3cc0f9a957f8342422f00c925
|
4
|
+
data.tar.gz: 0e2b2635f5330e5b7dd08a1135a0810d1e38d6695d289598826b0618798303ea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
43
|
+
adjust_caret!
|
44
44
|
end
|
45
45
|
|
46
|
-
|
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
|
68
|
-
|
69
|
-
|
70
|
-
|
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
|
-
|
75
|
-
|
76
|
-
|
111
|
+
def caret_down!
|
112
|
+
@caret[1] = [caret[1] + 1, @lines.length - 1].min
|
113
|
+
adjust_win!
|
77
114
|
end
|
78
115
|
|
79
|
-
|
80
|
-
|
81
|
-
|
116
|
+
def caret_up!
|
117
|
+
@caret[1] = [caret[1] - 1, 0].max
|
118
|
+
adjust_win!
|
82
119
|
end
|
83
120
|
|
84
|
-
|
85
|
-
|
86
|
-
|
121
|
+
def caret_left!
|
122
|
+
@caret[0] = [caret[0] - 1, 0].max
|
123
|
+
adjust_win!
|
87
124
|
end
|
88
125
|
|
89
|
-
|
90
|
-
|
91
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
219
|
+
adjust_caret!
|
177
220
|
end
|
178
221
|
|
179
222
|
# set a mark, as in the Vim sense
|