Skip to content

Commit

Permalink
invert-below command to substitute for visual mode
Browse files Browse the repository at this point in the history
This command inverts the selection for the current file and all the files below
it. Using this command twice substitutes for having a "visual" mode. This is
described in more detail in the docs and in
#477 (comment).

Since `invert` is bound to `v` by default, `invert-below` gets `V` as a default
binding.

Fixes #477. While that's not exactly what was asked for, I hope it's a suitable
replacement and seems more in the spirit of `lf`.
  • Loading branch information
ilyagr committed Feb 12, 2023
1 parent 530ab2c commit 478c97c
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 2 deletions.
1 change: 1 addition & 0 deletions complete.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ var (
"low",
"toggle",
"invert",
"invert-below",
"unselect",
"glob-select",
"glob-unselect",
Expand Down
8 changes: 8 additions & 0 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ The following commands are provided by lf:
low (default 'L')
toggle
invert (default 'v')
invert-below (default 'V')
unselect (default 'u')
glob-select
glob-unselect
Expand Down Expand Up @@ -336,6 +337,13 @@ Reverse the selection of all files in the current directory (i.e. 'toggle' all f
Selections in other directories are not effected by this command.
You can define a new command to select all files in the directory by combining 'invert' with 'unselect' (i.e. 'cmd select-all :unselect; invert'), though this will also remove selections in other directories.
invert-below (default 'V')
Reverse the selection (i.e. 'toggle') of all files at or after the current file in the current directory.
To select a contiguous block of files, use this command on the first file you want to select.
Then, move down to the first file you do *not* want to select (the one after the end of the desired selection) and use this command again.
This achieves an effect similar to the visual mode in vim.
unselect (default 'u')
Remove the selection of all files in all directories.
Expand Down
10 changes: 10 additions & 0 deletions docstring.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -1152,6 +1152,11 @@ func (e *callExpr) eval(app *app, args []string) {
return
}
app.nav.invert()
case "invert-below":
if !app.nav.init {
return
}
app.nav.invertBelow()
case "unselect":
app.nav.unselect()
case "calcdirsize":
Expand Down
7 changes: 7 additions & 0 deletions lf.1
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ The following commands are provided by lf:
low (default 'L')
toggle
invert (default 'v')
invert-below (default 'V')
unselect (default 'u')
glob-select
glob-unselect
Expand Down Expand Up @@ -394,6 +395,12 @@ Toggle the selection of the current file or files given as arguments.
.PP
Reverse the selection of all files in the current directory (i.e. 'toggle' all files). Selections in other directories are not effected by this command. You can define a new command to select all files in the directory by combining 'invert' with 'unselect' (i.e. 'cmd select-all :unselect; invert'), though this will also remove selections in other directories.
.PP
.EX
invert-below (default 'V')
.EE
.PP
Reverse the selection (i.e. 'toggle') of all files at or after the current file in the current directory. To select a contiguous block of files, use this command on the first file you want to select. Then, move down to the first file you do *not* want to select (the one after the end of the desired selection) and use this command again. This achieves an effect similar to the visual mode in vim.
.PP
.EX
unselect (default 'u')
.EE
Expand Down
12 changes: 10 additions & 2 deletions nav.go
Original file line number Diff line number Diff line change
Expand Up @@ -1149,14 +1149,22 @@ func (nav *nav) tag(tag string) error {
return nil
}

func (nav *nav) invert() {
func (nav *nav) invertAfter(ix int) {
dir := nav.currDir()
for _, f := range dir.files {
for _, f := range dir.files[ix:] {
path := filepath.Join(dir.path, f.Name())
nav.toggleSelection(path)
}
}

func (nav *nav) invert() {
nav.invertAfter(0)
}

func (nav *nav) invertBelow() {
nav.invertAfter(nav.currDir().ind)
}

func (nav *nav) unselect() {
nav.selections = make(map[string]int)
nav.selectionInd = 0
Expand Down
1 change: 1 addition & 0 deletions opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ func init() {
gOpts.keys["<space>"] = &listExpr{[]expr{&callExpr{"toggle", nil, 1}, &callExpr{"down", nil, 1}}, 1}
gOpts.keys["t"] = &callExpr{"tag-toggle", nil, 1}
gOpts.keys["v"] = &callExpr{"invert", nil, 1}
gOpts.keys["V"] = &callExpr{"invert-below", nil, 1}
gOpts.keys["u"] = &callExpr{"unselect", nil, 1}
gOpts.keys["y"] = &callExpr{"copy", nil, 1}
gOpts.keys["d"] = &callExpr{"cut", nil, 1}
Expand Down

0 comments on commit 478c97c

Please sign in to comment.