Switch to columnar selection by pressing alt-shift while mouse is down (#25096)

We begin a columnar selection when we drag the mouse while holding
`alt-shift`. This PR makes it possible to start the selection and then
turn it into columnar by pressing `alt-shift`.

Fixes #5372 

Release Notes:

- Support switching to columnar selection by pressing `alt-shift` while
mouse is down
This commit is contained in:
Agus Zubiaga 2025-02-18 14:49:13 -03:00 committed by GitHub
parent c10ac31866
commit 737b177ab5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 42 additions and 4 deletions

View file

@ -206,6 +206,14 @@ pub(crate) const SCROLL_CENTER_TOP_BOTTOM_DEBOUNCE_TIMEOUT: Duration = Duration:
pub(crate) const EDIT_PREDICTION_KEY_CONTEXT: &str = "edit_prediction";
pub(crate) const EDIT_PREDICTION_CONFLICT_KEY_CONTEXT: &str = "edit_prediction_conflict";
const COLUMNAR_SELECTION_MODIFIERS: Modifiers = Modifiers {
alt: true,
shift: true,
control: false,
platform: false,
function: false,
};
pub fn render_parsed_markdown(
element_id: impl Into<ElementId>,
parsed: &language::ParsedMarkdown,
@ -5341,6 +5349,8 @@ impl Editor {
self.update_edit_prediction_preview(&modifiers, window, cx);
}
self.update_selection_mode(&modifiers, position_map, window, cx);
let mouse_position = window.mouse_position();
if !position_map.text_hitbox.is_hovered(window) {
return;
@ -5355,6 +5365,32 @@ impl Editor {
)
}
fn update_selection_mode(
&mut self,
modifiers: &Modifiers,
position_map: &PositionMap,
window: &mut Window,
cx: &mut Context<Self>,
) {
if modifiers != &COLUMNAR_SELECTION_MODIFIERS || self.selections.pending.is_none() {
return;
}
let mouse_position = window.mouse_position();
let point_for_position = position_map.point_for_position(mouse_position);
let position = point_for_position.previous_valid;
self.select(
SelectPhase::BeginColumnar {
position,
reset: false,
goal_column: point_for_position.exact_unclipped.column(),
},
window,
cx,
);
}
fn update_edit_prediction_preview(
&mut self,
modifiers: &Modifiers,

View file

@ -21,8 +21,9 @@ use crate::{
GutterDimensions, HalfPageDown, HalfPageUp, HandleInput, HoveredCursor, InlineCompletion,
JumpData, LineDown, LineUp, OpenExcerpts, PageDown, PageUp, Point, RevertSelectedHunks, RowExt,
RowRangeExt, SelectPhase, SelectedTextHighlight, Selection, SoftWrap, StickyHeaderExcerpt,
ToPoint, ToggleFold, ToggleStagedSelectedDiffHunks, CURSORS_VISIBLE_FOR, FILE_HEADER_HEIGHT,
GIT_BLAME_MAX_AUTHOR_CHARS_DISPLAYED, MAX_LINE_LEN, MULTI_BUFFER_EXCERPT_HEADER_HEIGHT,
ToPoint, ToggleFold, ToggleStagedSelectedDiffHunks, COLUMNAR_SELECTION_MODIFIERS,
CURSORS_VISIBLE_FOR, FILE_HEADER_HEIGHT, GIT_BLAME_MAX_AUTHOR_CHARS_DISPLAYED, MAX_LINE_LEN,
MULTI_BUFFER_EXCERPT_HEADER_HEIGHT,
};
use buffer_diff::{DiffHunkSecondaryStatus, DiffHunkStatus};
use client::ParticipantIndex;
@ -515,6 +516,7 @@ impl EditorElement {
if editor.hover_state.focused(window, cx) {
return;
}
editor.handle_modifiers_changed(event.modifiers, &position_map, window, cx);
})
}
@ -594,7 +596,7 @@ impl EditorElement {
let point_for_position = position_map.point_for_position(event.position);
let position = point_for_position.previous_valid;
if modifiers.shift && modifiers.alt {
if modifiers == COLUMNAR_SELECTION_MODIFIERS {
editor.select(
SelectPhase::BeginColumnar {
position,

View file

@ -414,7 +414,7 @@ impl Modifiers {
}
}
/// Returns [`Modifiers`] with just control.
/// Returns [`Modifiers`] with just alt.
pub fn alt() -> Modifiers {
Modifiers {
alt: true,