Skip to content

Commit ce98612

Browse files
Fix completion on empty command (#4418)
1 parent 8d74d35 commit ce98612

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

ext/REPLExt/REPLExt.jl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,13 @@ function LineEdit.complete_line(c::PkgCompletionProvider, s; hint::Bool = false)
3939
# Convert to new completion interface format
4040
named_completions = map(LineEdit.NamedCompletion, ret)
4141
# Convert UnitRange to Region (Pair{Int,Int}) to match new completion interface
42-
# range represents character positions in full string, convert to 0-based byte positions
43-
if isempty(range)
42+
# range represents character positions in partial string, convert to 0-based byte positions
43+
if length(range) == 0 && first(range) > last(range)
44+
# Empty backward range like 4:3 means insert at cursor position
45+
# The cursor is at position last(range), so insert after it
46+
pos = thisind(partial, last(range) + 1) - 1
47+
region = pos => pos
48+
elseif isempty(range)
4449
region = 0 => 0
4550
else
4651
# Convert 1-based character positions to 0-based byte positions

test/repl.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,12 @@ temp_pkg_dir() do project_path
403403
@test "Example" in c
404404
pkg"free Example"
405405

406+
# Test for issue #59829 - completion with only trailing space should work
407+
# When typing "rm <TAB>" with Example installed, should complete to "rm Example"
408+
c, r = test_complete("rm ")
409+
@test "Example" in c
410+
@test apply_completion("rm ") == "rm Example"
411+
406412
# Test deduplication of already-specified packages (issue #4098)
407413
# After typing "rm Example ", typing "E" should not suggest Example again
408414
c, r = test_complete("rm Example E")

0 commit comments

Comments
 (0)