-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
tab_width
to functions instead of storing it in Word
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -193,10 +193,12 @@ where | |
let need_hyphen = !word[..idx].ends_with('-'); | ||
let w = Word { | ||
word: &word.word[prev..idx], | ||
width: display_width(&word[prev..idx], word.tab_width), | ||
// word[prev..idx] is a subset of the original word.word, | ||
// which is trimmed of whitespace in Word::from, so we | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
mtoohey31
Author
|
||
// don't need an accurate tab_width. | ||
width: display_width(&word[prev..idx], 0), | ||
whitespace: "", | ||
penalty: if need_hyphen { "-" } else { "" }, | ||
tab_width: word.tab_width, | ||
}; | ||
prev = idx; | ||
return Some(w); | ||
|
@@ -205,7 +207,9 @@ where | |
if prev < word.word.len() || prev == 0 { | ||
let w = Word { | ||
word: &word.word[prev..], | ||
width: display_width(&word[prev..], word.tab_width), | ||
// see comment by display_width call above regarding | ||
// tab_width. | ||
width: display_width(&word[prev..], 0), | ||
..word | ||
}; | ||
prev = word.word.len() + 1; | ||
|
@@ -279,15 +283,13 @@ mod tests { | |
word: "foo", | ||
width: 3, | ||
whitespace: "", | ||
penalty: "-", | ||
tab_width: 0 | ||
penalty: "-" | ||
}, | ||
Word { | ||
word: "bar", | ||
width: 3, | ||
whitespace: "", | ||
penalty: "", | ||
tab_width: 0 | ||
penalty: "" | ||
} | ||
] | ||
); | ||
|
@@ -302,15 +304,13 @@ mod tests { | |
word: "fo-", | ||
width: 3, | ||
whitespace: "", | ||
penalty: "", | ||
tab_width: 0 | ||
penalty: "" | ||
}, | ||
Word { | ||
word: "bar", | ||
width: 3, | ||
whitespace: "", | ||
penalty: "", | ||
tab_width: 0 | ||
penalty: "" | ||
} | ||
] | ||
); | ||
|
Ah nice! I had to read it twice to get it: can you instead say something like
I think that's the crucial point which allows us to skip looking for tabs.