Skip to content

Commit b882835

Browse files
committed
Merge branch 'main' into update-component-preview
2 parents b734408 + c31c638 commit b882835

File tree

18 files changed

+977
-434
lines changed

18 files changed

+977
-434
lines changed

assets/keymaps/default-macos.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,10 @@
9797
"cmd-right": "editor::MoveToEndOfLine",
9898
"ctrl-e": "editor::MoveToEndOfLine",
9999
"end": "editor::MoveToEndOfLine",
100-
"cmd-up": "editor::MoveToBeginning",
101-
"cmd-down": "editor::MoveToEnd",
100+
"cmd-up": "editor::MoveToStartOfExcerpt",
101+
"cmd-down": "editor::MoveToEndOfExcerpt",
102+
"cmd-home": "editor::MoveToBeginning", // Typed via `cmd-fn-left`
103+
"cmd-end": "editor::MoveToEnd", // Typed via `cmd-fn-right`
102104
"shift-up": "editor::SelectUp",
103105
"ctrl-shift-p": "editor::SelectUp",
104106
"shift-down": "editor::SelectDown",
@@ -111,8 +113,8 @@
111113
"alt-shift-right": "editor::SelectToNextWordEnd", // cursorWordRightSelect
112114
"ctrl-shift-up": "editor::SelectToStartOfParagraph",
113115
"ctrl-shift-down": "editor::SelectToEndOfParagraph",
114-
"cmd-shift-up": "editor::SelectToBeginning",
115-
"cmd-shift-down": "editor::SelectToEnd",
116+
"cmd-shift-up": "editor::SelectToStartOfExcerpt",
117+
"cmd-shift-down": "editor::SelectToEndOfExcerpt",
116118
"cmd-a": "editor::SelectAll",
117119
"cmd-l": "editor::SelectLine",
118120
"cmd-shift-i": "editor::Format",

crates/assistant_context_editor/src/patch.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ impl ResolvedPatch {
140140
buffer.edit(
141141
edits,
142142
Some(AutoindentMode::Block {
143-
original_indent_columns: Vec::new(),
143+
original_start_columns: Vec::new(),
144144
}),
145145
cx,
146146
);

crates/diagnostics/src/diagnostics.rs

Lines changed: 258 additions & 193 deletions
Large diffs are not rendered by default.

crates/editor/src/actions.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,8 @@ gpui::actions!(
329329
MoveToPreviousSubwordStart,
330330
MoveToPreviousWordStart,
331331
MoveToStartOfParagraph,
332+
MoveToStartOfExcerpt,
333+
MoveToEndOfExcerpt,
332334
MoveUp,
333335
Newline,
334336
NewlineAbove,
@@ -364,6 +366,8 @@ gpui::actions!(
364366
ScrollCursorTop,
365367
SelectAll,
366368
SelectAllMatches,
369+
SelectToStartOfExcerpt,
370+
SelectToEndOfExcerpt,
367371
SelectDown,
368372
SelectEnclosingSymbol,
369373
SelectLargerSyntaxNode,

crates/editor/src/editor.rs

Lines changed: 109 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -976,9 +976,12 @@ struct ActiveDiagnosticGroup {
976976

977977
#[derive(Serialize, Deserialize, Clone, Debug)]
978978
pub struct ClipboardSelection {
979+
/// The number of bytes in this selection.
979980
pub len: usize,
981+
/// Whether this was a full-line selection.
980982
pub is_entire_line: bool,
981-
pub first_line_indent: u32,
983+
/// The column where this selection originally started.
984+
pub start_column: u32,
982985
}
983986

984987
#[derive(Debug)]
@@ -2273,7 +2276,7 @@ impl Editor {
22732276
pub fn edit_with_block_indent<I, S, T>(
22742277
&mut self,
22752278
edits: I,
2276-
original_indent_columns: Vec<u32>,
2279+
original_start_columns: Vec<u32>,
22772280
cx: &mut Context<Self>,
22782281
) where
22792282
I: IntoIterator<Item = (Range<S>, T)>,
@@ -2288,7 +2291,7 @@ impl Editor {
22882291
buffer.edit(
22892292
edits,
22902293
Some(AutoindentMode::Block {
2291-
original_indent_columns,
2294+
original_start_columns,
22922295
}),
22932296
cx,
22942297
)
@@ -3397,7 +3400,7 @@ impl Editor {
33973400

33983401
pub fn insert(&mut self, text: &str, window: &mut Window, cx: &mut Context<Self>) {
33993402
let autoindent = text.is_empty().not().then(|| AutoindentMode::Block {
3400-
original_indent_columns: Vec::new(),
3403+
original_start_columns: Vec::new(),
34013404
});
34023405
self.insert_with_autoindent_mode(text, autoindent, window, cx);
34033406
}
@@ -7943,9 +7946,7 @@ impl Editor {
79437946
clipboard_selections.push(ClipboardSelection {
79447947
len,
79457948
is_entire_line,
7946-
first_line_indent: buffer
7947-
.indent_size_for_line(MultiBufferRow(selection.start.row))
7948-
.len,
7949+
start_column: selection.start.column,
79497950
});
79507951
}
79517952
}
@@ -8024,7 +8025,7 @@ impl Editor {
80248025
clipboard_selections.push(ClipboardSelection {
80258026
len,
80268027
is_entire_line,
8027-
first_line_indent: buffer.indent_size_for_line(MultiBufferRow(start.row)).len,
8028+
start_column: start.column,
80288029
});
80298030
}
80308031
}
@@ -8054,8 +8055,8 @@ impl Editor {
80548055
let old_selections = this.selections.all::<usize>(cx);
80558056
let all_selections_were_entire_line =
80568057
clipboard_selections.iter().all(|s| s.is_entire_line);
8057-
let first_selection_indent_column =
8058-
clipboard_selections.first().map(|s| s.first_line_indent);
8058+
let first_selection_start_column =
8059+
clipboard_selections.first().map(|s| s.start_column);
80598060
if clipboard_selections.len() != old_selections.len() {
80608061
clipboard_selections.drain(..);
80618062
}
@@ -8069,21 +8070,21 @@ impl Editor {
80698070

80708071
let mut start_offset = 0;
80718072
let mut edits = Vec::new();
8072-
let mut original_indent_columns = Vec::new();
8073+
let mut original_start_columns = Vec::new();
80738074
for (ix, selection) in old_selections.iter().enumerate() {
80748075
let to_insert;
80758076
let entire_line;
8076-
let original_indent_column;
8077+
let original_start_column;
80778078
if let Some(clipboard_selection) = clipboard_selections.get(ix) {
80788079
let end_offset = start_offset + clipboard_selection.len;
80798080
to_insert = &clipboard_text[start_offset..end_offset];
80808081
entire_line = clipboard_selection.is_entire_line;
80818082
start_offset = end_offset + 1;
8082-
original_indent_column = Some(clipboard_selection.first_line_indent);
8083+
original_start_column = Some(clipboard_selection.start_column);
80838084
} else {
80848085
to_insert = clipboard_text.as_str();
80858086
entire_line = all_selections_were_entire_line;
8086-
original_indent_column = first_selection_indent_column
8087+
original_start_column = first_selection_start_column
80878088
}
80888089

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

81018102
edits.push((range, to_insert));
8102-
original_indent_columns.extend(original_indent_column);
8103+
original_start_columns.extend(original_start_column);
81038104
}
81048105
drop(snapshot);
81058106

81068107
buffer.edit(
81078108
edits,
81088109
if auto_indent_on_paste {
81098110
Some(AutoindentMode::Block {
8110-
original_indent_columns,
8111+
original_start_columns,
81118112
})
81128113
} else {
81138114
None
@@ -9033,6 +9034,98 @@ impl Editor {
90339034
})
90349035
}
90359036

9037+
pub fn move_to_start_of_excerpt(
9038+
&mut self,
9039+
_: &MoveToStartOfExcerpt,
9040+
window: &mut Window,
9041+
cx: &mut Context<Self>,
9042+
) {
9043+
if matches!(self.mode, EditorMode::SingleLine { .. }) {
9044+
cx.propagate();
9045+
return;
9046+
}
9047+
9048+
self.change_selections(Some(Autoscroll::fit()), window, cx, |s| {
9049+
s.move_with(|map, selection| {
9050+
selection.collapse_to(
9051+
movement::start_of_excerpt(
9052+
map,
9053+
selection.head(),
9054+
workspace::searchable::Direction::Prev,
9055+
),
9056+
SelectionGoal::None,
9057+
)
9058+
});
9059+
})
9060+
}
9061+
9062+
pub fn move_to_end_of_excerpt(
9063+
&mut self,
9064+
_: &MoveToEndOfExcerpt,
9065+
window: &mut Window,
9066+
cx: &mut Context<Self>,
9067+
) {
9068+
if matches!(self.mode, EditorMode::SingleLine { .. }) {
9069+
cx.propagate();
9070+
return;
9071+
}
9072+
9073+
self.change_selections(Some(Autoscroll::fit()), window, cx, |s| {
9074+
s.move_with(|map, selection| {
9075+
selection.collapse_to(
9076+
movement::end_of_excerpt(
9077+
map,
9078+
selection.head(),
9079+
workspace::searchable::Direction::Next,
9080+
),
9081+
SelectionGoal::None,
9082+
)
9083+
});
9084+
})
9085+
}
9086+
9087+
pub fn select_to_start_of_excerpt(
9088+
&mut self,
9089+
_: &SelectToStartOfExcerpt,
9090+
window: &mut Window,
9091+
cx: &mut Context<Self>,
9092+
) {
9093+
if matches!(self.mode, EditorMode::SingleLine { .. }) {
9094+
cx.propagate();
9095+
return;
9096+
}
9097+
9098+
self.change_selections(Some(Autoscroll::fit()), window, cx, |s| {
9099+
s.move_heads_with(|map, head, _| {
9100+
(
9101+
movement::start_of_excerpt(map, head, workspace::searchable::Direction::Prev),
9102+
SelectionGoal::None,
9103+
)
9104+
});
9105+
})
9106+
}
9107+
9108+
pub fn select_to_end_of_excerpt(
9109+
&mut self,
9110+
_: &SelectToEndOfExcerpt,
9111+
window: &mut Window,
9112+
cx: &mut Context<Self>,
9113+
) {
9114+
if matches!(self.mode, EditorMode::SingleLine { .. }) {
9115+
cx.propagate();
9116+
return;
9117+
}
9118+
9119+
self.change_selections(Some(Autoscroll::fit()), window, cx, |s| {
9120+
s.move_heads_with(|map, head, _| {
9121+
(
9122+
movement::end_of_excerpt(map, head, workspace::searchable::Direction::Next),
9123+
SelectionGoal::None,
9124+
)
9125+
});
9126+
})
9127+
}
9128+
90369129
pub fn move_to_beginning(
90379130
&mut self,
90389131
_: &MoveToBeginning,

0 commit comments

Comments
 (0)