ZIm/crates
Osvaldo e068c7b4b4
vim: Update anyquotes and anybrackets to behave like mini.ai plugin (#24167)
### Overview
This PR improves the existing
[mini.ai‐like](https://github.com/echasnovski/mini.ai) text-object logic
for both “AnyQuotes” (quotes) and “AnyBrackets” (brackets) by adding a
multi‐line fallback. The first pass searches only the current line for a
best match (cover or next); if none are found, we do a multi‐line pass.
This preserves mini.ai's usual “line priority” while ensuring we can
detect pairs that start on one line and end on another.

### What Changed
1. Brackets
- Line-based pass uses `gather_line_brackets(map, caret.row()) `to find
bracket pairs `((), [], {}, <>) `on the caret’s line.
- If that fails, we call `gather_brackets_multiline(map)` to single‐pass
scan the entire buffer, collecting bracket pairs that might span
multiple lines.
- Finally, we apply the mini.ai “**cover or next**” logic
(`pick_best_range`) to choose the best.
2.  Quotes
  - Similar line-based pass with `gather_line_quotes(map, caret.row())`.
- If no local quotes found, we do a multi‐line fallback with
`gather_quotes_multiline(map)`, building a big string for the whole
buffer and using naive regex for "...", '...', and `...`.
  - Also preserves “inner vs. outer” logic:
- For inner (e.g. `ciq`), we skip bounding quotes or brackets if the
range is at least 2 characters wide.
    - For outer (`caq`), we return the entire range.
3. Shared “`finalize`” helpers
- `finalize_bracket_range` and `finalize_quote_range` handle the “inner”
skip‐chars vs. “outer” logic.
  - Both rely on the same “line first, then full fallback” approach.

### Why This Matters
- **Old Behavior**: If you had multi‐line brackets { ... } or multi‐line
quotes spanning multiple lines, they weren’t found at all, since we only
scanned line by line. That made text objects like ci{ or ciq fail in
multi-line scenarios.
- **New Behavior**: We still do a quick line pass (for user‐friendly
“line priority”), but now if that fails, we do a single‐pass approach
across the entire buffer. This detects multi‐line pairs and maintains
mini.ai’s “cover‐or‐next” picking logic.

### Example Use Cases
- **Curly braces:** e.g., opening { on line 10, closing } on line 15 →
previously missed; now recognized.
- **Multi‐line quotes**: e.g., "'Line 1\nLine 2', no longer missed. We
do gather_quotes_multiline with a naive regex matching across newlines.

### Tests
- Updated and expanded coverage in:
  - test_anyquotes_object:
    - Includes a multi-line '...' test case.
- E.g. 'first' false\n<caret>string 'second' → ensuring we detect
multi‐line quotes.
  - test_anybrackets_object:
- Verifies line‐based priority but also multi‐line bracket detection.
- E.g., an open bracket ( on line 3, close ) on line 5, which used to
fail.

### Limitations / Future Enhancements
- **Escaping**: The current approach for quotes is naive and doesn’t
handle escape sequences (like \") or advanced parser logic. For deeper
correctness, we’ll need more advanced logic, this is also not supported
in the original mini.ai plugin so it is a known issue that won't be
attended for now.

### Important Notes
- Fix for the bug: https://github.com/zed-industries/zed/issues/23889
this PR addresses that bug specifically for the AnyQuotes text object.
Note that the issue still remains in the built-in motions (ci', ci",
ci`).
- Caret Position Differences: The caret position now slightly deviates
from Vim’s default behavior. This is intentional. I aim to closely mimic
the mini.ai plugin. Because these text objects are optional
(configurable via vim.json), this adjusted behavior is considered
acceptable and in my opinion the new behavior is better and it should be
the default in vim. Please review the new tests for details and context.
- Improved Special Cases: I’ve also refined how “false strings” in the
middle and certain curly-bracket scenarios are handled. The test suite
reflects these improvements, resulting in a more seamless coding
experience overall.

### References:
- Mini.AI plugin in nvim: https://github.com/echasnovski/mini.ai

Thank you for reviewing these changes!

Release Notes:

- Improve logic of aq, iq, ab and ib motions to work more like mini.ai
plugin
2025-02-17 14:55:48 -07:00
..
activity_indicator Remove more references to 'model' in GPUI APIs (#23693) 2025-01-27 04:00:27 +00:00
anthropic Solve 50+ cargo doc warnings (#24071) 2025-02-01 06:19:29 +00:00
assets Eliminate GPUI View, ViewContext, and WindowContext types (#22632) 2025-01-26 03:02:45 +00:00
assistant assistant: Add model selector to the Context Editor (#25032) 2025-02-17 16:29:42 -03:00
assistant2 Display case-sensitive keybindings for vim commands (#24322) 2025-02-14 22:03:59 -07:00
assistant_context_editor assistant: Add model selector to the Context Editor (#25032) 2025-02-17 16:29:42 -03:00
assistant_settings Solve 50+ cargo doc warnings (#24071) 2025-02-01 06:19:29 +00:00
assistant_slash_command Eliminate GPUI View, ViewContext, and WindowContext types (#22632) 2025-01-26 03:02:45 +00:00
assistant_slash_commands windows: Fix tests on Windows (#22616) 2025-02-05 14:30:09 +00:00
assistant_tool Eliminate GPUI View, ViewContext, and WindowContext types (#22632) 2025-01-26 03:02:45 +00:00
assistant_tools Eliminate GPUI View, ViewContext, and WindowContext types (#22632) 2025-01-26 03:02:45 +00:00
audio Eliminate GPUI View, ViewContext, and WindowContext types (#22632) 2025-01-26 03:02:45 +00:00
auto_update Fix missed renames in #22632 (#23688) 2025-01-26 23:37:34 +00:00
auto_update_ui Use the MessageNotification component for the release notes toast (#25013) 2025-02-17 11:32:04 -03:00
breadcrumbs Remove more references to 'model' in GPUI APIs (#23693) 2025-01-27 04:00:27 +00:00
buffer_diff Implement staging and unstaging hunks (#24606) 2025-02-12 19:46:42 +00:00
call Use different commit author for collab project clients (#24058) 2025-01-31 23:25:58 +00:00
channel Rename model based variable names to entity (#24198) 2025-02-04 10:24:35 -08:00
cli Add build SHA to panic reports and zed --version (on nightly/dev) (#24258) 2025-02-06 02:09:24 -07:00
client Replace rustls-native-certs with rustls-platform-verifier (#24656) 2025-02-12 07:32:17 -08:00
clock chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
collab Rename livekit_server to livekit_api (#24984) 2025-02-16 20:24:12 +00:00
collab_ui Display case-sensitive keybindings for vim commands (#24322) 2025-02-14 22:03:59 -07:00
collections chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
command_palette Display case-sensitive keybindings for vim commands (#24322) 2025-02-14 22:03:59 -07:00
command_palette_hooks vim: :set support (#24209) 2025-02-11 04:55:40 +00:00
component project: Fine-grained language server management (#24038) 2025-02-14 15:41:49 +01:00
component_preview ui: Update Label component (#24653) 2025-02-11 20:16:59 +00:00
context_server Fix missed renames in #22632 (#23688) 2025-01-26 23:37:34 +00:00
context_server_settings Eliminate GPUI View, ViewContext, and WindowContext types (#22632) 2025-01-26 03:02:45 +00:00
copilot copilot: Add support for Gemini 2.0 Flash model to Copilot Chat (#24952) 2025-02-17 19:25:38 +00:00
db Eliminate GPUI View, ViewContext, and WindowContext types (#22632) 2025-01-26 03:02:45 +00:00
deepseek Add DeepSeek support (#23551) 2025-01-27 13:40:59 -05:00
diagnostics lsp: Send DidOpen notifications when changing selections in multi buffer (#22958) 2025-02-07 12:33:35 +01:00
docs_preprocessor Eliminate GPUI View, ViewContext, and WindowContext types (#22632) 2025-01-26 03:02:45 +00:00
editor vim: Update anyquotes and anybrackets to behave like mini.ai plugin (#24167) 2025-02-17 14:55:48 -07:00
evals Fix missed renames in #22632 (#23688) 2025-01-26 23:37:34 +00:00
extension theme: Implement icon theme reloading (#24449) 2025-02-07 11:30:53 -05:00
extension_api chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
extension_cli extension_cli: Include the list of what an extension provides in the generated manifest (#24295) 2025-02-05 18:17:19 +00:00
extension_host project: Fine-grained language server management (#24038) 2025-02-14 15:41:49 +01:00
extensions_ui extensions_ui: Add general structure for filtering extensions by what they provide (#24325) 2025-02-06 00:09:37 +00:00
feature_flags zeta: Remove predict-edits-launch feature flag (#24829) 2025-02-13 21:48:09 +00:00
feedback edit predictions: Cache settings across renders (#24581) 2025-02-10 20:57:25 +00:00
file_finder Display case-sensitive keybindings for vim commands (#24322) 2025-02-14 22:03:59 -07:00
file_icons Allow icon themes to provide their own file associations (#24926) 2025-02-15 00:35:13 +00:00
fs git: Compute and synchronize diffs from HEAD (#23626) 2025-02-04 15:29:10 -05:00
fsevent Deflake fs::test_event_stream_simple (#24013) 2025-01-30 23:53:36 -07:00
fuzzy windows: Fix tests on Windows (#22616) 2025-02-05 14:30:09 +00:00
git Git context menu (#24844) 2025-02-14 14:04:32 -07:00
git_hosting_providers Add an undo button to the git panel (#24593) 2025-02-12 15:57:08 -07:00
git_ui Git context menu (#24844) 2025-02-14 14:04:32 -07:00
go_to_line project: Fine-grained language server management (#24038) 2025-02-14 15:41:49 +01:00
google_ai google_ai: Add support for Gemini 2.0 models (#24448) 2025-02-07 11:18:18 -05:00
gpui Use Vec for KeyContext instead of SmallVec (#24916) 2025-02-17 12:43:28 -07:00
gpui_macros windows: Fix tests on Windows (#22616) 2025-02-05 14:30:09 +00:00
gpui_tokio Make the gpui_tokio crate generic over the context it spawns (#23995) 2025-01-31 02:00:55 +00:00
html_to_markdown Eliminate GPUI View, ViewContext, and WindowContext types (#22632) 2025-01-26 03:02:45 +00:00
http_client Replace rustls-native-certs with rustls-platform-verifier (#24656) 2025-02-12 07:32:17 -08:00
image_viewer ui: Update Label component (#24653) 2025-02-11 20:16:59 +00:00
indexed_docs Eliminate GPUI View, ViewContext, and WindowContext types (#22632) 2025-01-26 03:02:45 +00:00
inline_completion edit predictions: Show user if current project is open source (#24587) 2025-02-10 22:28:56 -03:00
inline_completion_button inline_completion_button: Put "Eager Preview Mode" menu entry behind a feature flag (#24734) 2025-02-12 16:23:23 +00:00
install_cli Fix missed renames in #22632 (#23688) 2025-01-26 23:37:34 +00:00
journal Eliminate GPUI View, ViewContext, and WindowContext types (#22632) 2025-01-26 03:02:45 +00:00
language edit predictions: Fix cursor popover edit preview panic (#24866) 2025-02-14 15:44:45 +01:00
language_extension Fix missed renames in #22632 (#23688) 2025-01-26 23:37:34 +00:00
language_model assistant: Add Mistral support (#24879) 2025-02-14 13:07:41 -05:00
language_model_selector assistant: Improve language model selector design (#25036) 2025-02-17 17:12:46 -03:00
language_models copilot: Add support for Gemini 2.0 Flash model to Copilot Chat (#24952) 2025-02-17 19:25:38 +00:00
language_selector Refactor to use SharedString in more places (#23813) 2025-01-28 19:04:21 -05:00
language_tools Display case-sensitive keybindings for vim commands (#24322) 2025-02-14 22:03:59 -07:00
languages vim: Update anyquotes and anybrackets to behave like mini.ai plugin (#24167) 2025-02-17 14:55:48 -07:00
livekit_api Rename livekit_server to livekit_api (#24984) 2025-02-16 20:24:12 +00:00
livekit_client Rename livekit_server to livekit_api (#24984) 2025-02-16 20:24:12 +00:00
livekit_client_macos Rename livekit_server to livekit_api (#24984) 2025-02-16 20:24:12 +00:00
lmstudio lmstudio: Support missing quantization in model metadata (#24054) 2025-01-31 22:28:11 +00:00
lsp project: Fine-grained language server management (#24038) 2025-02-14 15:41:49 +01:00
markdown markdown: Use parsed text (#24388) 2025-02-06 18:37:50 -08:00
markdown_preview Migrate more events to telemetry::event! macro (#24102) 2025-02-03 16:38:45 +00:00
media chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
menu chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
migrator migrator: Fix keymap task_name regression (#24898) 2025-02-15 01:33:30 +05:30
mistral assistant: Add Mistral support (#24879) 2025-02-14 13:07:41 -05:00
multi_buffer Fix a couple of diff hunk issues (#24913) 2025-02-15 18:18:32 +00:00
node_runtime Pass extra CA certs to node process if env var exists (#23662) 2025-01-30 08:56:02 -08:00
notifications Remove more references to 'model' in GPUI APIs (#23693) 2025-01-27 04:00:27 +00:00
ollama Eliminate GPUI View, ViewContext, and WindowContext types (#22632) 2025-01-26 03:02:45 +00:00
open_ai open_ai: Include o3-mini in Model::from_id (#24261) 2025-02-05 16:45:38 -05:00
outline project: Fine-grained language server management (#24038) 2025-02-14 15:41:49 +01:00
outline_panel Allow icon themes to provide their own file associations (#24926) 2025-02-15 00:35:13 +00:00
panel git_ui: Update git panel commit editor, start on quick commit 2025-02-10 15:52:09 +00:00
paths Settings/keymap backup path next to files + update notification messages (#24517) 2025-02-09 16:51:37 -07:00
picker ui: Add show_scrollbar method to Picker (#25025) 2025-02-17 16:16:48 -03:00
prettier project: Fine-grained language server management (#24038) 2025-02-14 15:41:49 +01:00
project git: Fill the commit message buffer from MERGE_MSG (#24843) 2025-02-15 18:29:45 +00:00
project_panel Display case-sensitive keybindings for vim commands (#24322) 2025-02-14 22:03:59 -07:00
project_symbols windows: Fix tests on Windows (#22616) 2025-02-05 14:30:09 +00:00
prompt_library Display case-sensitive keybindings for vim commands (#24322) 2025-02-14 22:03:59 -07:00
proto Git context menu (#24844) 2025-02-14 14:04:32 -07:00
recent_projects Display case-sensitive keybindings for vim commands (#24322) 2025-02-14 22:03:59 -07:00
refineable windows: Fix tests on Windows (#22616) 2025-02-05 14:30:09 +00:00
release_channel Solve 50+ cargo doc warnings (#24071) 2025-02-01 06:19:29 +00:00
remote Add SSH port forwards to settings (#24474) 2025-02-14 14:52:24 -07:00
remote_server remote_server: Remove unnecessary Box, prevent time-of-check time-of-use bug (#24730) 2025-02-12 20:55:22 -07:00
repl Use Alacritty from crates.io (#25016) 2025-02-17 12:55:06 +00:00
reqwest_client Redact Google Gemini API keys from error messaging and log (#24884) 2025-02-17 11:42:22 -05:00
rich_text Eliminate GPUI View, ViewContext, and WindowContext types (#22632) 2025-01-26 03:02:45 +00:00
rope git: Compute and synchronize diffs from HEAD (#23626) 2025-02-04 15:29:10 -05:00
rpc extensions_ui: Add general structure for filtering extensions by what they provide (#24325) 2025-02-06 00:09:37 +00:00
schema_generator Add schema_generator for generating JSON schemas (#23991) 2025-01-31 01:22:10 +00:00
search Add regex highlights in the query input (#25005) 2025-02-17 09:15:43 +00:00
semantic_index Update tree-sitter to 0.24 (#24492) 2025-02-10 10:52:27 -08:00
semantic_version chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
session Eliminate GPUI View, ViewContext, and WindowContext types (#22632) 2025-01-26 03:02:45 +00:00
settings migrator: In-memory migration and improved UX (#24621) 2025-02-12 06:47:08 +05:30
settings_ui Eliminate GPUI View, ViewContext, and WindowContext types (#22632) 2025-01-26 03:02:45 +00:00
snippet Eliminate GPUI View, ViewContext, and WindowContext types (#22632) 2025-01-26 03:02:45 +00:00
snippet_provider snippets: Fix snippets not updating while containing comments (#23755) 2025-01-28 10:37:48 +01:00
snippets_ui Remove more references to 'model' in GPUI APIs (#23693) 2025-01-27 04:00:27 +00:00
sqlez Eliminate GPUI View, ViewContext, and WindowContext types (#22632) 2025-01-26 03:02:45 +00:00
sqlez_macros windows: Fix tests on Windows (#22616) 2025-02-05 14:30:09 +00:00
story Eliminate GPUI View, ViewContext, and WindowContext types (#22632) 2025-01-26 03:02:45 +00:00
storybook ui: Update Label component (#24653) 2025-02-11 20:16:59 +00:00
streaming_diff chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
sum_tree Implement staging and unstaging hunks (#24606) 2025-02-12 19:46:42 +00:00
supermaven Include prediction ID on edit prediction accepted/discarded events (#24480) 2025-02-07 22:06:37 +00:00
supermaven_api Eliminate GPUI View, ViewContext, and WindowContext types (#22632) 2025-01-26 03:02:45 +00:00
tab_switcher project: Fine-grained language server management (#24038) 2025-02-14 15:41:49 +01:00
task Eliminate GPUI View, ViewContext, and WindowContext types (#22632) 2025-01-26 03:02:45 +00:00
tasks_ui Display case-sensitive keybindings for vim commands (#24322) 2025-02-14 22:03:59 -07:00
telemetry chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
telemetry_events Add build SHA to panic reports and zed --version (on nightly/dev) (#24258) 2025-02-06 02:09:24 -07:00
terminal Solve 50+ cargo doc warnings (#24071) 2025-02-01 06:19:29 +00:00
terminal_view Add regex highlights in the query input (#25005) 2025-02-17 09:15:43 +00:00
text Fix unnecessarily large edits emitted from multi buffer on diff recalculation (#23753) 2025-01-27 18:11:15 -08:00
theme theme: Add file icon associations for .rdata and .RData files (#24925) 2025-02-15 02:04:35 +00:00
theme_extension theme: Implement icon theme reloading (#24449) 2025-02-07 11:30:53 -05:00
theme_importer Add schema_generator for generating JSON schemas (#23991) 2025-01-31 01:22:10 +00:00
theme_selector theme: Add support for setting light/dark icon themes (#24702) 2025-02-11 23:45:37 +00:00
time_format Add an undo button to the git panel (#24593) 2025-02-12 15:57:08 -07:00
title_bar Add an undo button to the git panel (#24593) 2025-02-12 15:57:08 -07:00
toolchain_selector Remove more references to 'model' in GPUI APIs (#23693) 2025-01-27 04:00:27 +00:00
ui Use lowercase for vim key bindings (#25024) 2025-02-17 10:17:22 -07:00
ui_input Eliminate GPUI View, ViewContext, and WindowContext types (#22632) 2025-01-26 03:02:45 +00:00
ui_macros component: Add component and component_preview crates to power UI components (#24456) 2025-02-09 13:25:03 -05:00
util Fix linux zeta modifiers display (#24764) 2025-02-12 14:46:42 -08:00
util_macros windows: Fix tests on Windows (#22616) 2025-02-05 14:30:09 +00:00
vim vim: Update anyquotes and anybrackets to behave like mini.ai plugin (#24167) 2025-02-17 14:55:48 -07:00
vim_mode_setting Eliminate GPUI View, ViewContext, and WindowContext types (#22632) 2025-01-26 03:02:45 +00:00
welcome welcome: Try Zed Edit Prediction (#24876) 2025-02-14 10:28:07 -05:00
workspace pane: Disable the "Close..." controls depending on certain scenarios (#25037) 2025-02-17 18:01:13 -03:00
worktree git: Fill the commit message buffer from MERGE_MSG (#24843) 2025-02-15 18:29:45 +00:00
zed Add regex highlights in the query input (#25005) 2025-02-17 09:15:43 +00:00
zed_actions Adds a way to toggle font size without settings adjustments (#24857) 2025-02-14 13:27:48 +02:00
zeta Display case-sensitive keybindings for vim commands (#24322) 2025-02-14 22:03:59 -07:00