Skip to content

Commit 1fe54ef

Browse files
authored
Merge pull request #52 from simeji/develop
Add features : scroll to bottom and top
2 parents 82654b8 + d10e096 commit 1fe54ef

File tree

4 files changed

+40
-0
lines changed

4 files changed

+40
-0
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,10 @@ jid < file.json
108108
|`CTRL` + `E`|To the end of the 'Filter'|
109109
|`CTRL` + `J`|Scroll json buffer 1 line downwards|
110110
|`CTRL` + `K`|Scroll json buffer 1 line upwards|
111+
|`CTRL` + `G`|Scroll json buffer to bottom|
112+
|`CTRL` + `T`|Scroll json buffer to top|
111113
|`CTRL` + `L`|Change view mode whole json or keys (only object)|
114+
|`ESC`|Hide a candidate box|
112115

113116
### Option
114117

cmd/jid/jid.go

+9
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,17 @@ CTRL-J
104104
CTRL-K
105105
Scroll json buffer 1 line upwards
106106
107+
CTRL-G
108+
Scroll json buffer to bottom
109+
110+
CTRL-T
111+
Scroll json buffer to top
112+
107113
CTRL-L
108114
Change view mode whole json or keys (only object)
109115
116+
ESC
117+
Hide a candidate box
118+
110119
`
111120
}

engine.go

+18
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,13 @@ func (e *Engine) Run() EngineResultInterface {
101101
e.queryCursorIdx = e.query.Length()
102102
}
103103

104+
bl := len(contents)
104105
contents = e.getContents()
105106
e.setCandidateData()
106107
e.queryConfirm = false
108+
if bl != len(contents) {
109+
e.contentOffset = 0
110+
}
107111

108112
ta := &TerminalDrawAttributes{
109113
Query: e.query.StringGet(),
@@ -140,6 +144,10 @@ func (e *Engine) Run() EngineResultInterface {
140144
e.scrollToAbove()
141145
case termbox.KeyCtrlJ:
142146
e.scrollToBelow()
147+
case termbox.KeyCtrlG:
148+
e.scrollToBottom(len(contents))
149+
case termbox.KeyCtrlT:
150+
e.scrollToTop()
143151
case termbox.KeyCtrlL:
144152
e.toggleKeymode()
145153
case termbox.KeyCtrlU:
@@ -220,11 +228,21 @@ func (e *Engine) deleteLineQuery() {
220228
func (e *Engine) scrollToBelow() {
221229
e.contentOffset++
222230
}
231+
223232
func (e *Engine) scrollToAbove() {
224233
if o := e.contentOffset - 1; o >= 0 {
225234
e.contentOffset = o
226235
}
227236
}
237+
238+
func (e *Engine) scrollToBottom(rownum int) {
239+
e.contentOffset = rownum - 1
240+
}
241+
242+
func (e *Engine) scrollToTop() {
243+
e.contentOffset = 0
244+
}
245+
228246
func (e *Engine) toggleKeymode() {
229247
e.keymode = !e.keymode
230248
}

engine_test.go

+10
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,16 @@ func TestScrollToBelow(t *testing.T) {
103103
e.scrollToBelow()
104104
assert.Equal(3, e.contentOffset)
105105
}
106+
func TestScrollToBottomAndTop(t *testing.T) {
107+
var assert = assert.New(t)
108+
e := getEngine(`{"named":"go","NameTest":[1,2,3]}`, "")
109+
110+
e.scrollToBottom(5)
111+
assert.Equal(4, e.contentOffset)
112+
113+
e.scrollToTop()
114+
assert.Equal(0, e.contentOffset)
115+
}
106116

107117
func TestGetContents(t *testing.T) {
108118
var assert = assert.New(t)

0 commit comments

Comments
 (0)