Skip to content

Commit

Permalink
Merge pull request #48 from simeji/add-keymap-command
Browse files Browse the repository at this point in the history
Add Ctrl-U command and a query behavior.
  • Loading branch information
simeji authored Dec 14, 2016
2 parents 08cc7b3 + 82a5992 commit e0b9167
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ jid < file.json
|:-----------|:----------|
|`TAB` / `CTRL` + `I` |Show available items and choice them|
|`CTRL` + `W` |Delete from the cursor to the start of the word|
|`CTRL` + `U` |Delete whole query|
|`CTRL` + `F` / Right Arrow (:arrow_right:)|Move cursor a character to the right|
|`CTRL` + `B` / Left Arrow (:arrow_left:)|Move cursor a character to the left|
|`CTRL` + `A`|To the first character of the 'Filter'|
Expand Down
5 changes: 4 additions & 1 deletion cmd/jid/jid.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,12 @@ $ jid < file.json
TAB / CTRL-I
Show available items and choice them
CTRL-W
CTRL-W
Delete from the cursor to the start of the word
CTRL-U
Delete whole query
CTRL-F / Right Arrow
Move cursor a character to the right
Expand Down
14 changes: 14 additions & 0 deletions engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ func (e *Engine) Run() EngineResultInterface {
var contents []string

for {

if e.query.StringGet() == "" {
e.query.StringSet(".")
e.cursorOffsetX = len(e.query.StringGet())
}

contents = e.getContents()
e.setCandidateData()
e.queryConfirm = false
Expand Down Expand Up @@ -130,6 +136,8 @@ func (e *Engine) Run() EngineResultInterface {
e.scrollToBelow()
case termbox.KeyCtrlL:
e.toggleKeymode()
case termbox.KeyCtrlU:
e.deleteLineQuery()
case termbox.KeyCtrlW:
e.deleteWordBackward()
case termbox.KeyEsc:
Expand Down Expand Up @@ -196,6 +204,12 @@ func (e *Engine) deleteChar() {
e.cursorOffsetX -= 1
}
}

func (e *Engine) deleteLineQuery() {
_ = e.query.StringSet("")
e.cursorOffsetX = 0
}

func (e *Engine) scrollToBelow() {
e.contentOffset++
}
Expand Down
10 changes: 10 additions & 0 deletions engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,16 @@ func TestDeleteWordBackward(t *testing.T) {
assert.Equal(5, e.cursorOffsetX)
}

func TestDeleteLineQuery(t *testing.T) {
var assert = assert.New(t)
e := getEngine(`{"name":"go"}`, "")

e.query.StringSet(".name")
e.deleteLineQuery()
assert.Equal("", e.query.StringGet())
assert.Equal(0, e.cursorOffsetX)
}

func TestScrollToAbove(t *testing.T) {
var assert = assert.New(t)
e := getEngine(`{"named":"go","NameTest":[1,2,3]}`, "")
Expand Down

0 comments on commit e0b9167

Please sign in to comment.