Support wrapping while in Visual mode (#2056)
This commit is contained in:
1 parent
041dfcc073
commit
5b2d5ad99d
3 files changed
+24
-6
No files matched your search
@@ -392,6 +392,7 @@ func (app *app) loop() {
|
|||||||
d.ind = prev.ind
|
d.ind = prev.ind
|
||||||
d.pos = prev.pos
|
d.pos = prev.pos
|
||||||
d.visualAnchor = min(prev.visualAnchor, len(d.files)-1)
|
d.visualAnchor = min(prev.visualAnchor, len(d.files)-1)
|
||||||
|
d.visualWrap = prev.visualWrap
|
||||||
d.filter = prev.filter
|
d.filter = prev.filter
|
||||||
d.sort()
|
d.sort()
|
||||||
d.sel(prev.name(), app.nav.height)
|
d.sel(prev.name(), app.nav.height)
|
||||||
|
|||||||
@@ -837,6 +837,7 @@ func normal(app *app) {
|
|||||||
func visual(app *app) {
|
func visual(app *app) {
|
||||||
dir := app.nav.currDir()
|
dir := app.nav.currDir()
|
||||||
dir.visualAnchor = dir.ind
|
dir.visualAnchor = dir.ind
|
||||||
|
dir.visualWrap = 0
|
||||||
|
|
||||||
app.ui.loadFileInfo(app.nav)
|
app.ui.loadFileInfo(app.nav)
|
||||||
}
|
}
|
||||||
@@ -2378,6 +2379,7 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
beg := max(dir.ind-dir.pos, 0)
|
beg := max(dir.ind-dir.pos, 0)
|
||||||
dir.ind, dir.visualAnchor = dir.visualAnchor, dir.ind
|
dir.ind, dir.visualAnchor = dir.visualAnchor, dir.ind
|
||||||
dir.pos = dir.ind - beg
|
dir.pos = dir.ind - beg
|
||||||
|
dir.visualWrap = -dir.visualWrap
|
||||||
dir.boundPos(app.nav.height)
|
dir.boundPos(app.nav.height)
|
||||||
default:
|
default:
|
||||||
cmd, ok := gOpts.cmds[e.name]
|
cmd, ok := gOpts.cmds[e.name]
|
||||||
|
|||||||
@@ -182,7 +182,8 @@ type dir struct {
|
|||||||
dironly bool // dironly value from last sort
|
dironly bool // dironly value from last sort
|
||||||
hidden bool // hidden value from last sort
|
hidden bool // hidden value from last sort
|
||||||
reverse bool // reverse value from last sort
|
reverse bool // reverse value from last sort
|
||||||
visualAnchor int // index where visual mode was initiated
|
visualAnchor int // index where Visual mode was initiated
|
||||||
|
visualWrap int // wrap direction in Visual mode
|
||||||
hiddenfiles []string // hiddenfiles value from last sort
|
hiddenfiles []string // hiddenfiles value from last sort
|
||||||
filter []string // last filter for this directory
|
filter []string // last filter for this directory
|
||||||
ignorecase bool // ignorecase value from last sort
|
ignorecase bool // ignorecase value from last sort
|
||||||
@@ -459,13 +460,21 @@ func (dir *dir) visualSelections() []string {
|
|||||||
return paths
|
return paths
|
||||||
}
|
}
|
||||||
|
|
||||||
beg, end := dir.ind, dir.visualAnchor
|
var beg, end int
|
||||||
if beg > end {
|
switch {
|
||||||
beg, end = end, beg
|
case dir.visualWrap == 0:
|
||||||
|
beg = min(dir.ind, dir.visualAnchor)
|
||||||
|
end = max(dir.ind, dir.visualAnchor)
|
||||||
|
case dir.visualWrap < 0:
|
||||||
|
beg = dir.ind
|
||||||
|
end = dir.visualAnchor - dir.visualWrap*len(dir.files)
|
||||||
|
case dir.visualWrap > 0:
|
||||||
|
beg = dir.visualAnchor
|
||||||
|
end = dir.ind + dir.visualWrap*len(dir.files)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, f := range dir.files[beg : end+1] {
|
for i := beg; i < min(end+1, beg+len(dir.files)); i++ {
|
||||||
paths = append(paths, f.path)
|
paths = append(paths, dir.files[i%len(dir.files)].path)
|
||||||
}
|
}
|
||||||
|
|
||||||
return paths
|
return paths
|
||||||
@@ -1017,6 +1026,7 @@ func (nav *nav) up(dist int) bool {
|
|||||||
if dir.ind == 0 {
|
if dir.ind == 0 {
|
||||||
if gOpts.wrapscroll {
|
if gOpts.wrapscroll {
|
||||||
nav.bottom()
|
nav.bottom()
|
||||||
|
dir.visualWrap -= 1
|
||||||
}
|
}
|
||||||
return old != dir.ind
|
return old != dir.ind
|
||||||
}
|
}
|
||||||
@@ -1040,6 +1050,7 @@ func (nav *nav) down(dist int) bool {
|
|||||||
if dir.ind >= maxind {
|
if dir.ind >= maxind {
|
||||||
if gOpts.wrapscroll {
|
if gOpts.wrapscroll {
|
||||||
nav.top()
|
nav.top()
|
||||||
|
dir.visualWrap += 1
|
||||||
}
|
}
|
||||||
return old != dir.ind
|
return old != dir.ind
|
||||||
}
|
}
|
||||||
@@ -1751,6 +1762,7 @@ func (nav *nav) findNext() (bool, bool) {
|
|||||||
if gOpts.wrapscan {
|
if gOpts.wrapscan {
|
||||||
for i := range dir.ind {
|
for i := range dir.ind {
|
||||||
if findMatch(dir.files[i].Name(), nav.find) {
|
if findMatch(dir.files[i].Name(), nav.find) {
|
||||||
|
dir.visualWrap += 1
|
||||||
return nav.up(dir.ind - i), true
|
return nav.up(dir.ind - i), true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1768,6 +1780,7 @@ func (nav *nav) findPrev() (bool, bool) {
|
|||||||
if gOpts.wrapscan {
|
if gOpts.wrapscan {
|
||||||
for i := len(dir.files) - 1; i > dir.ind; i-- {
|
for i := len(dir.files) - 1; i > dir.ind; i-- {
|
||||||
if findMatch(dir.files[i].Name(), nav.find) {
|
if findMatch(dir.files[i].Name(), nav.find) {
|
||||||
|
dir.visualWrap -= 1
|
||||||
return nav.down(i - dir.ind), true
|
return nav.down(i - dir.ind), true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1810,6 +1823,7 @@ func (nav *nav) searchNext() (bool, error) {
|
|||||||
if matched, err := searchMatch(dir.files[i].Name(), nav.search, gOpts.globsearch); err != nil {
|
if matched, err := searchMatch(dir.files[i].Name(), nav.search, gOpts.globsearch); err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
} else if matched {
|
} else if matched {
|
||||||
|
dir.visualWrap += 1
|
||||||
return nav.up(dir.ind - i), nil
|
return nav.up(dir.ind - i), nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1831,6 +1845,7 @@ func (nav *nav) searchPrev() (bool, error) {
|
|||||||
if matched, err := searchMatch(dir.files[i].Name(), nav.search, gOpts.globsearch); err != nil {
|
if matched, err := searchMatch(dir.files[i].Name(), nav.search, gOpts.globsearch); err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
} else if matched {
|
} else if matched {
|
||||||
|
dir.visualWrap -= 1
|
||||||
return nav.down(i - dir.ind), nil
|
return nav.down(i - dir.ind), nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user