From 57f6ade1b7a924c152b9c808722fcd177822023a Mon Sep 17 00:00:00 2001 From: CatsDeservePets <145048791+CatsDeservePets@users.noreply.github.com> Date: Sat, 3 Jan 2026 00:44:12 +0100 Subject: [PATCH] fix: avoid surprising case changes in completions (#2336) --- CHANGELOG.md | 1 + complete.go | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b222afb..e62483ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), - A bug where sixel images fail to display when scrolling back and forth is now fixed (#2301). - Newline characters are now ignored when drawing the ruler with the `ruler` file configured (#2319). - A potential crash when using the `scroll-up`/`scroll-down` commands is now fixed (#2320). +- Case-insensitive command-line completions no longer cause user input to be displayed in lowercase (#2336). ## [r40](https://github.com/gokcehan/lf/releases/tag/r40) diff --git a/complete.go b/complete.go index 5c621971..5498f741 100644 --- a/complete.go +++ b/complete.go @@ -282,7 +282,9 @@ func matchFile(s string, dirOnly bool, escape, unescape func(string) string) (ma if len(matches) == 1 { commonName = name } else { - commonName = commonPrefix(strings.ToLower(commonName), strings.ToLower(name)) + // Match case-insensitively without changing the prefix's case. + p := commonPrefix(strings.ToLower(commonName), strings.ToLower(name)) + commonName = string([]rune(commonName)[:len([]rune(p))]) } } @@ -388,7 +390,8 @@ func matchSearch(s string) (matches []compMatch, result string) { if len(matches) == 1 { result = f.Name() } else { - result = commonPrefix(strings.ToLower(result), strings.ToLower(f.Name())) + p := commonPrefix(strings.ToLower(result), strings.ToLower(f.Name())) + result = string([]rune(result)[:len([]rune(p))]) } }