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 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