summaryrefslogtreecommitdiff
path: root/helix-term/src/commands.rs
diff options
context:
space:
mode:
authorSkyler Hawthorne2023-04-14 15:00:15 +0000
committerBlaž Hrastnik2023-08-10 21:22:22 +0000
commit7078e8400736dce923be44a4d26f136a22640f93 (patch)
treee1f9d821b605c5809d3210a79b91922c6edeb06b /helix-term/src/commands.rs
parent57f093d83641642ad5d4ba42ae59f03272efcfcc (diff)
Fix YAML auto indent
YAML indents queries are tweaked to fix auto indent behavior. A new capture type `indent.always` is introduced to address use cases where combining indent captures on a single line is desired. Fixes #6661
Diffstat (limited to 'helix-term/src/commands.rs')
-rw-r--r--helix-term/src/commands.rs8
1 files changed, 6 insertions, 2 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index 8be0f83a..61c647d0 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -2999,6 +2999,7 @@ fn open(cx: &mut Context, open: Open) {
Open::Below => graphemes::prev_grapheme_boundary(text, range.to()),
Open::Above => range.from(),
});
+
let new_line = match open {
// adjust position to the end of the line (next line - 1)
Open::Below => cursor_line + 1,
@@ -3006,13 +3007,15 @@ fn open(cx: &mut Context, open: Open) {
Open::Above => cursor_line,
};
+ let line_num = new_line.saturating_sub(1);
+
// Index to insert newlines after, as well as the char width
// to use to compensate for those inserted newlines.
let (line_end_index, line_end_offset_width) = if new_line == 0 {
(0, 0)
} else {
(
- line_end_char_index(&doc.text().slice(..), new_line.saturating_sub(1)),
+ line_end_char_index(&text, line_num),
doc.line_ending.len_chars(),
)
};
@@ -3023,10 +3026,11 @@ fn open(cx: &mut Context, open: Open) {
&doc.indent_style,
doc.tab_width(),
text,
- new_line.saturating_sub(1),
+ line_num,
line_end_index,
cursor_line,
);
+
let indent_len = indent.len();
let mut text = String::with_capacity(1 + indent_len);
text.push_str(doc.line_ending.as_str());