Avoid maintaining indent size as state on buffers

Indent size is still hard-coded, but it's now controlled by the
editor and not the buffer.

Co-authored-by: Keith Simmons <keith@zed.dev>
This commit is contained in:
Max Brunsfeld 2022-04-05 11:14:06 -07:00 committed by Keith Simmons
parent e21f90fec5
commit 664f17f92b
4 changed files with 51 additions and 45 deletions

View file

@ -63,6 +63,7 @@ const CURSOR_BLINK_INTERVAL: Duration = Duration::from_millis(500);
const MAX_LINE_LEN: usize = 1024;
const MIN_NAVIGATION_HISTORY_ROW_DELTA: i64 = 10;
const MAX_SELECTION_HISTORY_LEN: usize = 1024;
const INDENT_SIZE: u32 = 4;
action!(Cancel);
action!(Backspace);
@ -2946,7 +2947,7 @@ impl Editor {
{
let indent_column = buffer.indent_column_for_line(line_buffer_range.start.row);
if old_head.column <= indent_column && old_head.column > 0 {
let indent = buffer.indent_size();
let indent = INDENT_SIZE;
new_head = cmp::min(
new_head,
Point::new(old_head.row, ((old_head.column - 1) / indent) * indent),

View file

@ -287,6 +287,8 @@ impl MultiBuffer {
S: ToOffset,
T: Into<String>,
{
let indent_size = crate::INDENT_SIZE;
if self.buffers.borrow().is_empty() {
return;
}
@ -298,7 +300,7 @@ impl MultiBuffer {
.map(|range| range.start.to_offset(&snapshot)..range.end.to_offset(&snapshot));
return buffer.update(cx, |buffer, cx| {
if autoindent {
buffer.edit_with_autoindent(ranges, new_text, cx);
buffer.edit_with_autoindent(ranges, new_text, indent_size, cx);
} else {
buffer.edit(ranges, new_text, cx);
}
@ -394,8 +396,8 @@ impl MultiBuffer {
}
if autoindent {
buffer.edit_with_autoindent(deletions, "", cx);
buffer.edit_with_autoindent(insertions, new_text.clone(), cx);
buffer.edit_with_autoindent(deletions, "", indent_size, cx);
buffer.edit_with_autoindent(insertions, new_text.clone(), indent_size, cx);
} else {
buffer.edit(deletions, "", cx);
buffer.edit(insertions, new_text.clone(), cx);