mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-12-13 01:47:51 +08:00
pkg/edit: Fix race conditions.
This commit is contained in:
parent
b18b833acb
commit
c2c6254316
|
@ -66,7 +66,7 @@ func Start(app cli.App, cfg Config) {
|
|||
if cfg.Binding == nil {
|
||||
cfg.Binding = cli.DummyHandler{}
|
||||
}
|
||||
cursor := histutil.NewDedupCursor(cfg.Store.Cursor(cfg.Prefix))
|
||||
cursor := cfg.Store.Cursor(cfg.Prefix)
|
||||
cursor.Prev()
|
||||
_, err := cursor.Get()
|
||||
if err != nil {
|
||||
|
|
|
@ -21,8 +21,8 @@ func TestHistWalk(t *testing.T) {
|
|||
|
||||
getCfg := func() Config {
|
||||
store := histutil.NewMemStore(
|
||||
// 0 1 2 3 4 5
|
||||
"echo", "ls -l", "echo a", "ls -a", "echo a", "ls -a")
|
||||
// 0 1 2 3 4 5
|
||||
"echo", "ls -l", "echo a", "echo", "echo a", "ls -a")
|
||||
return Config{
|
||||
Store: store,
|
||||
Prefix: "ls",
|
||||
|
@ -45,7 +45,6 @@ func TestHistWalk(t *testing.T) {
|
|||
f.TTY.TestBuffer(t, buf5)
|
||||
|
||||
f.TTY.Inject(term.K(ui.Up))
|
||||
// Skips item #3 as it is a duplicate.
|
||||
buf1 := f.MakeBuffer(
|
||||
"ls -l", Styles,
|
||||
" ___", term.DotHere, "\n",
|
||||
|
|
|
@ -35,7 +35,7 @@ func (s *histStore) AllCmds() ([]store.Cmd, error) {
|
|||
func (s *histStore) Cursor(prefix string) histutil.Cursor {
|
||||
s.m.Lock()
|
||||
defer s.m.Unlock()
|
||||
return s.hs.Cursor(prefix)
|
||||
return cursor{&s.m, histutil.NewDedupCursor(s.hs.Cursor(prefix))}
|
||||
}
|
||||
|
||||
func (s *histStore) FastForward() error {
|
||||
|
@ -45,3 +45,26 @@ func (s *histStore) FastForward() error {
|
|||
s.hs = hs
|
||||
return err
|
||||
}
|
||||
|
||||
type cursor struct {
|
||||
m *sync.Mutex
|
||||
c histutil.Cursor
|
||||
}
|
||||
|
||||
func (c cursor) Prev() {
|
||||
c.m.Lock()
|
||||
defer c.m.Unlock()
|
||||
c.c.Prev()
|
||||
}
|
||||
|
||||
func (c cursor) Next() {
|
||||
c.m.Lock()
|
||||
defer c.m.Unlock()
|
||||
c.c.Next()
|
||||
}
|
||||
|
||||
func (c cursor) Get() (store.Cmd, error) {
|
||||
c.m.Lock()
|
||||
defer c.m.Unlock()
|
||||
return c.c.Get()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user