Skip to content

Commit

Permalink
Merge branch 'main' into update-component-preview
Browse files Browse the repository at this point in the history
  • Loading branch information
iamnbutler committed Feb 21, 2025
2 parents b734408 + c31c638 commit b882835
Show file tree
Hide file tree
Showing 18 changed files with 977 additions and 434 deletions.
10 changes: 6 additions & 4 deletions assets/keymaps/default-macos.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,10 @@
"cmd-right": "editor::MoveToEndOfLine",
"ctrl-e": "editor::MoveToEndOfLine",
"end": "editor::MoveToEndOfLine",
"cmd-up": "editor::MoveToBeginning",
"cmd-down": "editor::MoveToEnd",
"cmd-up": "editor::MoveToStartOfExcerpt",
"cmd-down": "editor::MoveToEndOfExcerpt",
"cmd-home": "editor::MoveToBeginning", // Typed via `cmd-fn-left`
"cmd-end": "editor::MoveToEnd", // Typed via `cmd-fn-right`
"shift-up": "editor::SelectUp",
"ctrl-shift-p": "editor::SelectUp",
"shift-down": "editor::SelectDown",
Expand All @@ -111,8 +113,8 @@
"alt-shift-right": "editor::SelectToNextWordEnd", // cursorWordRightSelect
"ctrl-shift-up": "editor::SelectToStartOfParagraph",
"ctrl-shift-down": "editor::SelectToEndOfParagraph",
"cmd-shift-up": "editor::SelectToBeginning",
"cmd-shift-down": "editor::SelectToEnd",
"cmd-shift-up": "editor::SelectToStartOfExcerpt",
"cmd-shift-down": "editor::SelectToEndOfExcerpt",
"cmd-a": "editor::SelectAll",
"cmd-l": "editor::SelectLine",
"cmd-shift-i": "editor::Format",
Expand Down
2 changes: 1 addition & 1 deletion crates/assistant_context_editor/src/patch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ impl ResolvedPatch {
buffer.edit(
edits,
Some(AutoindentMode::Block {
original_indent_columns: Vec::new(),
original_start_columns: Vec::new(),
}),
cx,
);
Expand Down
451 changes: 258 additions & 193 deletions crates/diagnostics/src/diagnostics.rs

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions crates/editor/src/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,8 @@ gpui::actions!(
MoveToPreviousSubwordStart,
MoveToPreviousWordStart,
MoveToStartOfParagraph,
MoveToStartOfExcerpt,
MoveToEndOfExcerpt,
MoveUp,
Newline,
NewlineAbove,
Expand Down Expand Up @@ -364,6 +366,8 @@ gpui::actions!(
ScrollCursorTop,
SelectAll,
SelectAllMatches,
SelectToStartOfExcerpt,
SelectToEndOfExcerpt,
SelectDown,
SelectEnclosingSymbol,
SelectLargerSyntaxNode,
Expand Down
125 changes: 109 additions & 16 deletions crates/editor/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -976,9 +976,12 @@ struct ActiveDiagnosticGroup {

#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct ClipboardSelection {
/// The number of bytes in this selection.
pub len: usize,
/// Whether this was a full-line selection.
pub is_entire_line: bool,
pub first_line_indent: u32,
/// The column where this selection originally started.
pub start_column: u32,
}

#[derive(Debug)]
Expand Down Expand Up @@ -2273,7 +2276,7 @@ impl Editor {
pub fn edit_with_block_indent<I, S, T>(
&mut self,
edits: I,
original_indent_columns: Vec<u32>,
original_start_columns: Vec<u32>,
cx: &mut Context<Self>,
) where
I: IntoIterator<Item = (Range<S>, T)>,
Expand All @@ -2288,7 +2291,7 @@ impl Editor {
buffer.edit(
edits,
Some(AutoindentMode::Block {
original_indent_columns,
original_start_columns,
}),
cx,
)
Expand Down Expand Up @@ -3397,7 +3400,7 @@ impl Editor {

pub fn insert(&mut self, text: &str, window: &mut Window, cx: &mut Context<Self>) {
let autoindent = text.is_empty().not().then(|| AutoindentMode::Block {
original_indent_columns: Vec::new(),
original_start_columns: Vec::new(),
});
self.insert_with_autoindent_mode(text, autoindent, window, cx);
}
Expand Down Expand Up @@ -7943,9 +7946,7 @@ impl Editor {
clipboard_selections.push(ClipboardSelection {
len,
is_entire_line,
first_line_indent: buffer
.indent_size_for_line(MultiBufferRow(selection.start.row))
.len,
start_column: selection.start.column,
});
}
}
Expand Down Expand Up @@ -8024,7 +8025,7 @@ impl Editor {
clipboard_selections.push(ClipboardSelection {
len,
is_entire_line,
first_line_indent: buffer.indent_size_for_line(MultiBufferRow(start.row)).len,
start_column: start.column,
});
}
}
Expand Down Expand Up @@ -8054,8 +8055,8 @@ impl Editor {
let old_selections = this.selections.all::<usize>(cx);
let all_selections_were_entire_line =
clipboard_selections.iter().all(|s| s.is_entire_line);
let first_selection_indent_column =
clipboard_selections.first().map(|s| s.first_line_indent);
let first_selection_start_column =
clipboard_selections.first().map(|s| s.start_column);
if clipboard_selections.len() != old_selections.len() {
clipboard_selections.drain(..);
}
Expand All @@ -8069,21 +8070,21 @@ impl Editor {

let mut start_offset = 0;
let mut edits = Vec::new();
let mut original_indent_columns = Vec::new();
let mut original_start_columns = Vec::new();
for (ix, selection) in old_selections.iter().enumerate() {
let to_insert;
let entire_line;
let original_indent_column;
let original_start_column;
if let Some(clipboard_selection) = clipboard_selections.get(ix) {
let end_offset = start_offset + clipboard_selection.len;
to_insert = &clipboard_text[start_offset..end_offset];
entire_line = clipboard_selection.is_entire_line;
start_offset = end_offset + 1;
original_indent_column = Some(clipboard_selection.first_line_indent);
original_start_column = Some(clipboard_selection.start_column);
} else {
to_insert = clipboard_text.as_str();
entire_line = all_selections_were_entire_line;
original_indent_column = first_selection_indent_column
original_start_column = first_selection_start_column
}

// If the corresponding selection was empty when this slice of the
Expand All @@ -8099,15 +8100,15 @@ impl Editor {
};

edits.push((range, to_insert));
original_indent_columns.extend(original_indent_column);
original_start_columns.extend(original_start_column);
}
drop(snapshot);

buffer.edit(
edits,
if auto_indent_on_paste {
Some(AutoindentMode::Block {
original_indent_columns,
original_start_columns,
})
} else {
None
Expand Down Expand Up @@ -9033,6 +9034,98 @@ impl Editor {
})
}

pub fn move_to_start_of_excerpt(
&mut self,
_: &MoveToStartOfExcerpt,
window: &mut Window,
cx: &mut Context<Self>,
) {
if matches!(self.mode, EditorMode::SingleLine { .. }) {
cx.propagate();
return;
}

self.change_selections(Some(Autoscroll::fit()), window, cx, |s| {
s.move_with(|map, selection| {
selection.collapse_to(
movement::start_of_excerpt(
map,
selection.head(),
workspace::searchable::Direction::Prev,
),
SelectionGoal::None,
)
});
})
}

pub fn move_to_end_of_excerpt(
&mut self,
_: &MoveToEndOfExcerpt,
window: &mut Window,
cx: &mut Context<Self>,
) {
if matches!(self.mode, EditorMode::SingleLine { .. }) {
cx.propagate();
return;
}

self.change_selections(Some(Autoscroll::fit()), window, cx, |s| {
s.move_with(|map, selection| {
selection.collapse_to(
movement::end_of_excerpt(
map,
selection.head(),
workspace::searchable::Direction::Next,
),
SelectionGoal::None,
)
});
})
}

pub fn select_to_start_of_excerpt(
&mut self,
_: &SelectToStartOfExcerpt,
window: &mut Window,
cx: &mut Context<Self>,
) {
if matches!(self.mode, EditorMode::SingleLine { .. }) {
cx.propagate();
return;
}

self.change_selections(Some(Autoscroll::fit()), window, cx, |s| {
s.move_heads_with(|map, head, _| {
(
movement::start_of_excerpt(map, head, workspace::searchable::Direction::Prev),
SelectionGoal::None,
)
});
})
}

pub fn select_to_end_of_excerpt(
&mut self,
_: &SelectToEndOfExcerpt,
window: &mut Window,
cx: &mut Context<Self>,
) {
if matches!(self.mode, EditorMode::SingleLine { .. }) {
cx.propagate();
return;
}

self.change_selections(Some(Autoscroll::fit()), window, cx, |s| {
s.move_heads_with(|map, head, _| {
(
movement::end_of_excerpt(map, head, workspace::searchable::Direction::Next),
SelectionGoal::None,
)
});
})
}

pub fn move_to_beginning(
&mut self,
_: &MoveToBeginning,
Expand Down
Loading

0 comments on commit b882835

Please sign in to comment.