From 82a59920c49f7b387e38ee1963a3a7fda44e4de0 Mon Sep 17 00:00:00 2001 From: simeji Date: Thu, 15 Dec 2016 01:09:49 +0900 Subject: [PATCH] Add Ctrl-U command and a query behavior. force insert `.` --- README.md | 1 + cmd/jid/jid.go | 5 ++++- engine.go | 14 ++++++++++++++ engine_test.go | 10 ++++++++++ 4 files changed, 29 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2732d63..3001f4a 100644 --- a/README.md +++ b/README.md @@ -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'| diff --git a/cmd/jid/jid.go b/cmd/jid/jid.go index 5ad9169..bd07393 100644 --- a/cmd/jid/jid.go +++ b/cmd/jid/jid.go @@ -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 diff --git a/engine.go b/engine.go index 53e3bd2..b695cff 100644 --- a/engine.go +++ b/engine.go @@ -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 @@ -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: @@ -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++ } diff --git a/engine_test.go b/engine_test.go index 7f45917..1a37537 100644 --- a/engine_test.go +++ b/engine_test.go @@ -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]}`, "")