Make gutters padding automatic (#3163)

Remove padding gutter type, and automatically add 1 padding if gutters is
non-empty.
pull/3168/head^2
Ivan Tham 2 years ago committed by GitHub
parent bfdcfec8c9
commit 2f980471f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -38,7 +38,7 @@ hidden = false
| `shell` | Shell to use when running external commands. | Unix: `["sh", "-c"]`<br/>Windows: `["cmd", "/C"]` | | `shell` | Shell to use when running external commands. | Unix: `["sh", "-c"]`<br/>Windows: `["cmd", "/C"]` |
| `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` | | `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` |
| `cursorline` | Highlight all lines with a cursor. | `false` | | `cursorline` | Highlight all lines with a cursor. | `false` |
| `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"]` | | `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"]` |
| `auto-completion` | Enable automatic pop up of auto-completion. | `true` | | `auto-completion` | Enable automatic pop up of auto-completion. | `true` |
| `auto-format` | Enable automatic formatting on save. | `true` | | `auto-format` | Enable automatic formatting on save. | `true` |
| `idle-timeout` | Time in milliseconds since last keypress before idle timers trigger. Used for autocompletion, set to 0 for instant. | `400` | | `idle-timeout` | Time in milliseconds since last keypress before idle timers trigger. Used for autocompletion, set to 0 for instant. | `400` |

@ -118,6 +118,9 @@ impl View {
width as usize, width as usize,
)); ));
} }
if !gutter_types.is_empty() {
gutter_offset += 1;
}
Self { Self {
id: ViewId::default(), id: ViewId::default(),
doc, doc,
@ -346,11 +349,7 @@ mod tests {
fn test_text_pos_at_screen_coords() { fn test_text_pos_at_screen_coords() {
let mut view = View::new( let mut view = View::new(
DocumentId::default(), DocumentId::default(),
vec![ vec![GutterType::Diagnostics, GutterType::LineNumbers],
GutterType::Diagnostics,
GutterType::LineNumbers,
GutterType::Padding,
],
); );
view.area = Rect::new(40, 40, 40, 40); view.area = Rect::new(40, 40, 40, 40);
let rope = Rope::from_str("abc\n\tdef"); let rope = Rope::from_str("abc\n\tdef");
@ -397,10 +396,7 @@ mod tests {
#[test] #[test]
fn test_text_pos_at_screen_coords_without_line_numbers_gutter() { fn test_text_pos_at_screen_coords_without_line_numbers_gutter() {
let mut view = View::new( let mut view = View::new(DocumentId::default(), vec![GutterType::Diagnostics]);
DocumentId::default(),
vec![GutterType::Diagnostics, GutterType::Padding],
);
view.area = Rect::new(40, 40, 40, 40); view.area = Rect::new(40, 40, 40, 40);
let rope = Rope::from_str("abc\n\tdef"); let rope = Rope::from_str("abc\n\tdef");
let text = rope.slice(..); let text = rope.slice(..);
@ -426,11 +422,7 @@ mod tests {
fn test_text_pos_at_screen_coords_cjk() { fn test_text_pos_at_screen_coords_cjk() {
let mut view = View::new( let mut view = View::new(
DocumentId::default(), DocumentId::default(),
vec![ vec![GutterType::Diagnostics, GutterType::LineNumbers],
GutterType::Diagnostics,
GutterType::LineNumbers,
GutterType::Padding,
],
); );
view.area = Rect::new(40, 40, 40, 40); view.area = Rect::new(40, 40, 40, 40);
let rope = Rope::from_str("Hi! こんにちは皆さん"); let rope = Rope::from_str("Hi! こんにちは皆さん");
@ -470,11 +462,7 @@ mod tests {
fn test_text_pos_at_screen_coords_graphemes() { fn test_text_pos_at_screen_coords_graphemes() {
let mut view = View::new( let mut view = View::new(
DocumentId::default(), DocumentId::default(),
vec![ vec![GutterType::Diagnostics, GutterType::LineNumbers],
GutterType::Diagnostics,
GutterType::LineNumbers,
GutterType::Padding,
],
); );
view.area = Rect::new(40, 40, 40, 40); view.area = Rect::new(40, 40, 40, 40);
let rope = Rope::from_str("Hèl̀l̀ò world!"); let rope = Rope::from_str("Hèl̀l̀ò world!");

Loading…
Cancel
Save