Skip to content

Commit

Permalink
Filter the keys only when the prompt is updated
Browse files Browse the repository at this point in the history
  • Loading branch information
slarwise committed Aug 7, 2024
1 parent 46a68e9 commit cf639ec
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,13 @@ func main() {
defer quit()
_, height := screen.Size()
prompt := ""
nextPrompt := ""
selectedIndex := 0
drawPrompt(screen, height, prompt)
drawLoadingScreen(screen, height)
screen.Show()
keys := getKeys(vault, DirEnt{IsDir: true, Name: "/"})
filteredKeys = keys
for {
ev := screen.PollEvent()
switch ev := ev.(type) {
Expand All @@ -129,24 +131,27 @@ func main() {
return
case tcell.KeyBackspace, tcell.KeyBackspace2:
if len(prompt) > 0 {
prompt = prompt[:len(prompt)-1]
nextPrompt = prompt[:len(prompt)-1]
}
case tcell.KeyCtrlU:
prompt = ""
nextPrompt = ""
case tcell.KeyCtrlK, tcell.KeyCtrlP:
selectedIndex = min(len(filteredKeys)-1, selectedIndex+1)
case tcell.KeyCtrlJ, tcell.KeyCtrlN:
selectedIndex = max(0, selectedIndex-1)
case tcell.KeyRune:
prompt += string(ev.Rune())
nextPrompt += string(ev.Rune())
selectedIndex = 0
}
}
width, height := screen.Size()
filteredKeys = []string{}
for _, k := range keys {
if strings.Contains(k, prompt) {
filteredKeys = append(filteredKeys, k)
if nextPrompt != prompt {
prompt = nextPrompt
filteredKeys = []string{}
for _, k := range keys {
if strings.Contains(k, prompt) {
filteredKeys = append(filteredKeys, k)
}
}
}
screen.Clear()
Expand Down

0 comments on commit cf639ec

Please sign in to comment.