diff options
author | Blaž Hrastnik | 2021-05-18 15:34:46 +0000 |
---|---|---|
committer | Blaž Hrastnik | 2021-05-18 15:35:33 +0000 |
commit | 4f335fabc834cac064c83ec2ec9f72ae4741f289 (patch) | |
tree | 788d87530ff54208d0ee36db374133aad4800b39 | |
parent | f366b97bcea331b4e70afe91f8f33f7fdbe44161 (diff) |
Fix unindent to work with tabs, take a count
-rw-r--r-- | helix-term/src/commands.rs | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 45f8420e..07e57cf4 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -1873,14 +1873,17 @@ pub fn indent(cx: &mut Context) { } pub fn unindent(cx: &mut Context) { + let count = cx.count; let (view, doc) = cx.current(); let lines = get_lines(doc, view.id); let mut changes = Vec::with_capacity(lines.len()); let tab_width = doc.tab_width(); + let indent_width = count * tab_width; for line_idx in lines { let line = doc.text().line(line_idx); let mut width = 0; + let mut pos = 0; for ch in line.chars() { match ch { @@ -1889,14 +1892,17 @@ pub fn unindent(cx: &mut Context) { _ => break, } - if width >= tab_width { + pos += 1; + + if width >= indent_width { break; } } - if width > 0 { + // now delete from start to first non-blank + if pos > 0 { let start = doc.text().line_to_char(line_idx); - changes.push((start, start + width, None)) + changes.push((start, start + pos, None)) } } |