on master help sign in
Make gutters padding automatic (#3163)

Remove padding gutter type, and automatically add 1 padding if gutters is non-empty.

commit2f980471f816e841628cf2b75d8d8e689b3fe9d5 authorIvan Tham <pickfire@riseup.net> dateTue 26 Jul 2022, 09:08 (4 years ago) parentbfdcfec
2 files changed+8−20
book/src/configuration.md+1−1 helix-view/src/view.rs+7−19
book/src/configuration.md+1−1
@@ -38,7 +38,7 @@ hidden = false
3838| `shell` | Shell to use when running external commands. | Unix: `["sh", "-c"]`<br/>Windows: `["cmd", "/C"]` |
3939| `line-number` | Line number display: `absolute` simply shows each line's number, while `relative` shows the distance from the current line. When unfocused or in insert mode, `relative` will still show absolute line numbers. | `absolute` |
4040| `cursorline` | Highlight all lines with a cursor. | `false` |
41−| `gutters` | Gutters to display: Available are `diagnostics` and `line-numbers` and `padding`, note that `diagnostics` also includes other features like breakpoints | `["diagnostics", "line-numbers", "padding"]` |
41+| `gutters` | Gutters to display: Available are `diagnostics` and `line-numbers` and `padding`, note that `diagnostics` also includes other features like breakpoints, 1-width padding will be inserted if gutters is non-empty | `["diagnostics", "line-numbers", "padding"]` |
4242| `auto-completion` | Enable automatic pop up of auto-completion. | `true` |
4343| `auto-format` | Enable automatic formatting on save. | `true` |
4444| `idle-timeout` | Time in milliseconds since last keypress before idle timers trigger. Used for autocompletion, set to 0 for instant. | `400` |
helix-view/src/view.rs+7−19
@@ -118,6 +118,9 @@ impl View {
118118 width as usize,
119119 ));
120120 }
121+ if !gutter_types.is_empty() {
122+ gutter_offset += 1;
123+ }
121124 Self {
122125 id: ViewId::default(),
123126 doc,
@@ -346,11 +349,7 @@ mod tests {
346349 fn test_text_pos_at_screen_coords() {
347350 let mut view = View::new(
348351 DocumentId::default(),
349− vec![
350− GutterType::Diagnostics,
351− GutterType::LineNumbers,
352− GutterType::Padding,
353− ],
352+ vec![GutterType::Diagnostics, GutterType::LineNumbers],
354353 );
355354 view.area = Rect::new(40, 40, 40, 40);
356355 let rope = Rope::from_str("abc\n\tdef");
@@ -397,10 +396,7 @@ mod tests {
397396
398397 #[test]
399398 fn test_text_pos_at_screen_coords_without_line_numbers_gutter() {
400− let mut view = View::new(
401− DocumentId::default(),
402− vec![GutterType::Diagnostics, GutterType::Padding],
403− );
399+ let mut view = View::new(DocumentId::default(), vec![GutterType::Diagnostics]);
404400 view.area = Rect::new(40, 40, 40, 40);
405401 let rope = Rope::from_str("abc\n\tdef");
406402 let text = rope.slice(..);
@@ -426,11 +422,7 @@ mod tests {
426422 fn test_text_pos_at_screen_coords_cjk() {
427423 let mut view = View::new(
428424 DocumentId::default(),
429− vec![
430− GutterType::Diagnostics,
431− GutterType::LineNumbers,
432− GutterType::Padding,
433− ],
425+ vec![GutterType::Diagnostics, GutterType::LineNumbers],
434426 );
435427 view.area = Rect::new(40, 40, 40, 40);
436428 let rope = Rope::from_str("Hi! こんにちは皆さん");
@@ -470,11 +462,7 @@ mod tests {
470462 fn test_text_pos_at_screen_coords_graphemes() {
471463 let mut view = View::new(
472464 DocumentId::default(),
473− vec![
474− GutterType::Diagnostics,
475− GutterType::LineNumbers,
476− GutterType::Padding,
477− ],
465+ vec![GutterType::Diagnostics, GutterType::LineNumbers],
478466 );
479467 view.area = Rect::new(40, 40, 40, 40);
480468 let rope = Rope::from_str("Hèl̀l̀ò world!");