ZIm/crates
Rodrigo Freire c979452c2d
Implement indent conversion editor commands (#32340)
## Description of Feature or Change

Zed currently lacks a built-in way to convert a file’s indentation style
on the fly. While it's possible to change indentation behavior via
global or language-specific settings, these changes are persistent and
broad in scope as they apply to all files or all files of a given
language. We believe this could be improved for quick one-off
adjustments to specific files.

This PR introduces two new editor commands:
`Editor::convert_indentation_to_spaces` and
`Editor::convert_indentation_to_tabs`. These commands allow users to
convert the indentation of either the entire buffer or a selection of
lines, to spaces or tabs. Indentation levels are preserved, and any
mixed whitespace lines are properly normalized.

This feature is inspired by VS Code’s "Convert Indentation to
Tabs/Spaces" commands, but offers faster execution and supports
selection-based conversion, making it more flexible for quick formatting
changes.

## Implementation Details

To enable selection-based indentation conversion, we initially
considered reusing the existing `Editor::manipulate_lines` function,
which handles selections for line-based manipulations. However, this
method was designed specifically for operations like sorting or
reversing lines, and does not allow modifications to the line contents
themselves.

To address this limitation, we refactored the method into a more
flexible version: `Editor::manipulate_generic_lines`. This new method
passes a reference to the selected text directly into a callback, giving
the callback full control over how to process and construct the
resulting lines. The callback returns a `String` containing the modified
text, as well as the number of lines before and after the
transformation. These counts are computed using `.len()` on the line
vectors during manipulation, which is more efficient than calculating
them after the fact.


```rust
fn manipulate_generic_lines<M>(
  &mut self,
  window: &mut Window,
  cx: &mut Context<Self>,
  mut manipulate: M,
) where
   M: FnMut(&str) -> (String, usize, usize),
 {
   // ... Get text from buffer.text_for_range() ...
   let (new_text, lines_before, lines_after) = manipulate(&text);
   // ...
``` 

We now introduce two specialized methods:
`Editor::manipulate_mutable_lines` and
`Editor::manipulate_immutable_lines`. Each editor command selects the
appropriate method based on whether it needs to modify line contents or
simply reorder them. This distinction is important for performance: when
line contents remain unchanged, working with an immutable reference as
`&mut Vec<&str>` is both faster and more memory-efficient than using an
owned `&mut Vec<String>`.

## Demonstration


https://github.com/user-attachments/assets/e50b37ea-a128-4c2a-b252-46c3c4530d97



Release Notes:

- Added `editor::ConvertIndentationToSpaces` and
`editor::ConvertIndentationToTabs` actions to change editor indents

---------

Co-authored-by: Pedro Silveira <pedroruanosilveira@tecnico.ulisboa.pt>
2025-06-25 12:02:42 +00:00
..
activity_indicator Move r-a status into the activity indicator (#32726) 2025-06-13 22:33:02 +00:00
agent agent: Fix issue with Anthropic thinking models (#33317) 2025-06-24 16:23:59 +00:00
agent_settings language_models: Add images support to LMStudio provider (#32741) 2025-06-17 12:14:44 +02:00
agent_ui agent: Fix issue where unconfigured MCP extensions would not start server (#33365) 2025-06-25 11:48:38 +02:00
anthropic Thread Anthropic errors into LanguageModelKnownError (#33261) 2025-06-23 18:48:26 +00:00
askpass supermaven_api: Ensure downloaded Supermaven binary has executable permissions set (#32576) 2025-06-17 14:39:45 +00:00
assets Use anyhow more idiomatically (#31052) 2025-05-20 23:06:07 +00:00
assistant_context agent: Fix issue with Anthropic thinking models (#33317) 2025-06-24 16:23:59 +00:00
assistant_slash_command chore: Make terminal_view own the TerminalSlashCommand (#31070) 2025-05-21 09:27:54 +00:00
assistant_slash_commands editor: Improve code completion filtering to provide fewer and more accurate suggestions (#32928) 2025-06-18 16:01:28 +05:30
assistant_tool agent: Less disruptive changed file notification (#31693) 2025-06-16 18:45:24 +03:00
assistant_tools Implement indent conversion editor commands (#32340) 2025-06-25 12:02:42 +00:00
audio agent: Add sound notification when done generating (#31472) 2025-05-26 21:20:41 -03:00
auto_update Silence failed auto update checks (#32696) 2025-06-13 13:11:02 -04:00
auto_update_helper Use anyhow more idiomatically (#31052) 2025-05-20 23:06:07 +00:00
auto_update_ui Fix release notes appearing in project search (#32898) 2025-06-17 20:56:41 +00:00
aws_http_client Add workspace-hack (#27277) 2025-04-02 13:26:34 -07:00
bedrock bedrock: Support Claude 3.7 in APAC (#33068) 2025-06-22 20:08:50 +00:00
breadcrumbs breadcrumbs: Stylize filename in breadcrumbs when tab-bar is off and file is dirty (#30507) 2025-05-30 08:32:54 -07:00
buffer_diff Diff view (#32922) 2025-06-18 14:43:23 +00:00
call Use read-only access methods for read-only entity operations (#31479) 2025-05-26 23:04:31 -04:00
channel Fetch and wait for channels when opening channel notes via URL (#33291) 2025-06-24 05:14:15 +00:00
cli Improve FreeBSD support (#33162) 2025-06-22 16:23:17 -04:00
client Improve FreeBSD support (#33162) 2025-06-22 16:23:17 -04:00
clock Add the ability to follow the agent as it makes edits (#29839) 2025-05-04 08:28:39 +00:00
collab collab: Require billing address in all Stripe checkouts (#32980) 2025-06-24 14:06:00 +00:00
collab_ui Fix being unable to input a whitespace character in collab channels filter (#33318) 2025-06-24 16:11:25 +00:00
collections Add workspace-hack (#27277) 2025-04-02 13:26:34 -07:00
command_palette editor: Improve code completion filtering to provide fewer and more accurate suggestions (#32928) 2025-06-18 16:01:28 +05:30
command_palette_hooks Add workspace-hack (#27277) 2025-04-02 13:26:34 -07:00
component Fix typo (#32160) 2025-06-05 12:59:22 +00:00
context_server Redact command environment variables from log output (#32985) 2025-06-21 11:19:23 -04:00
copilot copilot: Remove PromptTokensDetails from Usage struct (#33029) 2025-06-19 17:37:58 +03:00
credentials_provider Add workspace-hack (#27277) 2025-04-02 13:26:34 -07:00
dap debugger: Generate inline values based on debugger.scm file (#33081) 2025-06-24 18:24:43 +00:00
dap_adapters debugger: Generate inline values based on debugger.scm file (#33081) 2025-06-24 18:24:43 +00:00
db Misc nitpicks, changes too small / unrelated to be in other PRs (#32768) 2025-06-15 19:51:04 +00:00
debug_adapter_extension debugger: Support passing custom arguments to debug adapters (#33251) 2025-06-23 17:06:48 +00:00
debugger_tools debugger: Improve logging of debug sessions (#32718) 2025-06-13 20:56:23 +00:00
debugger_ui debugger: Add a tooltip to the session picker with the session ID (#33331) 2025-06-25 02:20:31 +00:00
deepseek language_models: Emit UsageUpdate events for token usage in DeepSeek and OpenAI (#33242) 2025-06-25 09:42:30 +02:00
diagnostics Show inline previews for LSP document colors (#32816) 2025-06-17 13:46:21 +00:00
docs_preprocessor gpui: Simplify Action macros + support doc comments in actions! (#33263) 2025-06-24 04:34:51 +00:00
editor Implement indent conversion editor commands (#32340) 2025-06-25 12:02:42 +00:00
eval agent: Fix issue with Anthropic thinking models (#33317) 2025-06-24 16:23:59 +00:00
extension Redact command environment variables from log output (#32985) 2025-06-21 11:19:23 -04:00
extension_api zed_extension_api: Release v0.6.0 (#32945) 2025-06-18 14:05:29 +00:00
extension_cli extensions: Add "Debug Adapters" category to the extension store (#32845) 2025-06-17 12:09:08 +02:00
extension_host agent: Fix issue where unconfigured MCP extensions would not start server (#33365) 2025-06-25 11:48:38 +02:00
extensions_ui agent: Improve the UX around interacting with MCP servers (#32622) 2025-06-18 22:52:40 +00:00
feature_flags debugger: Remove feature flag (#32877) 2025-06-17 13:56:19 -06:00
feedback Improve FreeBSD support (#33162) 2025-06-22 16:23:17 -04:00
file_finder editor: Improve code completion filtering to provide fewer and more accurate suggestions (#32928) 2025-06-18 16:01:28 +05:30
file_icons Add workspace-hack (#27277) 2025-04-02 13:26:34 -07:00
fs Improve FreeBSD support (#33162) 2025-06-22 16:23:17 -04:00
fsevent Add workspace-hack (#27277) 2025-04-02 13:26:34 -07:00
fuzzy editor: Improve code completion filtering to provide fewer and more accurate suggestions (#32928) 2025-06-18 16:01:28 +05:30
git gpui: Simplify Action macros + support doc comments in actions! (#33263) 2025-06-24 04:34:51 +00:00
git_hosting_providers Allow configuring custom git hosting providers in project settings (#31929) 2025-06-03 12:23:01 -04:00
git_ui Implement save functionality for diff view (#33298) 2025-06-24 09:17:53 +00:00
go_to_line go_to_line: Show position relative to current excerpt in a multi-buffer (#31947) 2025-06-03 09:41:45 +02:00
google_ai Update Gemini Models (#32902) 2025-06-17 20:26:27 +00:00
gpui gpui: Disable rounding in the layout engine (#31836) 2025-06-24 20:28:57 +00:00
gpui_macros gpui: Simplify Action macros + support doc comments in actions! (#33263) 2025-06-24 04:34:51 +00:00
gpui_tokio Add workspace-hack (#27277) 2025-04-02 13:26:34 -07:00
html_to_markdown Add workspace-hack (#27277) 2025-04-02 13:26:34 -07:00
http_client Use anyhow more idiomatically (#31052) 2025-05-20 23:06:07 +00:00
http_client_tls Add workspace-hack (#27277) 2025-04-02 13:26:34 -07:00
icons Add support for Vercel as a language model provider (#33292) 2025-06-24 11:02:06 -03:00
image_viewer Option to auto-close deleted files with no unsaved edits (#31920) 2025-06-03 13:18:29 +02:00
indexed_docs editor: Improve code completion filtering to provide fewer and more accurate suggestions (#32928) 2025-06-18 16:01:28 +05:30
inline_completion agent: Fix issues with usage display sometimes showing initially fetched usage (#33125) 2025-06-20 21:28:48 +00:00
inline_completion_button inline_completion_button: Fix links to account page (#31558) 2025-05-27 21:52:42 +00:00
inspector_ui Fix anchor biases for completion replacement ranges (esp slash commands) (#32262) 2025-06-06 20:54:00 +00:00
install_cli Use anyhow more idiomatically (#31052) 2025-05-20 23:06:07 +00:00
jj Add a picker for jj bookmark list (#30883) 2025-05-17 16:42:45 +00:00
jj_ui editor: Improve code completion filtering to provide fewer and more accurate suggestions (#32928) 2025-06-18 16:01:28 +05:30
journal VSCode Settings import (#29018) 2025-04-23 20:54:09 +00:00
language debugger: Generate inline values based on debugger.scm file (#33081) 2025-06-24 18:24:43 +00:00
language_extension supermaven_api: Ensure downloaded Supermaven binary has executable permissions set (#32576) 2025-06-17 14:39:45 +00:00
language_model agent: Fix issue with Anthropic thinking models (#33317) 2025-06-24 16:23:59 +00:00
language_models bedrock: DeepSeek does not support receiving Reasoning Blocks (#33326) 2025-06-25 14:51:25 +03:00
language_selector editor: Improve code completion filtering to provide fewer and more accurate suggestions (#32928) 2025-06-18 16:01:28 +05:30
language_tools debugger: Parse and highlight text with ANSI escape sequences (#32915) 2025-06-17 23:39:31 -04:00
languages debugger: Generate inline values based on debugger.scm file (#33081) 2025-06-24 18:24:43 +00:00
livekit_api Use anyhow more idiomatically (#31052) 2025-05-20 23:06:07 +00:00
livekit_client Improve FreeBSD support (#33162) 2025-06-22 16:23:17 -04:00
lmstudio Standardize on u64 for token counts (#32869) 2025-06-17 10:43:07 -04:00
lsp Fix race condition between auto-indent and on-type-formatting (#32005) 2025-06-23 17:59:06 -04:00
markdown chore: Fix warnings for Rust 1.89 (#32378) 2025-06-09 13:11:57 +02:00
markdown_preview chore: Fix warnings for Rust 1.89 (#32378) 2025-06-09 13:11:57 +02:00
media Use anyhow more idiomatically (#31052) 2025-05-20 23:06:07 +00:00
menu agent: Add new panel navigation dropdown (#29539) 2025-04-29 21:58:45 -03:00
migrator Fix MCP settings migration continually adding the same key (#32848) 2025-06-17 09:32:08 +00:00
mistral Standardize on u64 for token counts (#32869) 2025-06-17 10:43:07 -04:00
multi_buffer Cleanup handling of surrounding word logic, fixing crash in editor::SelectAllMatches (#33353) 2025-06-24 23:18:35 -06:00
node_runtime Replace async-watch with a custom watch (#32245) 2025-06-06 16:00:09 +00:00
notifications notification: Add built-in dismiss button in the Status Toast component (#33278) 2025-06-23 19:55:21 -03:00
ollama Standardize on u64 for token counts (#32869) 2025-06-17 10:43:07 -04:00
open_ai language_models: Emit UsageUpdate events for token usage in DeepSeek and OpenAI (#33242) 2025-06-25 09:42:30 +02:00
open_router language_models: Add thinking support to OpenRouter provider (#32541) 2025-06-21 08:03:50 +02:00
outline Use read-only access methods for read-only entity operations (#31479) 2025-05-26 23:04:31 -04:00
outline_panel Omit outlines from the outline panel, not related to the buffer's main language (#32987) 2025-06-18 22:36:00 +00:00
panel Add workspace-hack (#27277) 2025-04-02 13:26:34 -07:00
paths Improve logic for finding VSCode / Cursor settings files (#32721) 2025-06-14 21:39:54 -06:00
picker gpui: Simplify Action macros + support doc comments in actions! (#33263) 2025-06-24 04:34:51 +00:00
prettier Improve logging of prettier errors (#32665) 2025-06-13 07:26:06 +00:00
project agent: Fix issue where unconfigured MCP extensions would not start server (#33365) 2025-06-25 11:48:38 +02:00
project_panel gpui: Simplify Action macros + support doc comments in actions! (#33263) 2025-06-24 04:34:51 +00:00
project_symbols editor: Improve code completion filtering to provide fewer and more accurate suggestions (#32928) 2025-06-18 16:01:28 +05:30
prompt_store editor: Improve code completion filtering to provide fewer and more accurate suggestions (#32928) 2025-06-18 16:01:28 +05:30
proto Show inline previews for LSP document colors (#32816) 2025-06-17 13:46:21 +00:00
recent_projects editor: Improve code completion filtering to provide fewer and more accurate suggestions (#32928) 2025-06-18 16:01:28 +05:30
refineable Add a live Rust style editor to inspector to edit a sequence of no-argument style modifiers (#31443) 2025-05-26 17:43:57 +00:00
release_channel Use shortened SHA when displaying version to install (#31281) 2025-05-23 14:53:53 +00:00
remote Make remote mkdir shell-independent for compatibility (#32997) 2025-06-25 03:21:59 +00:00
remote_server Fix diff indicators not restored when reopening remote project (#31384) 2025-06-17 10:07:51 -04:00
repl Add horizontal scroll to REPL outputs (#33247) 2025-06-24 10:15:20 +03:00
reqwest_client Use anyhow more idiomatically (#31052) 2025-05-20 23:06:07 +00:00
rich_text Add workspace-hack (#27277) 2025-04-02 13:26:34 -07:00
rope chore: Fix warnings for Rust 1.89 (#32378) 2025-06-09 13:11:57 +02:00
rpc extensions: Add "Debug Adapters" category to the extension store (#32845) 2025-06-17 12:09:08 +02:00
rules_library linux: Add title bar for rules library (#33025) 2025-06-19 18:23:09 +05:30
schema_generator Add workspace-hack (#27277) 2025-04-02 13:26:34 -07:00
search gpui: Simplify Action macros + support doc comments in actions! (#33263) 2025-06-24 04:34:51 +00:00
semantic_index Remove separator! macro and make path! handle relative paths (#32527) 2025-06-13 06:32:29 +00:00
semantic_version Use anyhow more idiomatically (#31052) 2025-05-20 23:06:07 +00:00
session Avoid unnecessary DB writes (#29417) 2025-04-25 17:41:49 +03:00
settings gpui: Add keybind metadata API (#33316) 2025-06-24 16:07:45 +00:00
settings_ui gpui: Simplify Action macros + support doc comments in actions! (#33263) 2025-06-24 04:34:51 +00:00
snippet Use anyhow more idiomatically (#31052) 2025-05-20 23:06:07 +00:00
snippet_provider Use read-only access methods for read-only entity operations (#31479) 2025-05-26 23:04:31 -04:00
snippets_ui editor: Improve code completion filtering to provide fewer and more accurate suggestions (#32928) 2025-06-18 16:01:28 +05:30
sqlez Use anyhow more idiomatically (#31052) 2025-05-20 23:06:07 +00:00
sqlez_macros Add workspace-hack (#27277) 2025-04-02 13:26:34 -07:00
story gpui: Add a standard text example (#30747) 2025-05-16 17:35:44 +02:00
storybook gpui: Add keybind metadata API (#33316) 2025-06-24 16:07:45 +00:00
streaming_diff Introduce a new StreamingEditFileTool (#29733) 2025-05-01 17:37:43 +02:00
sum_tree chore: Fix warnings for Rust 1.89 (#32378) 2025-06-09 13:11:57 +02:00
supermaven Add workspace-hack (#27277) 2025-04-02 13:26:34 -07:00
supermaven_api supermaven_api: Ensure downloaded Supermaven binary has executable permissions set (#32576) 2025-06-17 14:39:45 +00:00
tab_switcher gpui: Simplify Action macros + support doc comments in actions! (#33263) 2025-06-24 04:34:51 +00:00
task Silence another backtrace-full log (#32990) 2025-06-18 22:47:48 +00:00
tasks_ui debugger: Refine session modal design (#33004) 2025-06-19 02:27:34 -03:00
telemetry Add workspace-hack (#27277) 2025-04-02 13:26:34 -07:00
telemetry_events Add new action to run agent eval (#29158) 2025-04-21 21:30:21 -07:00
terminal terminal: Fix file paths links with URL escapes not being clickable (#31830) 2025-06-15 19:20:01 +00:00
terminal_view gpui: Simplify Action macros + support doc comments in actions! (#33263) 2025-06-24 04:34:51 +00:00
text chore: Fix warnings for Rust 1.89 (#32378) 2025-06-09 13:11:57 +02:00
theme Add icon for Cairo files (#33268) 2025-06-23 20:53:55 -03:00
theme_extension Add workspace-hack (#27277) 2025-04-02 13:26:34 -07:00
theme_importer theme: Add colors for minimap thumb and border (#30785) 2025-05-26 18:23:41 +00:00
theme_selector editor: Improve code completion filtering to provide fewer and more accurate suggestions (#32928) 2025-06-18 16:01:28 +05:30
time_format agent: Add date separators to Thread History (#29961) 2025-05-06 10:18:48 +00:00
title_bar gpui: Simplify Action macros + support doc comments in actions! (#33263) 2025-06-24 04:34:51 +00:00
toolchain_selector editor: Improve code completion filtering to provide fewer and more accurate suggestions (#32928) 2025-06-18 16:01:28 +05:30
ui gpui: Simplify Action macros + support doc comments in actions! (#33263) 2025-06-24 04:34:51 +00:00
ui_input agent: Add ability to change the API base URL for OpenAI via the UI (#32979) 2025-06-18 18:47:43 -03:00
ui_macros Update syn crate from 1.0.109 to 2.0.101 (#31301) 2025-05-23 19:31:25 +00:00
ui_prompt gpui: Improve window.prompt to support ESC with non-English cancel text on macOS (#29538) 2025-05-30 15:26:27 +00:00
util Redact command environment variables from log output (#32985) 2025-06-21 11:19:23 -04:00
util_macros Remove separator! macro and make path! handle relative paths (#32527) 2025-06-13 06:32:29 +00:00
vercel Add support for Vercel as a language model provider (#33292) 2025-06-24 11:02:06 -03:00
vim helix: Prevent cursor move on entering insert mode (#33201) 2025-06-24 15:20:14 -06:00
vim_mode_setting vim: Fix escape key switching back to default mode instead of normal mode (#31843) 2025-06-18 21:26:12 +00:00
watch chore: Fix warnings for Rust 1.89 (#32378) 2025-06-09 13:11:57 +02:00
web_search agent: Expose web search tool to beta users (#29273) 2025-04-23 15:30:20 +00:00
web_search_providers Use anyhow more idiomatically (#31052) 2025-05-20 23:06:07 +00:00
welcome editor: Improve code completion filtering to provide fewer and more accurate suggestions (#32928) 2025-06-18 16:01:28 +05:30
workspace Patch panic around pinned tab count (#33335) 2025-06-24 20:24:06 +00:00
worktree chore: Fix warnings for Rust 1.89 (#32378) 2025-06-09 13:11:57 +02:00
zed Use background task for settings migrations + notify about errors (#30009) 2025-06-24 23:54:03 +00:00
zed_actions gpui: Simplify Action macros + support doc comments in actions! (#33263) 2025-06-24 04:34:51 +00:00
zeta agent: Fix issues with usage display sometimes showing initially fetched usage (#33125) 2025-06-20 21:28:48 +00:00
zlog Initialize zlog default filters on init rather than waiting for settings load (#32209) 2025-06-06 00:49:30 -06:00
zlog_settings VSCode Settings import (#29018) 2025-04-23 20:54:09 +00:00