mirror of
https://github.com/helix-editor/helix.git
synced 2025-01-20 05:57:06 +04:00
Fix unindent to work with tabs, take a count
This commit is contained in:
parent
f366b97bce
commit
4f335fabc8
@ -1873,14 +1873,17 @@ pub fn indent(cx: &mut Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn unindent(cx: &mut Context) {
|
pub fn unindent(cx: &mut Context) {
|
||||||
|
let count = cx.count;
|
||||||
let (view, doc) = cx.current();
|
let (view, doc) = cx.current();
|
||||||
let lines = get_lines(doc, view.id);
|
let lines = get_lines(doc, view.id);
|
||||||
let mut changes = Vec::with_capacity(lines.len());
|
let mut changes = Vec::with_capacity(lines.len());
|
||||||
let tab_width = doc.tab_width();
|
let tab_width = doc.tab_width();
|
||||||
|
let indent_width = count * tab_width;
|
||||||
|
|
||||||
for line_idx in lines {
|
for line_idx in lines {
|
||||||
let line = doc.text().line(line_idx);
|
let line = doc.text().line(line_idx);
|
||||||
let mut width = 0;
|
let mut width = 0;
|
||||||
|
let mut pos = 0;
|
||||||
|
|
||||||
for ch in line.chars() {
|
for ch in line.chars() {
|
||||||
match ch {
|
match ch {
|
||||||
@ -1889,14 +1892,17 @@ pub fn unindent(cx: &mut Context) {
|
|||||||
_ => break,
|
_ => break,
|
||||||
}
|
}
|
||||||
|
|
||||||
if width >= tab_width {
|
pos += 1;
|
||||||
|
|
||||||
|
if width >= indent_width {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if width > 0 {
|
// now delete from start to first non-blank
|
||||||
|
if pos > 0 {
|
||||||
let start = doc.text().line_to_char(line_idx);
|
let start = doc.text().line_to_char(line_idx);
|
||||||
changes.push((start, start + width, None))
|
changes.push((start, start + pos, None))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user