From c32f9ad2edefd9684d8b730074f1bee1796c2b17 Mon Sep 17 00:00:00 2001 From: Robin Date: Mon, 12 Sep 2022 17:27:10 +0200 Subject: [PATCH 1/7] Add option to skip the first indent guide --- helix-term/src/ui/editor.rs | 6 +++++- helix-view/src/editor.rs | 4 +++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index 7cb29c3b1ecb..c9260932f4d6 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -417,6 +417,7 @@ impl EditorView { " ".to_string() }; let indent_guide_char = config.indent_guides.character.to_string(); + let skip_first_indent_guide = config.indent_guides.skip_first; let text_style = theme.get("ui.text"); let whitespace_style = theme.get("ui.virtual.whitespace"); @@ -436,7 +437,10 @@ impl EditorView { return; } - let starting_indent = (offset.col / tab_width) as u16; + let mut starting_indent = (offset.col / tab_width) as u16; + if skip_first_indent_guide { + starting_indent += 1 + } // TODO: limit to a max indent level too. It doesn't cause visual artifacts but it would avoid some // extra loops if the code is deeply nested. diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index 5eff998360ef..2bb00d8ed306 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -529,8 +529,9 @@ impl Default for WhitespaceCharacters { } #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] -#[serde(default)] +#[serde(default, rename_all = "kebab-case")] pub struct IndentGuidesConfig { + pub skip_first: bool, pub render: bool, pub character: char, } @@ -538,6 +539,7 @@ pub struct IndentGuidesConfig { impl Default for IndentGuidesConfig { fn default() -> Self { Self { + skip_first: false, render: false, character: '│', } From 3ab274ca4020093e088fa39fca10464c5dc263b6 Mon Sep 17 00:00:00 2001 From: Robin Date: Tue, 13 Sep 2022 10:00:53 +0200 Subject: [PATCH 2/7] reorder skip_first option --- helix-view/src/editor.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index 2bb00d8ed306..f1dafb53013c 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -531,9 +531,9 @@ impl Default for WhitespaceCharacters { #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] #[serde(default, rename_all = "kebab-case")] pub struct IndentGuidesConfig { - pub skip_first: bool, pub render: bool, pub character: char, + pub skip_first: bool, } impl Default for IndentGuidesConfig { From 7194869fd627e5beca3f3dda0518dea263649e58 Mon Sep 17 00:00:00 2001 From: Robin Date: Tue, 13 Sep 2022 10:06:13 +0200 Subject: [PATCH 3/7] change indent-guides.skip_first to a number --- helix-term/src/ui/editor.rs | 5 +---- helix-view/src/editor.rs | 4 ++-- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index c9260932f4d6..40dec3ef262e 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -417,7 +417,6 @@ impl EditorView { " ".to_string() }; let indent_guide_char = config.indent_guides.character.to_string(); - let skip_first_indent_guide = config.indent_guides.skip_first; let text_style = theme.get("ui.text"); let whitespace_style = theme.get("ui.virtual.whitespace"); @@ -438,9 +437,7 @@ impl EditorView { } let mut starting_indent = (offset.col / tab_width) as u16; - if skip_first_indent_guide { - starting_indent += 1 - } + starting_indent += config.indent_guides.skip; // TODO: limit to a max indent level too. It doesn't cause visual artifacts but it would avoid some // extra loops if the code is deeply nested. diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index f1dafb53013c..eeaf058f228a 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -533,13 +533,13 @@ impl Default for WhitespaceCharacters { pub struct IndentGuidesConfig { pub render: bool, pub character: char, - pub skip_first: bool, + pub skip: u16, } impl Default for IndentGuidesConfig { fn default() -> Self { Self { - skip_first: false, + skip: 0, render: false, character: '│', } From 1d9159f411925a47bbc7c1a1fccddfa879ea709a Mon Sep 17 00:00:00 2001 From: Robin Date: Tue, 13 Sep 2022 14:12:39 +0200 Subject: [PATCH 4/7] rename skip -> skip_levels --- helix-term/src/ui/editor.rs | 2 +- helix-view/src/editor.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index 40dec3ef262e..d5a8ac2f6081 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -437,7 +437,7 @@ impl EditorView { } let mut starting_indent = (offset.col / tab_width) as u16; - starting_indent += config.indent_guides.skip; + starting_indent += config.indent_guides.skip_levels; // TODO: limit to a max indent level too. It doesn't cause visual artifacts but it would avoid some // extra loops if the code is deeply nested. diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index eeaf058f228a..c6b301ee089e 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -533,13 +533,13 @@ impl Default for WhitespaceCharacters { pub struct IndentGuidesConfig { pub render: bool, pub character: char, - pub skip: u16, + pub skip_levels: u16, } impl Default for IndentGuidesConfig { fn default() -> Self { Self { - skip: 0, + skip_levels: 0, render: false, character: '│', } From 727657edcc1e90ae9505f26320a670d6bb12f689 Mon Sep 17 00:00:00 2001 From: Robin Date: Tue, 13 Sep 2022 14:12:50 +0200 Subject: [PATCH 5/7] add skip_levels to the book --- book/src/configuration.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/book/src/configuration.md b/book/src/configuration.md index fdabe7687dd3..f5a8f3c9c695 100644 --- a/book/src/configuration.md +++ b/book/src/configuration.md @@ -218,10 +218,11 @@ tabpad = "·" # Tabs will look like "→···" (depending on tab width) Options for rendering vertical indent guides. -| Key | Description | Default | -| --- | --- | --- | -| `render` | Whether to render indent guides. | `false` | -| `character` | Literal character to use for rendering the indent guide | `│` | +| Key | Description | Default | +| --- | --- | --- | +| `render` | Whether to render indent guides. | `false` | +| `character` | Literal character to use for rendering the indent guide | `│` | +| `skip-levels` | amount of indent levels to skip | `0` | Example: @@ -229,4 +230,5 @@ Example: [editor.indent-guides] render = true character = "╎" +skip-levels = 1 ``` From 14a21c464350e638e8a796c00977fdec7fc6e347 Mon Sep 17 00:00:00 2001 From: Robin Date: Wed, 14 Sep 2022 10:57:18 +0200 Subject: [PATCH 6/7] Update book/src/configuration.md Co-authored-by: A-Walrus <58790821+A-Walrus@users.noreply.github.com> --- book/src/configuration.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/book/src/configuration.md b/book/src/configuration.md index f5a8f3c9c695..1f32b6578a11 100644 --- a/book/src/configuration.md +++ b/book/src/configuration.md @@ -222,7 +222,7 @@ Options for rendering vertical indent guides. | --- | --- | --- | | `render` | Whether to render indent guides. | `false` | | `character` | Literal character to use for rendering the indent guide | `│` | -| `skip-levels` | amount of indent levels to skip | `0` | +| `skip-levels` | Number of indent levels to skip | `0` | Example: From 39eb0310ccaada636af70995000566fa8e1ae1ad Mon Sep 17 00:00:00 2001 From: Robin Date: Tue, 20 Sep 2022 10:54:21 +0200 Subject: [PATCH 7/7] Update helix-term/src/ui/editor.rs Co-authored-by: Michael Davis --- helix-term/src/ui/editor.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index d5a8ac2f6081..4d450faa5b73 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -436,8 +436,8 @@ impl EditorView { return; } - let mut starting_indent = (offset.col / tab_width) as u16; - starting_indent += config.indent_guides.skip_levels; + let starting_indent = + (offset.col / tab_width) as u16 + config.indent_guides.skip_levels; // TODO: limit to a max indent level too. It doesn't cause visual artifacts but it would avoid some // extra loops if the code is deeply nested.