@@ -543,7 +543,7 @@ pub fn paste(view: &mut View, _count: usize) {
544const TAB_WIDTH: usize = 4;
544const TAB_WIDTH: usize = 4;
546−pub fn indent(view: &mut View, _count: usize) {
546+fn get_lines(view: &View) -> Vec<usize> {
547 let mut lines = Vec::new();
547 let mut lines = Vec::new();
549 // Get all line numbers
549 // Get all line numbers
@@ -557,6 +557,11 @@ pub fn indent(view: &mut View, _count: usize) {
558 lines.sort_unstable(); // sorting by usize so _unstable is preferred
558 lines.sort_unstable(); // sorting by usize so _unstable is preferred
559 lines.dedup();
559 lines.dedup();
563+pub fn indent(view: &mut View, _count: usize) {
564+ let lines = get_lines(view);
561 // Indent by one level
566 // Indent by one level
562 let indent = Tendril::from(" ".repeat(TAB_WIDTH));
567 let indent = Tendril::from(" ".repeat(TAB_WIDTH));
@@ -573,5 +578,33 @@ pub fn indent(view: &mut View, _count: usize) {
575pub fn unindent(view: &mut View, _count: usize) {
580pub fn unindent(view: &mut View, _count: usize) {
576− unimplemented!()
581+ let lines = get_lines(view);
582+ let mut changes = Vec::with_capacity(lines.len());
584+ for line_idx in lines {
585+ let line = view.state.doc.line(line_idx);
588+ for ch in line.chars() {
591+ '\t' => width = (width / TAB_WIDTH + 1) * TAB_WIDTH,
595+ if width >= TAB_WIDTH {
601+ let start = view.state.doc.line_to_char(line_idx);
602+ changes.push((start, start + width, None))
606+ let transaction = Transaction::change(&view.state, changes.into_iter());
608+ transaction.apply(&mut view.state);
609+ append_changes_to_history(view);