on master help sign in
Switch to `tabpad` configuration option (#3458)

Virtual whitespace tabs are created from the `tab` character padded with `tabpad` up to the tab width.

commited74e6d5d405dd37e067c5fd41e2ae908da22a3c authorA-Walrus <58790821+A-Walrus@users.noreply.github.com> dateSun 21 Aug 2022, 07:54 (4 years ago) parente61c0b4
3 files changed+12−5
book/src/configuration.md+2−1 helix-term/src/ui/editor.rs+8−4 helix-view/src/editor.rs+2
book/src/configuration.md+2−1
@@ -192,7 +192,7 @@ Options for rendering whitespace with visible characters. Use `:set whitespace.r
192192| Key | Description | Default |
193193|-----|-------------|---------|
194194| `render` | Whether to render whitespace. May either be `"all"` or `"none"`, or a table with sub-keys `space`, `tab`, and `newline`. | `"none"` |
195−| `characters` | Literal characters to use when rendering whitespace. Sub-keys may be any of `tab`, `space`, `nbsp` or `newline` | See example below |
195+| `characters` | Literal characters to use when rendering whitespace. Sub-keys may be any of `tab`, `space`, `nbsp`, `newline` or `tabpad` | See example below |
196196
197197Example
198198
@@ -210,6 +210,7 @@ space = "·"
210210nbsp = "⍽"
211211tab = "→"
212212newline = "⏎"
213+tabpad = "·" # Tabs will look like "→···" (depending on tab width)
213214```
214215
215216### `[editor.indent-guides]` Section
helix-term/src/ui/editor.rs+8−4
@@ -390,19 +390,23 @@ impl EditorView {
390390 // of times than it is to always call Rope::slice/get_slice (it will internally always hit RSEnum::Light).
391391 let text = doc.text().slice(..);
392392
393+ let characters = &whitespace.characters;
394+
393395 let mut spans = Vec::new();
394396 let mut visual_x = 0u16;
395397 let mut line = 0u16;
396398 let tab_width = doc.tab_width();
397399 let tab = if whitespace.render.tab() == WhitespaceRenderValue::All {
398− (1..tab_width).fold(whitespace.characters.tab.to_string(), |s, _| s + " ")
400+ std::iter::once(characters.tab)
401+ .chain(std::iter::repeat(characters.tabpad).take(tab_width - 1))
402+ .collect()
399403 } else {
400404 " ".repeat(tab_width)
401405 };
402− let space = whitespace.characters.space.to_string();
403− let nbsp = whitespace.characters.nbsp.to_string();
406+ let space = characters.space.to_string();
407+ let nbsp = characters.nbsp.to_string();
404408 let newline = if whitespace.render.newline() == WhitespaceRenderValue::All {
405− whitespace.characters.newline.to_string()
409+ characters.newline.to_string()
406410 } else {
407411 " ".to_string()
408412 };
helix-view/src/editor.rs+2
@@ -438,6 +438,7 @@ pub struct WhitespaceCharacters {
438438 pub space: char,
439439 pub nbsp: char,
440440 pub tab: char,
441+ pub tabpad: char,
441442 pub newline: char,
442443}
443444
@@ -448,6 +449,7 @@ impl Default for WhitespaceCharacters {
448449 nbsp: '⍽', // U+237D
449450 tab: '→', // U+2192
450451 newline: '⏎', // U+23CE
452+ tabpad: ' ',
451453 }
452454 }
453455}