From 2ceffe31d6670839909ee813886ffd2d6b9130a9 Mon Sep 17 00:00:00 2001 From: tjmtmmnk Date: Wed, 2 Dec 2020 00:53:42 +0900 Subject: [PATCH 1/2] consider cursor when backspace press --- fuzzyfinder.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fuzzyfinder.go b/fuzzyfinder.go index 9677b4b..0974760 100644 --- a/fuzzyfinder.go +++ b/fuzzyfinder.go @@ -402,10 +402,10 @@ func (f *finder) readKey() error { if f.state.x == 0 { return nil } - // Remove the latest input rune. - f.state.cursorX -= runewidth.RuneWidth(f.state.input[len(f.state.input)-1]) + x := f.state.x + f.state.cursorX -= runewidth.RuneWidth(f.state.input[x-1]) f.state.x-- - f.state.input = f.state.input[0 : len(f.state.input)-1] + f.state.input = append(f.state.input[:x-1], f.state.input[x:]...) case tcell.KeyDelete: if f.state.x == len(f.state.input) { return nil From 776f827e94710bb1dff01b4f193e4d02e25a283e Mon Sep 17 00:00:00 2001 From: tjmtmmnk Date: Wed, 2 Dec 2020 00:53:52 +0900 Subject: [PATCH 2/2] add test --- fuzzyfinder_test.go | 4 ++++ .../fixtures/testfind-arrow_left_backspace.golden | 11 +++++++++++ 2 files changed, 15 insertions(+) create mode 100644 testdata/fixtures/testfind-arrow_left_backspace.golden diff --git a/fuzzyfinder_test.go b/fuzzyfinder_test.go index 99d62e4..fc0f7ec 100644 --- a/fuzzyfinder_test.go +++ b/fuzzyfinder_test.go @@ -143,6 +143,10 @@ func TestFind(t *testing.T) { {tcell.KeyBackspace2, rune(tcell.KeyBackspace2), tcell.ModNone}, {tcell.KeyBackspace2, rune(tcell.KeyBackspace2), tcell.ModNone}, }...)...)}, + "arrow left backspace": {append(runes("オレンジ"), keys([]input{ + {tcell.KeyLeft, rune(tcell.KeyLeft), tcell.ModNone}, + {tcell.KeyBackspace, rune(tcell.KeyBackspace), tcell.ModNone}, + }...)...)}, "delete": {append(runes("オレンジ"), keys([]input{ {tcell.KeyCtrlA, 'A', tcell.ModCtrl}, {tcell.KeyDelete, rune(tcell.KeyDelete), tcell.ModNone}, diff --git a/testdata/fixtures/testfind-arrow_left_backspace.golden b/testdata/fixtures/testfind-arrow_left_backspace.golden new file mode 100644 index 0000000..de9617e --- /dev/null +++ b/testdata/fixtures/testfind-arrow_left_backspace.golden @@ -0,0 +1,11 @@ + ┌────────────────────────────┐ + │ not found │ + │ │ + │ │ + │ │ + │ │ + │ │ + │ │ + 0/9 │ │ +> オレジ └────────────────────────────┘ + \ No newline at end of file