Skip to content

Commit 1fd014a

Browse files
author
Jonathan Turner
committed
Add fix for tabs. Move error unit tests->ui tests
1 parent 2e8e73c commit 1fd014a

17 files changed

+414
-772
lines changed

src/librustc_errors/styled_buffer.rs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,27 @@ impl StyledBuffer {
2626
}
2727
}
2828

29-
pub fn render(&self) -> Vec<Vec<StyledString>> {
29+
pub fn copy_tabs(&mut self, row: usize) {
30+
if row < self.text.len() {
31+
for i in row+1..self.text.len() {
32+
for j in 0..self.text[i].len() {
33+
if self.text[row].len() > j &&
34+
self.text[row][j] == '\t' &&
35+
self.text[i][j] == ' ' {
36+
self.text[i][j] = '\t';
37+
}
38+
}
39+
}
40+
}
41+
}
42+
43+
pub fn render(&mut self) -> Vec<Vec<StyledString>> {
3044
let mut output: Vec<Vec<StyledString>> = vec![];
3145
let mut styled_vec: Vec<StyledString> = vec![];
3246

47+
//before we render, do a little patch-up work to support tabs
48+
self.copy_tabs(3);
49+
3350
for (row, row_style) in self.text.iter().zip(&self.styles) {
3451
let mut current_style = Style::NoStyle;
3552
let mut current_text = String::new();
@@ -78,11 +95,7 @@ impl StyledBuffer {
7895
} else {
7996
let mut i = self.text[line].len();
8097
while i < col {
81-
let s = match self.text[0].get(i) {
82-
Some(&'\t') => '\t',
83-
_ => ' ',
84-
};
85-
self.text[line].push(s);
98+
self.text[line].push(' ');
8699
self.styles[line].push(Style::NoStyle);
87100
i += 1;
88101
}

0 commit comments

Comments
 (0)