Skip to content

Commit 4599e22

Browse files
committed
Add adequate arrows-keys support
1 parent 0ef60c5 commit 4599e22

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

prompt.go

+13-17
Original file line numberDiff line numberDiff line change
@@ -151,13 +151,10 @@ func (p *Prompt) feed(b []byte) (shouldExit bool, exec *Exec) {
151151
p.buf = NewBuffer()
152152
p.history.Clear()
153153
case Up, ControlP:
154-
if !completing { // Don't use p.completion.Completing() because it takes double operation when switch to selected=-1.
155-
if p.renderer.reverseSearchEnabled {
156-
offsetCnt := strings.Count(p.history.lastReverseFinded, "\n") + 1
157-
p.history.lastReverseFinded = ""
158-
p.turnOffReverseSearch(offsetCnt)
159-
}
160-
154+
if p.renderer.reverseSearchEnabled {
155+
offsetCnt := strings.Count(p.history.lastReverseFinded, "\n") + 1
156+
p.turnOffReverseSearch(offsetCnt)
157+
} else if !completing { // Don't use p.completion.Completing() because it takes double operation when switch to selected=-1.
161158
// if this is a multiline buffer and the cursor is not at the top line,
162159
// then we just move up the cursor
163160
if p.buf.NewLineCount() > 0 && p.buf.Document().CursorPositionRow() > 0 {
@@ -168,17 +165,12 @@ func (p *Prompt) feed(b []byte) (shouldExit bool, exec *Exec) {
168165
p.prevText = p.buf.Text()
169166
p.buf = newBuf
170167
}
171-
172-
return
173168
}
174169
case Down, ControlN:
175-
if !completing { // Don't use p.completion.Completing() because it takes double operation when switch to selected=-1.
176-
if p.renderer.reverseSearchEnabled {
177-
offsetCnt := strings.Count(p.history.lastReverseFinded, "\n") + 1
178-
p.history.lastReverseFinded = ""
179-
p.turnOffReverseSearch(offsetCnt)
180-
}
181-
170+
if p.renderer.reverseSearchEnabled {
171+
offsetCnt := strings.Count(p.history.lastReverseFinded, "\n") + 1
172+
p.turnOffReverseSearch(offsetCnt)
173+
} else if !completing { // Don't use p.completion.Completing() because it takes double operation when switch to selected=-1.
182174
// if this is a multiline buffer and the cursor is not at the top line,
183175
// then we just move up the cursor
184176
// debug.Log(fmt.Sprintln("NewLineCount:", p.buf.NewLineCount()))
@@ -192,7 +184,11 @@ func (p *Prompt) feed(b []byte) (shouldExit bool, exec *Exec) {
192184
p.prevText = p.buf.Text()
193185
p.buf = newBuf
194186
}
195-
return
187+
}
188+
case Left, Right:
189+
if p.renderer.reverseSearchEnabled {
190+
offsetCnt := strings.Count(p.history.lastReverseFinded, "\n") + 1
191+
p.turnOffReverseSearch(offsetCnt)
196192
}
197193
case ControlD:
198194
if p.buf.Text() == "" {

0 commit comments

Comments
 (0)