use super::*; impl Editor { pub fn move_left(&mut self, _: &MoveLeft, window: &mut Window, cx: &mut Context<Self>) { self.change_selections(Default::default(), window, cx, |s| { s.move_with(&mut |map, selection| { let cursor = if selection.is_empty() { movement::left(map, selection.start) } else { selection.start }; selection.collapse_to(cursor, SelectionGoal::None); }); }) } pub fn select_left(&mut self, _: &SelectLeft, window: &mut Window, cx: &mut Context<Self>) { self.change_selections(Default::default(), window, cx, |s| { s.move_heads_with(&mut |map, head, _| (movement::left(map, head), SelectionGoal::None)); }) } pub fn move_right(&mut self, _: &MoveRight, window: &mut Window, cx: &mut Context<Self>) { self.change_selections(Default::default(), window, cx, |s| { s.move_with(&mut |map, selection| { let cursor = if selection.is_empty() { movement::right(map, selection.end) } else { selection.end }; selection.collapse_to(cursor, SelectionGoal::None) }); }) } pub fn select_right(&mut self, _: &SelectRight, window: &mut Window, cx: &mut Context<Self>) { self.change_selections(Default::default(), window, cx, |s| { s.move_heads_with(&mut |map, head, _| { (movement::right(map, head), SelectionGoal::None) }); }); } pub fn move_up(&mut self, _: &MoveUp, window: &mut Window, cx: &mut Context<Self>) { if self.take_rename(true, window, cx).is_some() { return; } if self.mode.is_single_line() { cx.propagate(); return; } let text_layout_details = &self.text_layout_details(window, cx); let selection_count = self.selections.count(); let first_selection = self.selections.first_anchor(); self.change_selections(Default::default(), window, cx, |s| { s.move_with(&mut |map, selection| { if !selection.is_empty() { selection.goal = SelectionGoal::None; } let (cursor, goal) = movement::up( map, selection.start, selection.goal, false, text_layout_details, ); selection.collapse_to(cursor, goal); }); }); if selection_count == 1 && first_selection.range() == self.selections.first_anchor().range() { cx.propagate(); } } pub fn move_up_by_lines( &mut self, action: &MoveUpByLines, window: &mut Window, cx: &mut Context<Self>, ) { if self.take_rename(true, window, cx).is_some() { return; } if self.mode.is_single_line() { cx.propagate(); return; } let text_layout_details = &self.text_layout_details(window, cx); self.change_selections(Default::default(), window, cx, |s| { s.move_with(&mut |map, selection| { if !selection.is_empty() { selection.goal = SelectionGoal::None; } let (cursor, goal) = movement::up_by_rows( map, selection.start, action.lines, selection.goal, false, text_layout_details, ); selection.collapse_to(cursor, goal); }); }) } pub fn move_down_by_lines( &mut self, action: &MoveDownByLines, window: &mut Window, cx: &mut Context<Self>, ) { if self.take_rename(true, window, cx).is_some() { return; } if self.mode.is_single_line() { cx.propagate(); return; } let text_layout_details = &self.text_layout_details(window, cx); self.change_selections(Default::default(), window, cx, |s| { s.move_with(&mut |map, selection| { if !selection.is_empty() { selection.goal = SelectionGoal::None; } let (cursor, goal) = movement::down_by_rows( map, selection.start, action.lines, selection.goal, false, text_layout_details, ); selection.collapse_to(cursor, goal); }); }) } pub fn select_down_by_lines( &mut self, action: &SelectDownByLines, window: &mut Window, cx: &mut Context<Self>, ) { let text_layout_details = &self.text_layout_details(window, cx); self.change_selections(Default::default(), window, cx, |s| { s.move_heads_with(&mut |map, head, goal| { movement::down_by_rows(map, head, action.lines, goal, false, text_layout_details) }) }) } pub fn select_up_by_lines( &mut self, action: &SelectUpByLines, window: &mut Window, cx: &mut Context<Self>, ) { let text_layout_details = &self.text_layout_details(window, cx); self.change_selections(Default::default(), window, cx, |s| { s.move_heads_with(&mut |map, head, goal| { movement::up_by_rows(map, head, action.lines, goal, false, text_layout_details) }) }) } pub fn select_page_up( &mut self, _: &SelectPageUp, window: &mut Window, cx: &mut Context<Self>, ) { let Some(row_count) = self.visible_row_count() else { return; }; let text_layout_details = &self.text_layout_details(window, cx); self.change_selections(Default::default(), window, cx, |s| { s.move_heads_with(&mut |map, head, goal| { movement::up_by_rows(map, head, row_count, goal, false, text_layout_details) }) }) } pub fn move_page_up( &mut self, action: &MovePageUp, window: &mut Window, cx: &mut Context<Self>, ) { if self.take_rename(true, window, cx).is_some() { return; } if self .context_menu .borrow_mut() .as_mut() .map(|menu| menu.select_first(self.completion_provider.as_deref(), window, cx)) .unwrap_or(false) { return; } if matches!(self.mode, EditorMode::SingleLine) { cx.propagate(); return; } let Some(row_count) = self.visible_row_count() else { return; }; let effects = if action.center_cursor { SelectionEffects::scroll(Autoscroll::center()) } else { SelectionEffects::default() }; let text_layout_details = &self.text_layout_details(window, cx); self.change_selections(effects, window, cx, |s| { s.move_with(&mut |map, selection| { if !selection.is_empty() { selection.goal = SelectionGoal::None; } let (cursor, goal) = movement::up_by_rows( map, selection.end, row_count, selection.goal, false, text_layout_details, ); selection.collapse_to(cursor, goal); }); }); } pub fn select_up(&mut self, _: &SelectUp, window: &mut Window, cx: &mut Context<Self>) { let text_layout_details = &self.text_layout_details(window, cx); self.change_selections(Default::default(), window, cx, |s| { s.move_heads_with(&mut |map, head, goal| { movement::up(map, head, goal, false, text_layout_details) }) }) } pub fn move_down(&mut self, _: &MoveDown, window: &mut Window, cx: &mut Context<Self>) { if self.take_rename(true, window, cx).is_some() { return; } if self.mode.is_single_line() { cx.propagate(); return; } let text_layout_details = &self.text_layout_details(window, cx); let selection_count = self.selections.count(); let first_selection = self.selections.first_anchor(); self.change_selections(Default::default(), window, cx, |s| { s.move_with(&mut |map, selection| { if !selection.is_empty() { selection.goal = SelectionGoal::None; } let (cursor, goal) = movement::down( map, selection.end, selection.goal, false, text_layout_details, ); selection.collapse_to(cursor, goal); }); }); if selection_count == 1 && first_selection.range() == self.selections.first_anchor().range() { cx.propagate(); } } pub fn select_page_down( &mut self, _: &SelectPageDown, window: &mut Window, cx: &mut Context<Self>, ) { let Some(row_count) = self.visible_row_count() else { return; }; let text_layout_details = &self.text_layout_details(window, cx); self.change_selections(Default::default(), window, cx, |s| { s.move_heads_with(&mut |map, head, goal| { movement::down_by_rows(map, head, row_count, goal, false, text_layout_details) }) }) } pub fn move_page_down( &mut self, action: &MovePageDown, window: &mut Window, cx: &mut Context<Self>, ) { if self.take_rename(true, window, cx).is_some() { return; } if self .context_menu .borrow_mut() .as_mut() .map(|menu| menu.select_last(self.completion_provider.as_deref(), window, cx)) .unwrap_or(false) { return; } if matches!(self.mode, EditorMode::SingleLine) { cx.propagate(); return; } let Some(row_count) = self.visible_row_count() else { return; }; let effects = if action.center_cursor { SelectionEffects::scroll(Autoscroll::center()) } else { SelectionEffects::default() }; let text_layout_details = &self.text_layout_details(window, cx); self.change_selections(effects, window, cx, |s| { s.move_with(&mut |map, selection| { if !selection.is_empty() { selection.goal = SelectionGoal::None; } let (cursor, goal) = movement::down_by_rows( map, selection.end, row_count, selection.goal, false, text_layout_details, ); selection.collapse_to(cursor, goal); }); }); } pub fn select_down(&mut self, _: &SelectDown, window: &mut Window, cx: &mut Context<Self>) { let text_layout_details = &self.text_layout_details(window, cx); self.change_selections(Default::default(), window, cx, |s| { s.move_heads_with(&mut |map, head, goal| { movement::down(map, head, goal, false, text_layout_details) }) }); } pub fn move_to_previous_word_start( &mut self, _: &MoveToPreviousWordStart, window: &mut Window, cx: &mut Context<Self>, ) { self.change_selections(Default::default(), window, cx, |s| { s.move_cursors_with(&mut |map, head, _| { ( movement::previous_word_start(map, head), SelectionGoal::None, ) }); }) } pub fn move_to_previous_subword_start( &mut self, _: &MoveToPreviousSubwordStart, window: &mut Window, cx: &mut Context<Self>, ) { self.change_selections(Default::default(), window, cx, |s| { s.move_cursors_with(&mut |map, head, _| { ( movement::previous_subword_start(map, head), SelectionGoal::None, ) }); }) } pub fn select_to_previous_word_start( &mut self, _: &SelectToPreviousWordStart, window: &mut Window, cx: &mut Context<Self>, ) { self.change_selections(Default::default(), window, cx, |s| { s.move_heads_with(&mut |map, head, _| { ( movement::previous_word_start(map, head), SelectionGoal::None, ) }); }) } pub fn select_to_previous_subword_start( &mut self, _: &SelectToPreviousSubwordStart, window: &mut Window, cx: &mut Context<Self>, ) { self.change_selections(Default::default(), window, cx, |s| { s.move_heads_with(&mut |map, head, _| { ( movement::previous_subword_start(map, head), SelectionGoal::None, ) }); }) } pub fn move_to_next_word_end( &mut self, _: &MoveToNextWordEnd, window: &mut Window, cx: &mut Context<Self>, ) { self.change_selections(Default::default(), window, cx, |s| { s.move_cursors_with(&mut |map, head, _| { (movement::next_word_end(map, head), SelectionGoal::None) }); }) } pub fn move_to_next_subword_end( &mut self, _: &MoveToNextSubwordEnd, window: &mut Window, cx: &mut Context<Self>, ) { self.change_selections(Default::default(), window, cx, |s| { s.move_cursors_with(&mut |map, head, _| { (movement::next_subword_end(map, head), SelectionGoal::None) }); }) } pub fn select_to_next_word_end( &mut self, _: &SelectToNextWordEnd, window: &mut Window, cx: &mut Context<Self>, ) { self.change_selections(Default::default(), window, cx, |s| { s.move_heads_with(&mut |map, head, _| { (movement::next_word_end(map, head), SelectionGoal::None) }); }) } pub fn select_to_next_subword_end( &mut self, _: &SelectToNextSubwordEnd, window: &mut Window, cx: &mut Context<Self>, ) { self.change_selections(Default::default(), window, cx, |s| { s.move_heads_with(&mut |map, head, _| { (movement::next_subword_end(map, head), SelectionGoal::None) }); }) } pub fn move_to_beginning_of_line( &mut self, action: &MoveToBeginningOfLine, window: &mut Window, cx: &mut Context<Self>, ) {Lines 1–500 of 2548. Load more
use super::*; impl Editor { pub fn move_left(&mut self, _: &MoveLeft, window: &mut Window, cx: &mut Context<Self>) { self.change_selections(Default::default(), window, cx, |s| { s.move_with(&mut |map, selection| { let cursor = if selection.is_empty() { movement::left(map, selection.start) } else { selection.start }; selection.collapse_to(cursor, SelectionGoal::None); }); }) } pub fn select_left(&mut self, _: &SelectLeft, window: &mut Window, cx: &mut Context<Self>) { self.change_selections(Default::default(), window, cx, |s| { s.move_heads_with(&mut |map, head, _| (movement::left(map, head), SelectionGoal::None)); }) } pub fn move_right(&mut self, _: &MoveRight, window: &mut Window, cx: &mut Context<Self>) { self.change_selections(Default::default(), window, cx, |s| { s.move_with(&mut |map, selection| { let cursor = if selection.is_empty() { movement::right(map, selection.end) } else { selection.end }; selection.collapse_to(cursor, SelectionGoal::None) }); }) } pub fn select_right(&mut self, _: &SelectRight, window: &mut Window, cx: &mut Context<Self>) { self.change_selections(Default::default(), window, cx, |s| { s.move_heads_with(&mut |map, head, _| { (movement::right(map, head), SelectionGoal::None) }); }); } pub fn move_up(&mut self, _: &MoveUp, window: &mut Window, cx: &mut Context<Self>) { if self.take_rename(true, window, cx).is_some() { return; } if self.mode.is_single_line() { cx.propagate(); return; } let text_layout_details = &self.text_layout_details(window, cx); let selection_count = self.selections.count(); let first_selection = self.selections.first_anchor(); self.change_selections(Default::default(), window, cx, |s| { s.move_with(&mut |map, selection| { if !selection.is_empty() { selection.goal = SelectionGoal::None; } let (cursor, goal) = movement::up( map, selection.start, selection.goal, false, text_layout_details, ); selection.collapse_to(cursor, goal); }); }); if selection_count == 1 && first_selection.range() == self.selections.first_anchor().range() { cx.propagate(); } } pub fn move_up_by_lines( &mut self, action: &MoveUpByLines, window: &mut Window, cx: &mut Context<Self>, ) { if self.take_rename(true, window, cx).is_some() { return; } if self.mode.is_single_line() { cx.propagate(); return; } let text_layout_details = &self.text_layout_details(window, cx); self.change_selections(Default::default(), window, cx, |s| { s.move_with(&mut |map, selection| { if !selection.is_empty() { selection.goal = SelectionGoal::None; } let (cursor, goal) = movement::up_by_rows( map, selection.start, action.lines, selection.goal, false, text_layout_details, ); selection.collapse_to(cursor, goal); }); }) } pub fn move_down_by_lines( &mut self, action: &MoveDownByLines, window: &mut Window, cx: &mut Context<Self>, ) { if self.take_rename(true, window, cx).is_some() { return; } if self.mode.is_single_line() { cx.propagate(); return; } let text_layout_details = &self.text_layout_details(window, cx); self.change_selections(Default::default(), window, cx, |s| { s.move_with(&mut |map, selection| { if !selection.is_empty() { selection.goal = SelectionGoal::None; } let (cursor, goal) = movement::down_by_rows( map, selection.start, action.lines, selection.goal, false, text_layout_details, ); selection.collapse_to(cursor, goal); }); }) } pub fn select_down_by_lines( &mut self, action: &SelectDownByLines, window: &mut Window, cx: &mut Context<Self>, ) { let text_layout_details = &self.text_layout_details(window, cx); self.change_selections(Default::default(), window, cx, |s| { s.move_heads_with(&mut |map, head, goal| { movement::down_by_rows(map, head, action.lines, goal, false, text_layout_details) }) }) } pub fn select_up_by_lines( &mut self, action: &SelectUpByLines, window: &mut Window, cx: &mut Context<Self>, ) { let text_layout_details = &self.text_layout_details(window, cx); self.change_selections(Default::default(), window, cx, |s| { s.move_heads_with(&mut |map, head, goal| { movement::up_by_rows(map, head, action.lines, goal, false, text_layout_details) }) }) } pub fn select_page_up( &mut self, _: &SelectPageUp, window: &mut Window, cx: &mut Context<Self>, ) { let Some(row_count) = self.visible_row_count() else { return; }; let text_layout_details = &self.text_layout_details(window, cx); self.change_selections(Default::default(), window, cx, |s| { s.move_heads_with(&mut |map, head, goal| { movement::up_by_rows(map, head, row_count, goal, false, text_layout_details) }) }) } pub fn move_page_up( &mut self, action: &MovePageUp, window: &mut Window, cx: &mut Context<Self>, ) { if self.take_rename(true, window, cx).is_some() { return; } if self .context_menu .borrow_mut() .as_mut() .map(|menu| menu.select_first(self.completion_provider.as_deref(), window, cx)) .unwrap_or(false) { return; } if matches!(self.mode, EditorMode::SingleLine) { cx.propagate(); return; } let Some(row_count) = self.visible_row_count() else { return; }; let effects = if action.center_cursor { SelectionEffects::scroll(Autoscroll::center()) } else { SelectionEffects::default() }; let text_layout_details = &self.text_layout_details(window, cx); self.change_selections(effects, window, cx, |s| { s.move_with(&mut |map, selection| { if !selection.is_empty() { selection.goal = SelectionGoal::None; } let (cursor, goal) = movement::up_by_rows( map, selection.end, row_count, selection.goal, false, text_layout_details, ); selection.collapse_to(cursor, goal); }); }); } pub fn select_up(&mut self, _: &SelectUp, window: &mut Window, cx: &mut Context<Self>) { let text_layout_details = &self.text_layout_details(window, cx); self.change_selections(Default::default(), window, cx, |s| { s.move_heads_with(&mut |map, head, goal| { movement::up(map, head, goal, false, text_layout_details) }) }) } pub fn move_down(&mut self, _: &MoveDown, window: &mut Window, cx: &mut Context<Self>) { if self.take_rename(true, window, cx).is_some() { return; } if self.mode.is_single_line() { cx.propagate(); return; } let text_layout_details = &self.text_layout_details(window, cx); let selection_count = self.selections.count(); let first_selection = self.selections.first_anchor(); self.change_selections(Default::default(), window, cx, |s| { s.move_with(&mut |map, selection| { if !selection.is_empty() { selection.goal = SelectionGoal::None; } let (cursor, goal) = movement::down( map, selection.end, selection.goal, false, text_layout_details, ); selection.collapse_to(cursor, goal); }); }); if selection_count == 1 && first_selection.range() == self.selections.first_anchor().range() { cx.propagate(); } } pub fn select_page_down( &mut self, _: &SelectPageDown, window: &mut Window, cx: &mut Context<Self>, ) { let Some(row_count) = self.visible_row_count() else { return; }; let text_layout_details = &self.text_layout_details(window, cx); self.change_selections(Default::default(), window, cx, |s| { s.move_heads_with(&mut |map, head, goal| { movement::down_by_rows(map, head, row_count, goal, false, text_layout_details) }) }) } pub fn move_page_down( &mut self, action: &MovePageDown, window: &mut Window, cx: &mut Context<Self>, ) { if self.take_rename(true, window, cx).is_some() { return; } if self .context_menu .borrow_mut() .as_mut() .map(|menu| menu.select_last(self.completion_provider.as_deref(), window, cx)) .unwrap_or(false) { return; } if matches!(self.mode, EditorMode::SingleLine) { cx.propagate(); return; } let Some(row_count) = self.visible_row_count() else { return; }; let effects = if action.center_cursor { SelectionEffects::scroll(Autoscroll::center()) } else { SelectionEffects::default() }; let text_layout_details = &self.text_layout_details(window, cx); self.change_selections(effects, window, cx, |s| { s.move_with(&mut |map, selection| { if !selection.is_empty() { selection.goal = SelectionGoal::None; } let (cursor, goal) = movement::down_by_rows( map, selection.end, row_count, selection.goal, false, text_layout_details, ); selection.collapse_to(cursor, goal); }); }); } pub fn select_down(&mut self, _: &SelectDown, window: &mut Window, cx: &mut Context<Self>) { let text_layout_details = &self.text_layout_details(window, cx); self.change_selections(Default::default(), window, cx, |s| { s.move_heads_with(&mut |map, head, goal| { movement::down(map, head, goal, false, text_layout_details) }) }); } pub fn move_to_previous_word_start( &mut self, _: &MoveToPreviousWordStart, window: &mut Window, cx: &mut Context<Self>, ) { self.change_selections(Default::default(), window, cx, |s| { s.move_cursors_with(&mut |map, head, _| { ( movement::previous_word_start(map, head), SelectionGoal::None, ) }); }) } pub fn move_to_previous_subword_start( &mut self, _: &MoveToPreviousSubwordStart, window: &mut Window, cx: &mut Context<Self>, ) { self.change_selections(Default::default(), window, cx, |s| { s.move_cursors_with(&mut |map, head, _| { ( movement::previous_subword_start(map, head), SelectionGoal::None, ) }); }) } pub fn select_to_previous_word_start( &mut self, _: &SelectToPreviousWordStart, window: &mut Window, cx: &mut Context<Self>, ) { self.change_selections(Default::default(), window, cx, |s| { s.move_heads_with(&mut |map, head, _| { ( movement::previous_word_start(map, head), SelectionGoal::None, ) }); }) } pub fn select_to_previous_subword_start( &mut self, _: &SelectToPreviousSubwordStart, window: &mut Window, cx: &mut Context<Self>, ) { self.change_selections(Default::default(), window, cx, |s| { s.move_heads_with(&mut |map, head, _| { ( movement::previous_subword_start(map, head), SelectionGoal::None, ) }); }) } pub fn move_to_next_word_end( &mut self, _: &MoveToNextWordEnd, window: &mut Window, cx: &mut Context<Self>, ) { self.change_selections(Default::default(), window, cx, |s| { s.move_cursors_with(&mut |map, head, _| { (movement::next_word_end(map, head), SelectionGoal::None) }); }) } pub fn move_to_next_subword_end( &mut self, _: &MoveToNextSubwordEnd, window: &mut Window, cx: &mut Context<Self>, ) { self.change_selections(Default::default(), window, cx, |s| { s.move_cursors_with(&mut |map, head, _| { (movement::next_subword_end(map, head), SelectionGoal::None) }); }) } pub fn select_to_next_word_end( &mut self, _: &SelectToNextWordEnd, window: &mut Window, cx: &mut Context<Self>, ) { self.change_selections(Default::default(), window, cx, |s| { s.move_heads_with(&mut |map, head, _| { (movement::next_word_end(map, head), SelectionGoal::None) }); }) } pub fn select_to_next_subword_end( &mut self, _: &SelectToNextSubwordEnd, window: &mut Window, cx: &mut Context<Self>, ) { self.change_selections(Default::default(), window, cx, |s| { s.move_heads_with(&mut |map, head, _| { (movement::next_subword_end(map, head), SelectionGoal::None) }); }) } pub fn move_to_beginning_of_line( &mut self, action: &MoveToBeginningOfLine, window: &mut Window, cx: &mut Context<Self>, ) {