Skip to content

Commit

Permalink
Merge pull request #36 from tjmtmmnk/backspace-ignore-cursor
Browse files Browse the repository at this point in the history
Backspace ignored cursor position
  • Loading branch information
ktr0731 authored Dec 25, 2020
2 parents 0d9e17e + 776f827 commit 0555829
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
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{
{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 │ │
> オレジ └────────────────────────────┘


0 comments on commit 0555829

Please sign in to comment.