diff --git a/src/editor/mod.rs b/src/editor/mod.rs index c83a8b1..5565d21 100644 --- a/src/editor/mod.rs +++ b/src/editor/mod.rs @@ -16,6 +16,7 @@ pub struct Editor { pub buffer: Buffer, pub file_path: Path, pub soft_tabs: bool, + pub soft_tab_width: u8, pub dirty: bool, // The dimensions and position of the editor's view within the buffer @@ -34,6 +35,7 @@ impl Editor { buffer: Buffer::new(formatter), file_path: Path::new(""), soft_tabs: false, + soft_tab_width: 4, dirty: false, view_dim: (0, 0), view_pos: (0, 0), @@ -52,6 +54,7 @@ impl Editor { buffer: buf, file_path: path.clone(), soft_tabs: false, + soft_tab_width: 4, dirty: false, view_dim: (0, 0), view_pos: (0, 0), @@ -163,13 +166,11 @@ impl Editor { } } - // TODO - //self.soft_tabs = true; - //self.buffer.formatter.tab_width = width as u8; + self.soft_tabs = true; + self.soft_tab_width = width as u8; } else { - // TODO - //self.soft_tabs = false; + self.soft_tabs = false; } } @@ -274,8 +275,7 @@ impl Editor { // Figure out how many spaces to insert let (_, vis_pos) = self.buffer.index_to_v2d(c.range.0); // TODO: handle tab settings - //let next_tab_stop = ((vis_pos / self.buffer.formatter.tab_width as usize) + 1) * self.buffer.formatter.tab_width as usize; - let next_tab_stop = ((vis_pos / 4) + 1) * 4 as usize; + let next_tab_stop = ((vis_pos / self.soft_tab_width as usize) + 1) * self.soft_tab_width as usize; let space_count = min(next_tab_stop - vis_pos, 8); diff --git a/src/term_ui/mod.rs b/src/term_ui/mod.rs index f77aace..63b0c4e 100644 --- a/src/term_ui/mod.rs +++ b/src/term_ui/mod.rs @@ -329,7 +329,7 @@ impl TermUI { LineEnding::PS => "PS", }; let soft_tabs_str = if editor.soft_tabs {"spaces"} else {"tabs"}; - let info_line = format!("UTF8:{} {}:{}", nl, soft_tabs_str, editor.buffer.formatter.tab_width as usize); + let info_line = format!("UTF8:{} {}:{}", nl, soft_tabs_str, editor.soft_tab_width as usize); self.rb.print(c2.1 - 30, c1.0, rustbox::RB_NORMAL, foreground, background, info_line.as_slice()); // Draw main text editing area diff --git a/todo.md b/todo.md index 100d105..072937c 100644 --- a/todo.md +++ b/todo.md @@ -9,7 +9,7 @@ preferences for tab width (specified in spaces) and line wrapping. The freetype formatter should not reference SDL at all, and should have only the freetype library itself as a dependency. - - Handle tab settings properly after the refactor + //- Handle tab settings properly after the refactor - Possibly split the text buffer out into its own library...? Would likely be useful to other people as well, and would encourage me to keep the API clean.