add 'cmd-capitalize-word' to upcase letter

This commit is contained in:
Gokcehan 2018-05-14 01:16:01 +03:00
parent bc67283f2a
commit 0c672fef6f
4 changed files with 53 additions and 38 deletions

1
doc.go
View File

@ -73,6 +73,7 @@ keybindings:
cmd-interrupt (default '<c-c>')
cmd-word (default '<a-f>')
cmd-word-back (default '<a-b>')
cmd-capitalize-word (default '<a-c>')
The following options can be used to customize the behavior of lf:

View File

@ -77,6 +77,7 @@ keybindings:
cmd-interrupt (default '<c-c>')
cmd-word (default '<a-f>')
cmd-word-back (default '<a-b>')
cmd-capitalize-word (default '<a-c>')
The following options can be used to customize the behavior of lf:

12
eval.go
View File

@ -6,6 +6,7 @@ import (
"os"
"strconv"
"strings"
"unicode"
"unicode/utf8"
)
@ -630,6 +631,17 @@ func (e *callExpr) eval(app *app, args []string) {
app.ui.cmdAccRight = append(app.ui.cmdAccLeft[ind:], app.ui.cmdAccRight...)
app.ui.cmdAccLeft = app.ui.cmdAccLeft[:ind]
}
case "cmd-capitalize-word":
if len(app.ui.cmdAccRight) > 0 {
app.ui.cmdAccRight[0] = unicode.ToUpper(app.ui.cmdAccRight[0])
loc := reWordEnd.FindStringIndex(string(app.ui.cmdAccRight))
if loc == nil {
return
}
ind := loc[0] + 1
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, app.ui.cmdAccRight[:ind]...)
app.ui.cmdAccRight = app.ui.cmdAccRight[ind:]
}
default:
cmd, ok := gOpts.cmds[e.name]
if !ok {

View File

@ -144,6 +144,7 @@ func init() {
gOpts.cmdkeys["<c-c>"] = &callExpr{"cmd-interrupt", nil, 1}
gOpts.cmdkeys["<a-f>"] = &callExpr{"cmd-word", nil, 1}
gOpts.cmdkeys["<a-b>"] = &callExpr{"cmd-word-back", nil, 1}
gOpts.cmdkeys["<a-c>"] = &callExpr{"cmd-capitalize-word", nil, 1}
// TODO: implement the rest of readline keys