feat: store current idx of history search

history-delete
sammyette 2023-11-11 21:14:47 -04:00
parent 504e9b272a
commit 856d3197d1
Signed by: sammyette
GPG Key ID: 904FC49417B44DCD
3 changed files with 10 additions and 3 deletions

View File

@ -121,6 +121,7 @@ func (g *CompletionGroup) writeMap(rl *Instance) (comp string) {
} }
description = g.Descriptions[g.Suggestions[i]] description = g.Descriptions[g.Suggestions[i]]
rl.lineCompDescription = description
if len(description) > maxLength { if len(description) > maxLength {
description = description[:maxLength-3] + "..." description = description[:maxLength-3] + "..."
} }

View File

@ -101,6 +101,7 @@ type Instance struct {
// Candidate / virtual completion string / etc // Candidate / virtual completion string / etc
currentComp []rune // The currently selected item, not yet a real part of the input line. currentComp []rune // The currently selected item, not yet a real part of the input line.
lineComp []rune // Same as rl.line, but with the currentComp inserted. lineComp []rune // Same as rl.line, but with the currentComp inserted.
lineCompDescription string
lineRemain []rune // When we complete in the middle of a line, we cut and keep the remain. lineRemain []rune // When we complete in the middle of a line, we cut and keep the remain.
compAddSpace bool // If true, any candidate inserted into the real line is done with an added space. compAddSpace bool // If true, any candidate inserted into the real line is done with an added space.

View File

@ -6,7 +6,10 @@ import (
"fmt" "fmt"
"os" "os"
"regexp" "regexp"
"strconv"
"syscall" "syscall"
ansi "github.com/acarl005/stripansi"
) )
var rxMultiline = regexp.MustCompile(`[\r\n]+`) var rxMultiline = regexp.MustCompile(`[\r\n]+`)
@ -838,10 +841,12 @@ func (rl *Instance) escapeSeq(r []rune) {
case seqCtrlDelete, seqCtrlDelete2, seqAltD: case seqCtrlDelete, seqCtrlDelete2, seqAltD:
if rl.searchMode == HistoryFind { if rl.searchMode == HistoryFind {
fmt.Println("\nCURRENT COMP\n", string(rl.lineComp), "\n\n\n") idx, err := strconv.Atoi(ansi.Strip(rl.lineCompDescription))
rl.resetVirtualComp(true) fmt.Println("\nCURRENT COMP\n", string(rl.lineComp), idx, "\n\n\n")
fmt.Println(idx, err)
rl.updateVirtualComp()
rl.renderHelpers() rl.updateHelpers()
rl.viUndoSkipAppend = true rl.viUndoSkipAppend = true
return return
} }