on master help sign in
Add rulers option (#2060)
5d5b6baThomas
book/src/configuration.md+1
@@ -43,6 +43,7 @@ hidden = false
43| `completion-trigger-len` | The min-length of word under cursor to trigger autocompletion | `2` |
43| `completion-trigger-len` | The min-length of word under cursor to trigger autocompletion | `2` |
44| `auto-info` | Whether to display infoboxes | `true` |
44| `auto-info` | Whether to display infoboxes | `true` |
45| `true-color` | Set to `true` to override automatic detection of terminal truecolor support in the event of a false negative. | `false` |
45| `true-color` | Set to `true` to override automatic detection of terminal truecolor support in the event of a false negative. | `false` |
46+| `rulers` | List of column positions at which to display the rulers. Can be overidden by language specific `rulers` in `languages.toml` file. | `[]` |
46
47
47### `[editor.lsp]` Section
48### `[editor.lsp]` Section
48
49
helix-core/src/syntax.rs+2
@@ -104,6 +104,8 @@ pub struct LanguageConfiguration {
104 /// global setting.
104 /// global setting.
105 #[serde(default, skip_serializing, deserialize_with = "deserialize_auto_pairs")]
105 #[serde(default, skip_serializing, deserialize_with = "deserialize_auto_pairs")]
106 pub auto_pairs: Option<AutoPairs>,
106 pub auto_pairs: Option<AutoPairs>,
107+
108+ pub rulers: Option<Vec<u16>>, // if set, override editor's rulers
107}
109}
108
110
109#[derive(Debug, Serialize, Deserialize)]
111#[derive(Debug, Serialize, Deserialize)]
helix-term/src/ui/editor.rs+27
@@ -126,6 +126,7 @@ impl EditorView {
126
126
127 Self::render_text_highlights(doc, view.offset, inner, surface, theme, highlights);
127 Self::render_text_highlights(doc, view.offset, inner, surface, theme, highlights);
128 Self::render_gutter(editor, doc, view, view.area, surface, theme, is_focused);
128 Self::render_gutter(editor, doc, view, view.area, surface, theme, is_focused);
129+ Self::render_rulers(editor, doc, view, inner, surface, theme);
129
130
130 if is_focused {
131 if is_focused {
131 Self::render_focused_view_elements(view, doc, inner, theme, surface);
132 Self::render_focused_view_elements(view, doc, inner, theme, surface);
@@ -152,6 +153,32 @@ impl EditorView {
152 self.render_statusline(doc, view, statusline_area, surface, theme, is_focused);
153 self.render_statusline(doc, view, statusline_area, surface, theme, is_focused);
153 }
154 }
154
155
156+ pub fn render_rulers(
157+ editor: &Editor,
158+ doc: &Document,
159+ view: &View,
160+ viewport: Rect,
161+ surface: &mut Surface,
162+ theme: &Theme,
163+ ) {
164+ let editor_rulers = &editor.config().rulers;
165+ let ruler_theme = theme.get("ui.virtual.ruler");
166+
167+ let rulers = doc
168+ .language_config()
169+ .and_then(|config| config.rulers.as_ref())
170+ .unwrap_or(editor_rulers);
171+
172+ rulers
173+ .iter()
174+ // View might be horizontally scrolled, convert from absolute distance
175+ // from the 1st column to relative distance from left of viewport
176+ .filter_map(|ruler| ruler.checked_sub(1 + view.offset.col as u16))
177+ .filter(|ruler| ruler < &viewport.width)
178+ .map(|ruler| viewport.clip_left(ruler).with_width(1))
179+ .for_each(|area| surface.set_style(area, ruler_theme))
180+ }
181+
155 /// Get syntax highlights for a document in a view represented by the first line
182 /// Get syntax highlights for a document in a view represented by the first line
156 /// and column (`offset`) and the last line. This is done instead of using a view
183 /// and column (`offset`) and the last line. This is done instead of using a view
157 /// directly to enable rendering syntax highlighted docs anywhere (eg. picker preview)
184 /// directly to enable rendering syntax highlighted docs anywhere (eg. picker preview)
helix-view/src/editor.rs+3
@@ -146,6 +146,8 @@ pub struct Config {
146 #[serde(default)]
146 #[serde(default)]
147 pub search: SearchConfig,
147 pub search: SearchConfig,
148 pub lsp: LspConfig,
148 pub lsp: LspConfig,
149+ /// Column numbers at which to draw the rulers. Default to `[]`, meaning no rulers.
150+ pub rulers: Vec<u16>,
149}
151}
150
152
151#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
153#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
@@ -285,6 +287,7 @@ impl Default for Config {
285 true_color: false,
287 true_color: false,
286 search: SearchConfig::default(),
288 search: SearchConfig::default(),
287 lsp: LspConfig::default(),
289 lsp: LspConfig::default(),
290+ rulers: Vec::new(),
288 }
291 }
289 }
292 }
290}
293}