Fix two auto-indent issues with Markdown and YAML (#20193)

Closes #13376
Closes #13338

Release Notes:

- Fixed unhelpful auto-indent suggestions in markdown.
- Added `auto_indent_on_paste` setting, which can be used on a
per-language basis, to configure whether indentation should be adjusted
when pasting. This setting is enabled by default for languages other
than YAML and Markdown.
This commit is contained in:
Max Brunsfeld
2024-11-04 12:29:38 -08:00
committed by GitHub
parent cfcbfc1d82
commit 4d3a18cbdc
7 changed files with 29 additions and 3 deletions
+12 -3
View File
@@ -7280,9 +7280,14 @@ impl Editor {
if clipboard_selections.len() != old_selections.len() {
clipboard_selections.drain(..);
}
let cursor_offset = this.selections.last::<usize>(cx).head();
let mut auto_indent_on_paste = true;
this.buffer.update(cx, |buffer, cx| {
let snapshot = buffer.read(cx);
auto_indent_on_paste =
snapshot.settings_at(cursor_offset, cx).auto_indent_on_paste;
let mut start_offset = 0;
let mut edits = Vec::new();
let mut original_indent_columns = Vec::new();
@@ -7321,9 +7326,13 @@ impl Editor {
buffer.edit(
edits,
Some(AutoindentMode::Block {
original_indent_columns,
}),
if auto_indent_on_paste {
Some(AutoindentMode::Block {
original_indent_columns,
})
} else {
None
},
cx,
);
});