use multiple selections for tag command

cc #791
This commit is contained in:
Gokcehan 2022-03-28 18:02:17 +03:00
parent 304026d680
commit afa90fe647
6 changed files with 27 additions and 19 deletions

4
doc.go
View File

@ -467,11 +467,11 @@ Remove a bookmark assigned to the given key.
tag
Tag a file with a single width character given in the argument.
Tag a file with "*" or a single width character given in the argument.
tag-toggle (default 't')
Tag a file with a single width character given in the argument if the file is untagged, otherwise remove the tag.
Tag a file with "*" or a single width character given in the argument if the file is untagged, otherwise remove the tag.
Command Line Commands

View File

@ -492,12 +492,12 @@ Remove a bookmark assigned to the given key.
tag
Tag a file with a single width character given in the argument.
Tag a file with "*" or a single width character given in the argument.
tag-toggle (default 't')
Tag a file with a single width character given in the argument if the file
is untagged, otherwise remove the tag.
Tag a file with "*" or a single width character given in the argument if the
file is untagged, otherwise remove the tag.
Command Line Commands

18
eval.go
View File

@ -988,9 +988,12 @@ func (e *callExpr) eval(app *app, args []string) {
return
}
if len(e.args) == 0 {
app.ui.echoerr("tag-toggle: missing default tag")
} else if err := app.nav.toggleTag(e.args[0]); err != nil {
tag := "*"
if len(e.args) != 0 {
tag = e.args[0]
}
if err := app.nav.tagToggle(tag); err != nil {
app.ui.echoerrf("tag-toggle: %s", err)
} else if err := app.nav.writeTags(); err != nil {
app.ui.echoerrf("tag-toggle: %s", err)
@ -1010,9 +1013,12 @@ func (e *callExpr) eval(app *app, args []string) {
return
}
if len(e.args) == 0 {
app.ui.echoerr("tag: missing tag")
} else if err := app.nav.tag(e.args[0]); err != nil {
tag := "*"
if len(e.args) != 0 {
tag = e.args[0]
}
if err := app.nav.tag(tag); err != nil {
app.ui.echoerrf("tag: %s", err)
} else if err := app.nav.writeTags(); err != nil {
app.ui.echoerrf("tag: %s", err)

4
lf.1
View File

@ -579,13 +579,13 @@ Remove a bookmark assigned to the given key.
tag
.EE
.PP
Tag a file with a single width character given in the argument.
Tag a file with "*" or a single width character given in the argument.
.PP
.EX
tag-toggle (default 't')
.EE
.PP
Tag a file with a single width character given in the argument if the file is untagged, otherwise remove the tag.
Tag a file with "*" or a single width character given in the argument if the file is untagged, otherwise remove the tag.
.SH COMMAND LINE COMMANDS
This section shows information about command line commands. These should be mostly compatible with readline keybindings. A character refers to a unicode code point, a word consists of letters and digits, and a unix word consists of any non-blank characters.
.PP

12
nav.go
View File

@ -964,7 +964,7 @@ func (nav *nav) toggle() {
nav.toggleSelection(curr.path)
}
func (nav *nav) toggleTagSelection(path string, tag string) {
func (nav *nav) tagToggleSelection(path string, tag string) {
if _, ok := nav.tags[path]; ok {
delete(nav.tags, path)
} else {
@ -972,7 +972,7 @@ func (nav *nav) toggleTagSelection(path string, tag string) {
}
}
func (nav *nav) toggleTag(tag string) error {
func (nav *nav) tagToggle(tag string) error {
list, err := nav.currFileOrSelections()
if err != nil {
return err
@ -983,14 +983,14 @@ func (nav *nav) toggleTag(tag string) error {
}
for _, path := range list {
nav.toggleTagSelection(path, tag)
nav.tagToggleSelection(path, tag)
}
return nil
}
func (nav *nav) tag(tag string) error {
curr, err := nav.currFile()
list, err := nav.currFileOrSelections()
if err != nil {
return err
}
@ -999,7 +999,9 @@ func (nav *nav) tag(tag string) error {
return errors.New("tag should be single width character")
}
nav.tags[curr.path] = tag
for _, path := range list {
nav.tags[path] = tag
}
return nil
}

View File

@ -149,7 +149,7 @@ func init() {
gOpts.keys["["] = &callExpr{"jump-prev", nil, 1}
gOpts.keys["]"] = &callExpr{"jump-next", nil, 1}
gOpts.keys["<space>"] = &listExpr{[]expr{&callExpr{"toggle", nil, 1}, &callExpr{"down", nil, 1}}, 1}
gOpts.keys["t"] = &callExpr{"tag-toggle", []string{"*"}, 1}
gOpts.keys["t"] = &callExpr{"tag-toggle", nil, 1}
gOpts.keys["v"] = &callExpr{"invert", nil, 1}
gOpts.keys["u"] = &callExpr{"unselect", nil, 1}
gOpts.keys["y"] = &callExpr{"copy", nil, 1}