Skip to content

Don't add trailing space after Tab-completing a directory path #4092

@huww98

Description

@huww98

Don't add trailing space after Tab-completing a directory path

What would you like to be added?

When using Tab to accept a directory path completion in the @ directive or the /dir add command, no trailing space should be appended. Currently, accepting a directory completion inserts a space after the path, forcing the user to delete it before continuing to type the next subdirectory level.

For example, when typing @src/ and pressing Tab to complete a directory like components/, the current result is:

@src/components/ 

The desired result should be:

@src/components/

So the user can immediately continue typing the next directory level without needing to backspace.

The same applies to /dir add — completing a directory path should not append a space, allowing the user to keep navigating deeper into the directory tree.

Why is this needed?

This is a common UX friction in path completion. Users typically drill down into directory trees by repeatedly pressing Tab to complete each level. The auto-inserted space breaks this workflow — every Tab acceptance requires a backspace before the next Tab can be used, doubling the keystrokes needed to navigate a multi-level path.

This behavior differs from how most shells (bash, zsh) handle directory completion: they append / (not a space) for directories, enabling seamless drill-down navigation.

Additional context

  • For @ completions, directory suggestions already end with / (e.g., src/components/), so the trailing space is clearly redundant.
  • For /dir add completions, directory paths don't currently end with /, so either the suggestion value should be changed to include /, or the completion system needs a way to distinguish directory vs file completions.
  • The trailing space is added unconditionally in the handleAutocomplete function for all completion types. The fix should only suppress the space for directory completions, keeping it for other completions (commands, files, etc.) where a space is appropriate.
中文

你希望添加什么功能?

在使用 Tab 键接受 @ 指令或 /dir add 命令中的目录路径补全时,不应在路径末尾追加空格。当前,接受目录补全后会在路径后插入一个空格,导致用户必须先删除该空格才能继续输入下一级子目录。

例如,当输入 @src/ 并按 Tab 补全目录 components/ 时,当前结果是:

@src/components/ 

期望结果应为:

@src/components/

这样用户可以立即继续输入下一级目录,无需先按退格键删除空格。

/dir add 同理——补全目录路径时不应追加空格,让用户可以持续深入目录树导航。

为什么需要这个功能?

这是路径补全中常见的用户体验摩擦点。用户通常通过反复按 Tab 来逐级深入目录树。自动插入的空格破坏了这一工作流——每次 Tab 补全后都需要退格,然后才能再次使用 Tab,导致导航多级路径所需的按键数翻倍。

这一行为与大多数 Shell(bash、zsh)的目录补全方式不同:Shell 对目录补全追加 /(而非空格),从而支持无缝逐级导航。

补充信息

  • 对于 @ 补全,目录建议值已经以 / 结尾(如 src/components/),因此尾部空格明显是多余的。
  • 对于 /dir add 补全,目录路径当前不以 / 结尾,因此要么需要将建议值改为包含 /,要么补全系统需要一种方式来区分目录与文件补全。
  • 当前尾部空格是在 handleAutocomplete 函数中对所有补全类型无条件添加的。修复应仅对目录补全抑制空格,对其他补全(命令、文件等)保留空格,因为在那些场景下空格是合适的。

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions