mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-12-12 17:27:50 +08:00
parent
32150672fc
commit
939bd0e505
|
@ -54,7 +54,7 @@ func (ed *Editor) prevHistory() bool {
|
|||
if ed.store != nil {
|
||||
// Persistent history
|
||||
upto := ed.cmdSeq + min(0, ed.history.current)
|
||||
i, line, err := ed.store.LastCmd(upto, ed.history.prefix)
|
||||
i, line, err := ed.store.LastCmd(upto, ed.history.prefix, true)
|
||||
if err == nil {
|
||||
ed.history.jump(i-ed.cmdSeq, line)
|
||||
return true
|
||||
|
@ -69,7 +69,7 @@ func (ed *Editor) nextHistory() bool {
|
|||
// Persistent history
|
||||
if ed.history.current < -1 {
|
||||
from := ed.cmdSeq + ed.history.current + 1
|
||||
i, line, err := ed.store.FirstCmd(from, ed.history.prefix)
|
||||
i, line, err := ed.store.FirstCmd(from, ed.history.prefix, true)
|
||||
if err == nil {
|
||||
ed.history.jump(i-ed.cmdSeq, line)
|
||||
return true
|
||||
|
|
|
@ -95,14 +95,14 @@ func convertCmd(row *sql.Row) (int, string, error) {
|
|||
|
||||
// LastCmd finds the last command before the given sequence number (exclusive)
|
||||
// with the given prefix.
|
||||
func (s *Store) LastCmd(upto int, prefix string) (int, string, error) {
|
||||
row := s.db.QueryRow(`select rowid, content from cmd where rowid < ? and substr(content, 1, ?) = ? order by rowid desc limit 1`, upto, len(prefix), prefix)
|
||||
func (s *Store) LastCmd(upto int, prefix string, uniq bool) (int, string, error) {
|
||||
row := s.db.QueryRow(`select rowid, content from cmd where rowid < ? and substr(content, 1, ?) = ? and (? or lastAmongDup) order by rowid desc limit 1`, upto, len(prefix), prefix, !uniq)
|
||||
return convertCmd(row)
|
||||
}
|
||||
|
||||
// FirstCmd finds the first command after the given sequence number (inclusive)
|
||||
// with the given prefix.
|
||||
func (s *Store) FirstCmd(from int, prefix string) (int, string, error) {
|
||||
row := s.db.QueryRow(`select rowid, content from cmd where rowid >= ? and substr(content, 1, ?) = ? order by rowid asc limit 1`, from, len(prefix), prefix)
|
||||
func (s *Store) FirstCmd(from int, prefix string, uniq bool) (int, string, error) {
|
||||
row := s.db.QueryRow(`select rowid, content from cmd where rowid >= ? and substr(content, 1, ?) = ? and (? or lastAmongDup) order by rowid asc limit 1`, from, len(prefix), prefix, !uniq)
|
||||
return convertCmd(row)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user