diff --git a/eval.go b/eval.go index 9f37827..433c6ed 100644 --- a/eval.go +++ b/eval.go @@ -292,7 +292,7 @@ func (e *callExpr) eval(app *app, args []string) { log.Printf(msg) return } - app.nav.marks = make(map[string]bool) + app.nav.marks = make(map[string]int) if err := sendRemote("send sync"); err != nil { msg := fmt.Sprintf("yank: %s", err) app.ui.message = msg @@ -305,7 +305,7 @@ func (e *callExpr) eval(app *app, args []string) { log.Printf(msg) return } - app.nav.marks = make(map[string]bool) + app.nav.marks = make(map[string]int) if err := sendRemote("send sync"); err != nil { msg := fmt.Sprintf("delete: %s", err) app.ui.message = msg diff --git a/nav.go b/nav.go index 4426d7e..69be244 100644 --- a/nav.go +++ b/nav.go @@ -179,14 +179,15 @@ func (dir *dir) load(ind, pos, height int, name string) { } type nav struct { - dirs []*dir - inds map[string]int - poss map[string]int - names map[string]string - marks map[string]bool - saves map[string]bool - height int - search string + dirs []*dir + inds map[string]int + poss map[string]int + names map[string]string + marks map[string]int + saves map[string]bool + markInd int + height int + search string } func getDirs(wd string, height int) []*dir { @@ -221,13 +222,14 @@ func newNav(height int) *nav { dirs := getDirs(wd, height) return &nav{ - dirs: dirs, - inds: make(map[string]int), - poss: make(map[string]int), - names: make(map[string]string), - marks: make(map[string]bool), - saves: make(map[string]bool), - height: height, + dirs: dirs, + inds: make(map[string]int), + poss: make(map[string]int), + names: make(map[string]string), + marks: make(map[string]int), + saves: make(map[string]bool), + markInd: 0, + height: height, } } @@ -242,6 +244,9 @@ func (nav *nav) renew(height int) { delete(nav.marks, m) } } + if len(nav.marks) == 0 { + nav.markInd = 0 + } } func (nav *nav) up(dist int) { @@ -380,10 +385,14 @@ func (nav *nav) searchPrev() { } func (nav *nav) toggleMark(path string) { - if nav.marks[path] { + if _, ok := nav.marks[path]; ok { delete(nav.marks, path) + if len(nav.marks) == 0 { + nav.markInd = 0 + } } else { - nav.marks[path] = true + nav.marks[path] = nav.markInd + nav.markInd = nav.markInd + 1 } } @@ -502,10 +511,25 @@ func (nav *nav) currFile() (*file, error) { return last.fi[last.ind], nil } -func (nav *nav) currMarks() []string { - marks := make([]string, 0, len(nav.marks)) - for m := range nav.marks { - marks = append(marks, m) - } - return marks +type IndexedMarks struct { + paths []string + indices []int +} + +func (m IndexedMarks) Len() int { return len(m.paths) } +func (m IndexedMarks) Swap(i, j int) { + m.paths[i], m.paths[j] = m.paths[j], m.paths[i] + m.indices[i], m.indices[j] = m.indices[j], m.indices[i] +} +func (m IndexedMarks) Less(i, j int) bool { return m.indices[i] < m.indices[j] } + +func (nav *nav) currMarks() []string { + paths := make([]string, 0, len(nav.marks)) + indices := make([]int, 0, len(nav.marks)) + for path, index := range nav.marks { + paths = append(paths, path) + indices = append(indices, index) + } + sort.Sort(IndexedMarks{paths: paths, indices: indices}) + return paths } diff --git a/ui.go b/ui.go index d551dae..b3856f9 100644 --- a/ui.go +++ b/ui.go @@ -209,7 +209,7 @@ func (win *win) printl(x, y int, fg, bg termbox.Attribute, s string) { win.printf(x, y, fg, bg, "%s%*s", s, win.w-len(s), "") } -func (win *win) printd(dir *dir, marks, saves map[string]bool) { +func (win *win) printd(dir *dir, marks map[string]int, saves map[string]bool) { if win.w < 3 { return } @@ -254,7 +254,7 @@ func (win *win) printd(dir *dir, marks, saves map[string]bool) { path := filepath.Join(dir.path, f.Name()) - if marks[path] { + if _, ok := marks[path]; ok { win.print(0, i, fg, termbox.ColorMagenta, " ") } else if copy, ok := saves[path]; ok { if copy {