Tabs working again.

This commit is contained in:
Nathan Vegdahl 2015-01-25 22:07:06 -08:00
parent 109e46a027
commit 83fa6a72cb
3 changed files with 9 additions and 9 deletions

View File

@ -16,6 +16,7 @@ pub struct Editor<T: LineFormatter> {
pub buffer: Buffer<T>, pub buffer: Buffer<T>,
pub file_path: Path, pub file_path: Path,
pub soft_tabs: bool, pub soft_tabs: bool,
pub soft_tab_width: u8,
pub dirty: bool, pub dirty: bool,
// The dimensions and position of the editor's view within the buffer // The dimensions and position of the editor's view within the buffer
@ -34,6 +35,7 @@ impl<T: LineFormatter> Editor<T> {
buffer: Buffer::new(formatter), buffer: Buffer::new(formatter),
file_path: Path::new(""), file_path: Path::new(""),
soft_tabs: false, soft_tabs: false,
soft_tab_width: 4,
dirty: false, dirty: false,
view_dim: (0, 0), view_dim: (0, 0),
view_pos: (0, 0), view_pos: (0, 0),
@ -52,6 +54,7 @@ impl<T: LineFormatter> Editor<T> {
buffer: buf, buffer: buf,
file_path: path.clone(), file_path: path.clone(),
soft_tabs: false, soft_tabs: false,
soft_tab_width: 4,
dirty: false, dirty: false,
view_dim: (0, 0), view_dim: (0, 0),
view_pos: (0, 0), view_pos: (0, 0),
@ -163,13 +166,11 @@ impl<T: LineFormatter> Editor<T> {
} }
} }
// TODO self.soft_tabs = true;
//self.soft_tabs = true; self.soft_tab_width = width as u8;
//self.buffer.formatter.tab_width = width as u8;
} }
else { else {
// TODO self.soft_tabs = false;
//self.soft_tabs = false;
} }
} }
@ -274,8 +275,7 @@ impl<T: LineFormatter> Editor<T> {
// Figure out how many spaces to insert // Figure out how many spaces to insert
let (_, vis_pos) = self.buffer.index_to_v2d(c.range.0); let (_, vis_pos) = self.buffer.index_to_v2d(c.range.0);
// TODO: handle tab settings // 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 / self.soft_tab_width as usize) + 1) * self.soft_tab_width as usize;
let next_tab_stop = ((vis_pos / 4) + 1) * 4 as usize;
let space_count = min(next_tab_stop - vis_pos, 8); let space_count = min(next_tab_stop - vis_pos, 8);

View File

@ -329,7 +329,7 @@ impl TermUI {
LineEnding::PS => "PS", LineEnding::PS => "PS",
}; };
let soft_tabs_str = if editor.soft_tabs {"spaces"} else {"tabs"}; 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()); self.rb.print(c2.1 - 30, c1.0, rustbox::RB_NORMAL, foreground, background, info_line.as_slice());
// Draw main text editing area // Draw main text editing area

View File

@ -9,7 +9,7 @@
preferences for tab width (specified in spaces) and line wrapping. preferences for tab width (specified in spaces) and line wrapping.
The freetype formatter should not reference SDL at all, and should The freetype formatter should not reference SDL at all, and should
have only the freetype library itself as a dependency. 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 - Possibly split the text buffer out into its own library...? Would
likely be useful to other people as well, and would encourage me to likely be useful to other people as well, and would encourage me to
keep the API clean. keep the API clean.