From b47aa334591ecc60c98154bdec7063da21ec6434 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Marcos?= Date: Wed, 9 Apr 2025 14:13:41 -0300 Subject: [PATCH] Remove actions `UnfoldAt` and `FoldAt` (#28442) `UnfoldAt` and `FoldAt` are used internally, and don't really work when users try to trigger them, they do however appear in the command palette and keybindings, misleading users to try using them. Release Notes: - Remove unused actions `UnfoldAt` and `FoldAt` (prefer `Fold` and `Unfold`). --- .../src/context_editor.rs | 22 ++++++--------- crates/editor/src/actions.rs | 16 ----------- crates/editor/src/editor.rs | 28 +++++++++---------- crates/editor/src/element.rs | 2 -- 4 files changed, 22 insertions(+), 46 deletions(-) diff --git a/crates/assistant_context_editor/src/context_editor.rs b/crates/assistant_context_editor/src/context_editor.rs index 5248e97559..723ce2acbd 100644 --- a/crates/assistant_context_editor/src/context_editor.rs +++ b/crates/assistant_context_editor/src/context_editor.rs @@ -10,7 +10,7 @@ use collections::{BTreeSet, HashMap, HashSet, hash_map}; use editor::{ Anchor, Editor, EditorEvent, MenuInlineCompletionsPolicy, ProposedChangeLocation, ProposedChangesEditor, RowExt, ToOffset as _, ToPoint, - actions::{FoldAt, MoveToEndOfLine, Newline, ShowCompletions, UnfoldAt}, + actions::{MoveToEndOfLine, Newline, ShowCompletions}, display_map::{ BlockContext, BlockId, BlockPlacement, BlockProperties, BlockStyle, Crease, CreaseMetadata, CustomBlockId, FoldId, RenderBlock, ToDisplayPoint, @@ -1053,7 +1053,7 @@ impl ContextEditor { let creases = editor.insert_creases(creases, cx); for buffer_row in buffer_rows_to_fold.into_iter().rev() { - editor.fold_at(&FoldAt { buffer_row }, window, cx); + editor.fold_at(buffer_row, window, cx); } creases @@ -1109,7 +1109,7 @@ impl ContextEditor { buffer_rows_to_fold.clear(); } for buffer_row in buffer_rows_to_fold.into_iter().rev() { - editor.fold_at(&FoldAt { buffer_row }, window, cx); + editor.fold_at(buffer_row, window, cx); } }); } @@ -1844,13 +1844,7 @@ impl ContextEditor { |_, _, _, _| Empty.into_any(), ); editor.insert_creases(vec![crease], cx); - editor.fold_at( - &FoldAt { - buffer_row: start_row, - }, - window, - cx, - ); + editor.fold_at(start_row, window, cx); } }) } @@ -2042,7 +2036,7 @@ impl ContextEditor { cx, ); for buffer_row in buffer_rows_to_fold.into_iter().rev() { - editor.fold_at(&FoldAt { buffer_row }, window, cx); + editor.fold_at(buffer_row, window, cx); } } }); @@ -2820,7 +2814,7 @@ fn render_thought_process_fold_icon_button( .start .to_point(&editor.buffer().read(cx).read(cx)); let buffer_row = MultiBufferRow(buffer_start.row); - editor.unfold_at(&UnfoldAt { buffer_row }, window, cx); + editor.unfold_at(buffer_row, window, cx); }) .ok(); }) @@ -2847,7 +2841,7 @@ fn render_fold_icon_button( .start .to_point(&editor.buffer().read(cx).read(cx)); let buffer_row = MultiBufferRow(buffer_start.row); - editor.unfold_at(&UnfoldAt { buffer_row }, window, cx); + editor.unfold_at(buffer_row, window, cx); }) .ok(); }) @@ -2907,7 +2901,7 @@ fn quote_selection_fold_placeholder(title: String, editor: WeakEntity) - .start .to_point(&editor.buffer().read(cx).read(cx)); let buffer_row = MultiBufferRow(buffer_start.row); - editor.unfold_at(&UnfoldAt { buffer_row }, window, cx); + editor.unfold_at(buffer_row, window, cx); }) .ok(); }) diff --git a/crates/editor/src/actions.rs b/crates/editor/src/actions.rs index 670d21478f..f0fbc168df 100644 --- a/crates/editor/src/actions.rs +++ b/crates/editor/src/actions.rs @@ -110,20 +110,6 @@ pub struct ToggleComments { pub ignore_indent: bool, } -#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema)] -#[serde(deny_unknown_fields)] -pub struct FoldAt { - #[serde(skip)] - pub buffer_row: MultiBufferRow, -} - -#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema)] -#[serde(deny_unknown_fields)] -pub struct UnfoldAt { - #[serde(skip)] - pub buffer_row: MultiBufferRow, -} - #[derive(PartialEq, Clone, Deserialize, Default, JsonSchema)] #[serde(deny_unknown_fields)] pub struct MoveUpByLines { @@ -226,7 +212,6 @@ impl_actions!( ExpandExcerpts, ExpandExcerptsDown, ExpandExcerptsUp, - FoldAt, HandleInput, MoveDownByLines, MovePageDown, @@ -244,7 +229,6 @@ impl_actions!( ShowCompletions, ToggleCodeActions, ToggleComments, - UnfoldAt, FoldAtLevel, ] ); diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 9fe0e81ab0..b255cbbdcf 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -14915,8 +14915,12 @@ impl Editor { self.fold_creases(to_fold, true, window, cx); } - pub fn fold_at(&mut self, fold_at: &FoldAt, window: &mut Window, cx: &mut Context) { - let buffer_row = fold_at.buffer_row; + pub fn fold_at( + &mut self, + buffer_row: MultiBufferRow, + window: &mut Window, + cx: &mut Context, + ) { let display_map = self.display_map.update(cx, |map, cx| map.snapshot(cx)); if let Some(crease) = display_map.crease_for_buffer_row(buffer_row) { @@ -14986,16 +14990,16 @@ impl Editor { pub fn unfold_at( &mut self, - unfold_at: &UnfoldAt, + buffer_row: MultiBufferRow, _window: &mut Window, cx: &mut Context, ) { let display_map = self.display_map.update(cx, |map, cx| map.snapshot(cx)); - let intersection_range = Point::new(unfold_at.buffer_row.0, 0) + let intersection_range = Point::new(buffer_row.0, 0) ..Point::new( - unfold_at.buffer_row.0, - display_map.buffer_snapshot.line_len(unfold_at.buffer_row), + buffer_row.0, + display_map.buffer_snapshot.line_len(buffer_row), ); let autoscroll = self @@ -19364,15 +19368,11 @@ impl EditorSnapshot { Arc::new(move |folded, window: &mut Window, cx: &mut App| { if folded { editor.update(cx, |editor, cx| { - editor.fold_at(&crate::FoldAt { buffer_row }, window, cx) + editor.fold_at(buffer_row, window, cx) }); } else { editor.update(cx, |editor, cx| { - editor.unfold_at( - &crate::UnfoldAt { buffer_row }, - window, - cx, - ) + editor.unfold_at(buffer_row, window, cx) }); } }); @@ -19396,9 +19396,9 @@ impl EditorSnapshot { .toggle_state(folded) .on_click(window.listener_for(&editor, move |this, _e, window, cx| { if folded { - this.unfold_at(&UnfoldAt { buffer_row }, window, cx); + this.unfold_at(buffer_row, window, cx); } else { - this.fold_at(&FoldAt { buffer_row }, window, cx); + this.fold_at(buffer_row, window, cx); } })) .into_any_element(), diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index 54c65f05e6..adf45c31e8 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -387,14 +387,12 @@ impl EditorElement { register_action(editor, window, Editor::fold_at_level); register_action(editor, window, Editor::fold_all); register_action(editor, window, Editor::fold_function_bodies); - register_action(editor, window, Editor::fold_at); register_action(editor, window, Editor::fold_recursive); register_action(editor, window, Editor::toggle_fold); register_action(editor, window, Editor::toggle_fold_recursive); register_action(editor, window, Editor::unfold_lines); register_action(editor, window, Editor::unfold_recursive); register_action(editor, window, Editor::unfold_all); - register_action(editor, window, Editor::unfold_at); register_action(editor, window, Editor::fold_selected_ranges); register_action(editor, window, Editor::set_mark); register_action(editor, window, Editor::swap_selection_ends);