Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backspace ignored cursor position #36

Merged
merged 2 commits into from
Dec 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions fuzzyfinder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions fuzzyfinder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

{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},
Expand Down
11 changes: 11 additions & 0 deletions testdata/fixtures/testfind-arrow_left_backspace.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
┌────────────────────────────┐
│ not found │
│ │
│ │
│ │
│ │
│ │
│ │
0/9 │ │
> オレジ └────────────────────────────┘