Skip to content

Commit

Permalink
Switch to tabpad configuration option (helix-editor#3458)
Browse files Browse the repository at this point in the history
Virtual whitespace tabs are created from the `tab` character padded
with `tabpad` up to  the tab width.
  • Loading branch information
A-Walrus authored and jdrst committed Sep 13, 2022
1 parent f5b450d commit f06296e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
3 changes: 2 additions & 1 deletion book/src/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ Options for rendering whitespace with visible characters. Use `:set whitespace.r
| Key | Description | Default |
|-----|-------------|---------|
| `render` | Whether to render whitespace. May either be `"all"` or `"none"`, or a table with sub-keys `space`, `tab`, and `newline`. | `"none"` |
| `characters` | Literal characters to use when rendering whitespace. Sub-keys may be any of `tab`, `space`, `nbsp` or `newline` | See example below |
| `characters` | Literal characters to use when rendering whitespace. Sub-keys may be any of `tab`, `space`, `nbsp`, `newline` or `tabpad` | See example below |

Example

Expand All @@ -210,6 +210,7 @@ space = "·"
nbsp = ""
tab = ""
newline = ""
tabpad = "·" # Tabs will look like "→···" (depending on tab width)
```

### `[editor.indent-guides]` Section
Expand Down
12 changes: 8 additions & 4 deletions helix-term/src/ui/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,19 +390,23 @@ impl EditorView {
// of times than it is to always call Rope::slice/get_slice (it will internally always hit RSEnum::Light).
let text = doc.text().slice(..);

let characters = &whitespace.characters;

let mut spans = Vec::new();
let mut visual_x = 0u16;
let mut line = 0u16;
let tab_width = doc.tab_width();
let tab = if whitespace.render.tab() == WhitespaceRenderValue::All {
(1..tab_width).fold(whitespace.characters.tab.to_string(), |s, _| s + " ")
std::iter::once(characters.tab)
.chain(std::iter::repeat(characters.tabpad).take(tab_width - 1))
.collect()
} else {
" ".repeat(tab_width)
};
let space = whitespace.characters.space.to_string();
let nbsp = whitespace.characters.nbsp.to_string();
let space = characters.space.to_string();
let nbsp = characters.nbsp.to_string();
let newline = if whitespace.render.newline() == WhitespaceRenderValue::All {
whitespace.characters.newline.to_string()
characters.newline.to_string()
} else {
" ".to_string()
};
Expand Down
2 changes: 2 additions & 0 deletions helix-view/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,7 @@ pub struct WhitespaceCharacters {
pub space: char,
pub nbsp: char,
pub tab: char,
pub tabpad: char,
pub newline: char,
}

Expand All @@ -448,6 +449,7 @@ impl Default for WhitespaceCharacters {
nbsp: '⍽', // U+237D
tab: '→', // U+2192
newline: '⏎', // U+23CE
tabpad: ' ',
}
}
}
Expand Down

0 comments on commit f06296e

Please sign in to comment.