diff --git a/internal/action/actions.go b/internal/action/actions.go index ee9c78aa..ce9f9d80 100644 --- a/internal/action/actions.go +++ b/internal/action/actions.go @@ -1166,7 +1166,7 @@ func (h *BufPane) paste(clip string) { if h.Buf.Settings["smartpaste"].(bool) { if h.Cursor.X > 0 && len(util.GetLeadingWhitespace([]byte(strings.TrimLeft(clip, "\r\n")))) == 0 { leadingWS := util.GetLeadingWhitespace(h.Buf.LineBytes(h.Cursor.Y)) - clip = strings.Replace(clip, "\n", "\n"+string(leadingWS), -1) + clip = strings.ReplaceAll(clip, "\n", "\n"+string(leadingWS)) } } @@ -1349,10 +1349,8 @@ func (h *BufPane) HalfPageDown() bool { v := h.GetView() if h.Buf.LinesNum()-(v.StartLine+v.Height) > v.Height/2 { h.ScrollDown(v.Height / 2) - } else { - if h.Buf.LinesNum() >= v.Height { - v.StartLine = h.Buf.LinesNum() - v.Height - } + } else if h.Buf.LinesNum() >= v.Height { + v.StartLine = h.Buf.LinesNum() - v.Height } h.SetView(v) return true diff --git a/internal/buffer/buffer.go b/internal/buffer/buffer.go index dba08fe7..c2fda665 100644 --- a/internal/buffer/buffer.go +++ b/internal/buffer/buffer.go @@ -355,12 +355,10 @@ func NewBuffer(r io.Reader, size int64, path string, startcursor Loc, btype BufT if startcursor.X != -1 && startcursor.Y != -1 { b.StartCursor = startcursor - } else { - if b.Settings["savecursor"].(bool) || b.Settings["saveundo"].(bool) { - err := b.Unserialize() - if err != nil { - screen.TermMessage(err) - } + } else if b.Settings["savecursor"].(bool) || b.Settings["saveundo"].(bool) { + err := b.Unserialize() + if err != nil { + screen.TermMessage(err) } } @@ -1003,9 +1001,9 @@ func (b *Buffer) Retab() { ws := util.GetLeadingWhitespace(l) if len(ws) != 0 { if toSpaces { - ws = bytes.Replace(ws, []byte{'\t'}, bytes.Repeat([]byte{' '}, tabsize), -1) + ws = bytes.ReplaceAll(ws, []byte{'\t'}, bytes.Repeat([]byte{' '}, tabsize)) } else { - ws = bytes.Replace(ws, bytes.Repeat([]byte{' '}, tabsize), []byte{'\t'}, -1) + ws = bytes.ReplaceAll(ws, bytes.Repeat([]byte{' '}, tabsize), []byte{'\t'}) } } diff --git a/internal/config/runtime.go b/internal/config/runtime.go index 13548447..5d174dea 100644 --- a/internal/config/runtime.go +++ b/internal/config/runtime.go @@ -6812,7 +6812,7 @@ func runtimeSyntaxZshYaml() (*asset, error) { // It returns an error if the asset could not be found or // could not be loaded. func Asset(name string) ([]byte, error) { - cannonicalName := strings.Replace(name, "\\", "/", -1) + cannonicalName := strings.ReplaceAll(name, "\\", "/") if f, ok := _bindata[cannonicalName]; ok { a, err := f() if err != nil { @@ -6838,7 +6838,7 @@ func MustAsset(name string) []byte { // It returns an error if the asset could not be found or // could not be loaded. func AssetInfo(name string) (os.FileInfo, error) { - cannonicalName := strings.Replace(name, "\\", "/", -1) + cannonicalName := strings.ReplaceAll(name, "\\", "/") if f, ok := _bindata[cannonicalName]; ok { a, err := f() if err != nil { @@ -7198,8 +7198,8 @@ var _bindata = map[string]func() (*asset, error){ // AssetDir("") will return []string{"data"}. func AssetDir(name string) ([]string, error) { node := _bintree - if len(name) != 0 { - cannonicalName := strings.Replace(name, "\\", "/", -1) + if name != "" { + cannonicalName := strings.ReplaceAll(name, "\\", "/") pathList := strings.Split(cannonicalName, "/") for _, p := range pathList { node = node.Children[p] @@ -7620,6 +7620,6 @@ func RestoreAssets(dir, name string) error { } func _filePath(dir, name string) string { - cannonicalName := strings.Replace(name, "\\", "/", -1) + cannonicalName := strings.ReplaceAll(name, "\\", "/") return filepath.Join(append([]string{dir}, strings.Split(cannonicalName, "/")...)...) } diff --git a/internal/shell/job.go b/internal/shell/job.go index f45d4020..6e1f4b18 100644 --- a/internal/shell/job.go +++ b/internal/shell/job.go @@ -78,7 +78,7 @@ func JobSpawn(cmdName string, cmdArgs []string, onStdout, onStderr, onExit func( go func() { // Run the process in the background and create the onExit callback proc.Run() - jobFunc := JobFunction{onExit, string(outbuf.Bytes()), userargs} + jobFunc := JobFunction{onExit, outbuf.String(), userargs} Jobs <- jobFunc }() diff --git a/internal/util/util.go b/internal/util/util.go index 667b8565..f312ef56 100644 --- a/internal/util/util.go +++ b/internal/util/util.go @@ -341,9 +341,9 @@ func EscapePath(path string) string { path = filepath.ToSlash(path) if runtime.GOOS == "windows" { // ':' is not valid in a path name on Windows but is ok on Unix - path = strings.Replace(path, ":", "%", -1) + path = strings.ReplaceAll(path, ":", "%") } - return strings.Replace(path, "/", "%", -1) + return strings.ReplaceAll(path, "/", "%") } // GetLeadingWhitespace returns the leading whitespace of the given byte array @@ -430,7 +430,7 @@ func IsAutocomplete(c rune) bool { } func ParseSpecial(s string) string { - return strings.Replace(s, "\\t", "\t", -1) + return strings.ReplaceAll(s, "\\t", "\t") } // String converts a byte array to a string (for lua plugins)