From 0791b39abb90ee38e08dfacb39f7f47068830aa7 Mon Sep 17 00:00:00 2001 From: Anand Hegde Date: Mon, 14 Sep 2026 16:09:05 +0530 Subject: [PATCH] Fix completion after a trailing space in the kitty shell SplitForCompletion computed the position of the new empty word as if the previous word were one byte long, so tab completing after a space following a multi-character word replaced part of that word. For example, completing "launch --type " in the kitten @ shell produced "launch --window ". The new word starts at the end of the input. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_01MA8JGs7pCoXFL2W6jEJ8sD --- tools/utils/shlex/shlex.go | 2 +- tools/utils/shlex/shlex_test.go | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/utils/shlex/shlex.go b/tools/utils/shlex/shlex.go index 5f6f4f9e0..839fa1397 100644 --- a/tools/utils/shlex/shlex.go +++ b/tools/utils/shlex/shlex.go @@ -210,7 +210,7 @@ func SplitForCompletion(s string) (argv []string, position_of_last_arg int) { } if pos < len(s) { // trailing whitespace argv = append(argv, "") - position_of_last_arg += len(s) - pos + 1 + position_of_last_arg = len(s) } } } else { diff --git a/tools/utils/shlex/shlex_test.go b/tools/utils/shlex/shlex_test.go index f6be690eb..1d55ac419 100644 --- a/tools/utils/shlex/shlex_test.go +++ b/tools/utils/shlex/shlex_test.go @@ -96,6 +96,9 @@ func TestSplitForCompletion(t *testing.T) { test("a b", 2, "a", "b") test("a b ", 4, "a", "b", "") test("a b ", 5, "a", "b", "") + test("ab cd ", 6, "ab", "cd", "") + test("launch --type ", 14, "launch", "--type", "") + test(`a "b c" `, 8, "a", "b c", "") test(`a "b c"`, 2, "a", "b c") test(`a "b c`, 2, "a", "b c") }