Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

invert-below command to substitute for visual mode #1101

Merged
merged 1 commit into from Feb 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions complete.go
Expand Up @@ -35,6 +35,7 @@ var (
"low",
"toggle",
"invert",
"invert-below",
"unselect",
"glob-select",
"glob-unselect",
Expand Down
12 changes: 12 additions & 0 deletions doc.go
Expand Up @@ -36,6 +36,7 @@ The following commands are provided by lf:
low (default 'L')
toggle
invert (default 'v')
invert-below
unselect (default 'u')
glob-select
glob-unselect
Expand Down Expand Up @@ -336,6 +337,17 @@ 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

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.

This command is experimental and may be removed once a better replacement for the visual mode is implemented in 'lf'.
If you'd like to experiment with using this command, you should bind it to a key (e.g. 'V') for a better experience.

unselect (default 'u')

Remove the selection of all files in all directories.
Expand Down
15 changes: 15 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
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
11 changes: 11 additions & 0 deletions lf.1
Expand Up @@ -51,6 +51,7 @@ The following commands are provided by lf:
low (default 'L')
toggle
invert (default 'v')
invert-below
unselect (default 'u')
glob-select
glob-unselect
Expand Down Expand Up @@ -394,6 +395,16 @@ 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
.EE
.PP
Reverse the selection (i.e. 'toggle') of all files at or after the current file in the current directory.
.PP
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
This command is experimental and may be removed once a better replacement for the visual mode is implemented in 'lf'. If you'd like to experiment with using this command, you should bind it to a key (e.g. 'V') for a better experience.
.PP
.EX
unselect (default 'u')
.EE
Expand Down
12 changes: 10 additions & 2 deletions nav.go
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