From 4f335fabc834cac064c83ec2ec9f72ae4741f289 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bla=C5=BE=20Hrastnik?= Date: Wed, 19 May 2021 00:34:46 +0900 Subject: [PATCH] Fix unindent to work with tabs, take a count --- helix-term/src/commands.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 45f8420ef..07e57cf4d 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)) } }