From 549ab16e0f4d34631459f7bf654f79cd7071c1b3 Mon Sep 17 00:00:00 2001 From: rr Date: Fri, 17 Mar 2023 12:52:43 +0200 Subject: [PATCH 1/5] enhance rename ui --- eval.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/eval.go b/eval.go index b8e69ffa..3b42cdae 100644 --- a/eval.go +++ b/eval.go @@ -1920,7 +1920,22 @@ func (e *callExpr) eval(app *app, args []string) { } normal(app) app.ui.cmdPrefix = "rename: " + + if len(e.args) == 1 && e.args[0] == "start" { + app.ui.cmdAccRight = append(app.ui.cmdAccRight, []rune(curr.Name())...) + } else if len(e.args) == 1 && e.args[0] == "ext" { + dotidx := strings.LastIndex(curr.Name(), ".") + if dotidx < 1 { app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(curr.Name())...) + } else { + app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(curr.Name()[:dotidx])...) + app.ui.cmdAccRight = append(app.ui.cmdAccRight, []rune(curr.Name()[dotidx:])...) + } + } else if len(e.args) == 1 && e.args[0] == "cw" { + // user types whole word + } else { + app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(curr.Name())...) + } } app.ui.loadFile(app, true) app.ui.loadFileInfo(app.nav) From 9d14f86dd4dc1fbd6dce8244aa9791aba106a694 Mon Sep 17 00:00:00 2001 From: rr Date: Fri, 17 Mar 2023 12:56:13 +0200 Subject: [PATCH 2/5] gofmt --- eval.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eval.go b/eval.go index 3b42cdae..1ecd2d2b 100644 --- a/eval.go +++ b/eval.go @@ -1926,7 +1926,7 @@ func (e *callExpr) eval(app *app, args []string) { } else if len(e.args) == 1 && e.args[0] == "ext" { dotidx := strings.LastIndex(curr.Name(), ".") if dotidx < 1 { - app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(curr.Name())...) + app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(curr.Name())...) } else { app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(curr.Name()[:dotidx])...) app.ui.cmdAccRight = append(app.ui.cmdAccRight, []rune(curr.Name()[dotidx:])...) From d84df80c1402db09d09eb8f5a3869149e79372da Mon Sep 17 00:00:00 2001 From: rr Date: Mon, 20 Mar 2023 17:26:22 +0200 Subject: [PATCH 3/5] default rename: cursor on dot --- eval.go | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/eval.go b/eval.go index 1ecd2d2b..4392fafd 100644 --- a/eval.go +++ b/eval.go @@ -1920,21 +1920,13 @@ func (e *callExpr) eval(app *app, args []string) { } normal(app) app.ui.cmdPrefix = "rename: " - - if len(e.args) == 1 && e.args[0] == "start" { - app.ui.cmdAccRight = append(app.ui.cmdAccRight, []rune(curr.Name())...) - } else if len(e.args) == 1 && e.args[0] == "ext" { - dotidx := strings.LastIndex(curr.Name(), ".") - if dotidx < 1 { - app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(curr.Name())...) - } else { - app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(curr.Name()[:dotidx])...) - app.ui.cmdAccRight = append(app.ui.cmdAccRight, []rune(curr.Name()[dotidx:])...) - } - } else if len(e.args) == 1 && e.args[0] == "cw" { - // user types whole word - } else { + extension := filepath.Ext(curr.Name()) + if len(extension) == 0 || extension == curr.Name() { + // no extension or .hidden app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(curr.Name())...) + } else { + app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(curr.Name()[:len(extension)])...) + app.ui.cmdAccRight = append(app.ui.cmdAccRight, []rune(extension)...) } } app.ui.loadFile(app, true) From 4c6c2fed1aa0dd53ae3e40b62ef44b0db731056f Mon Sep 17 00:00:00 2001 From: rr Date: Mon, 20 Mar 2023 17:58:22 +0200 Subject: [PATCH 4/5] fix basename length --- eval.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eval.go b/eval.go index 4392fafd..dfc15ae0 100644 --- a/eval.go +++ b/eval.go @@ -1925,7 +1925,7 @@ func (e *callExpr) eval(app *app, args []string) { // no extension or .hidden app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(curr.Name())...) } else { - app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(curr.Name()[:len(extension)])...) + app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(curr.Name()[:len(extension)-1])...) app.ui.cmdAccRight = append(app.ui.cmdAccRight, []rune(extension)...) } } From d89577cb84ad7530312c3127e8e2e82113b14890 Mon Sep 17 00:00:00 2001 From: rr Date: Mon, 20 Mar 2023 18:22:46 +0200 Subject: [PATCH 5/5] fix basename length... again --- eval.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eval.go b/eval.go index dfc15ae0..bcc1807e 100644 --- a/eval.go +++ b/eval.go @@ -1925,7 +1925,7 @@ func (e *callExpr) eval(app *app, args []string) { // no extension or .hidden app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(curr.Name())...) } else { - app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(curr.Name()[:len(extension)-1])...) + app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(curr.Name()[:len(curr.Name())-len(extension)])...) app.ui.cmdAccRight = append(app.ui.cmdAccRight, []rune(extension)...) } }