@@ -976,9 +976,12 @@ struct ActiveDiagnosticGroup {
976
976
977
977
#[derive(Serialize, Deserialize, Clone, Debug)]
978
978
pub struct ClipboardSelection {
979
+ /// The number of bytes in this selection.
979
980
pub len: usize,
981
+ /// Whether this was a full-line selection.
980
982
pub is_entire_line: bool,
981
- pub first_line_indent: u32,
983
+ /// The column where this selection originally started.
984
+ pub start_column: u32,
982
985
}
983
986
984
987
#[derive(Debug)]
@@ -2273,7 +2276,7 @@ impl Editor {
2273
2276
pub fn edit_with_block_indent<I, S, T>(
2274
2277
&mut self,
2275
2278
edits: I,
2276
- original_indent_columns : Vec<u32>,
2279
+ original_start_columns : Vec<u32>,
2277
2280
cx: &mut Context<Self>,
2278
2281
) where
2279
2282
I: IntoIterator<Item = (Range<S>, T)>,
@@ -2288,7 +2291,7 @@ impl Editor {
2288
2291
buffer.edit(
2289
2292
edits,
2290
2293
Some(AutoindentMode::Block {
2291
- original_indent_columns ,
2294
+ original_start_columns ,
2292
2295
}),
2293
2296
cx,
2294
2297
)
@@ -3397,7 +3400,7 @@ impl Editor {
3397
3400
3398
3401
pub fn insert(&mut self, text: &str, window: &mut Window, cx: &mut Context<Self>) {
3399
3402
let autoindent = text.is_empty().not().then(|| AutoindentMode::Block {
3400
- original_indent_columns : Vec::new(),
3403
+ original_start_columns : Vec::new(),
3401
3404
});
3402
3405
self.insert_with_autoindent_mode(text, autoindent, window, cx);
3403
3406
}
@@ -7943,9 +7946,7 @@ impl Editor {
7943
7946
clipboard_selections.push(ClipboardSelection {
7944
7947
len,
7945
7948
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,
7949
7950
});
7950
7951
}
7951
7952
}
@@ -8024,7 +8025,7 @@ impl Editor {
8024
8025
clipboard_selections.push(ClipboardSelection {
8025
8026
len,
8026
8027
is_entire_line,
8027
- first_line_indent: buffer.indent_size_for_line(MultiBufferRow( start.row)).len ,
8028
+ start_column: start.column ,
8028
8029
});
8029
8030
}
8030
8031
}
@@ -8054,8 +8055,8 @@ impl Editor {
8054
8055
let old_selections = this.selections.all::<usize>(cx);
8055
8056
let all_selections_were_entire_line =
8056
8057
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 );
8059
8060
if clipboard_selections.len() != old_selections.len() {
8060
8061
clipboard_selections.drain(..);
8061
8062
}
@@ -8069,21 +8070,21 @@ impl Editor {
8069
8070
8070
8071
let mut start_offset = 0;
8071
8072
let mut edits = Vec::new();
8072
- let mut original_indent_columns = Vec::new();
8073
+ let mut original_start_columns = Vec::new();
8073
8074
for (ix, selection) in old_selections.iter().enumerate() {
8074
8075
let to_insert;
8075
8076
let entire_line;
8076
- let original_indent_column ;
8077
+ let original_start_column ;
8077
8078
if let Some(clipboard_selection) = clipboard_selections.get(ix) {
8078
8079
let end_offset = start_offset + clipboard_selection.len;
8079
8080
to_insert = &clipboard_text[start_offset..end_offset];
8080
8081
entire_line = clipboard_selection.is_entire_line;
8081
8082
start_offset = end_offset + 1;
8082
- original_indent_column = Some(clipboard_selection.first_line_indent );
8083
+ original_start_column = Some(clipboard_selection.start_column );
8083
8084
} else {
8084
8085
to_insert = clipboard_text.as_str();
8085
8086
entire_line = all_selections_were_entire_line;
8086
- original_indent_column = first_selection_indent_column
8087
+ original_start_column = first_selection_start_column
8087
8088
}
8088
8089
8089
8090
// If the corresponding selection was empty when this slice of the
@@ -8099,15 +8100,15 @@ impl Editor {
8099
8100
};
8100
8101
8101
8102
edits.push((range, to_insert));
8102
- original_indent_columns .extend(original_indent_column );
8103
+ original_start_columns .extend(original_start_column );
8103
8104
}
8104
8105
drop(snapshot);
8105
8106
8106
8107
buffer.edit(
8107
8108
edits,
8108
8109
if auto_indent_on_paste {
8109
8110
Some(AutoindentMode::Block {
8110
- original_indent_columns ,
8111
+ original_start_columns ,
8111
8112
})
8112
8113
} else {
8113
8114
None
@@ -9033,6 +9034,98 @@ impl Editor {
9033
9034
})
9034
9035
}
9035
9036
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
+
9036
9129
pub fn move_to_beginning(
9037
9130
&mut self,
9038
9131
_: &MoveToBeginning,
0 commit comments