Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

editor: indent from cursor position with a single selection (#10073)

Piotr Osiewiczb43602f21b82
diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs
index c197e02fe13..736ba74f8b0 100644
--- a/crates/editor/src/editor.rs
+++ b/crates/editor/src/editor.rs
@@ -4845,6 +4845,7 @@ impl Editor {
}
let mut delta_for_end_row = 0;
+ let has_multiple_rows = start_row + 1 != end_row;
for row in start_row..end_row {
let current_indent = snapshot.indent_size_for_line(row);
let indent_delta = match (current_indent.kind, indent_kind) {
@@ -4856,7 +4857,12 @@ impl Editor {
(_, IndentKind::Tab) => IndentSize::tab(),
};
- let row_start = Point::new(row, 0);
+ let start = if has_multiple_rows || current_indent.len < selection.start.column {
+ 0
+ } else {
+ selection.start.column
+ };
+ let row_start = Point::new(row, start);
edits.push((
row_start..row_start,
indent_delta.chars().collect::<String>(),
@@ -4902,7 +4908,7 @@ impl Editor {
rows.start += 1;
}
}
-
+ let has_multiple_rows = rows.len() > 1;
for row in rows {
let indent_size = snapshot.indent_size_for_line(row);
if indent_size.len > 0 {
@@ -4917,7 +4923,16 @@ impl Editor {
}
IndentKind::Tab => 1,
};
- deletion_ranges.push(Point::new(row, 0)..Point::new(row, deletion_len));
+ let start = if has_multiple_rows
+ || deletion_len > selection.start.column
+ || indent_size.len < selection.start.column
+ {
+ 0
+ } else {
+ selection.start.column - deletion_len
+ };
+ deletion_ranges
+ .push(Point::new(row, start)..Point::new(row, start + deletion_len));
last_outdent = Some(row);
}
}