diff --git a/ext/REPLExt/REPLExt.jl b/ext/REPLExt/REPLExt.jl index 23247ee542..faf7f6cb0c 100644 --- a/ext/REPLExt/REPLExt.jl +++ b/ext/REPLExt/REPLExt.jl @@ -39,8 +39,13 @@ function LineEdit.complete_line(c::PkgCompletionProvider, s; hint::Bool = false) # Convert to new completion interface format named_completions = map(LineEdit.NamedCompletion, ret) # Convert UnitRange to Region (Pair{Int,Int}) to match new completion interface - # range represents character positions in full string, convert to 0-based byte positions - if isempty(range) + # range represents character positions in partial string, convert to 0-based byte positions + if length(range) == 0 && first(range) > last(range) + # Empty backward range like 4:3 means insert at cursor position + # The cursor is at position last(range), so insert after it + pos = thisind(partial, last(range) + 1) - 1 + region = pos => pos + elseif isempty(range) region = 0 => 0 else # Convert 1-based character positions to 0-based byte positions diff --git a/test/repl.jl b/test/repl.jl index 2cb62501e3..86d363c279 100644 --- a/test/repl.jl +++ b/test/repl.jl @@ -403,6 +403,12 @@ temp_pkg_dir() do project_path @test "Example" in c pkg"free Example" + # Test for issue #59829 - completion with only trailing space should work + # When typing "rm " with Example installed, should complete to "rm Example" + c, r = test_complete("rm ") + @test "Example" in c + @test apply_completion("rm ") == "rm Example" + # Test deduplication of already-specified packages (issue #4098) # After typing "rm Example ", typing "E" should not suggest Example again c, r = test_complete("rm Example E")