Skip to content

Commit

Permalink
Make gutters padding automatic
Browse files Browse the repository at this point in the history
Remove padding gutter type, and automatically add 1 padding if gutters is
non-empty.

Fix #3111
  • Loading branch information
pickfire committed Jul 23, 2022
1 parent 1b3a10d commit c155990
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 40 deletions.
2 changes: 1 addition & 1 deletion book/src/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ hidden = false
| `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` |
| `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`, note that `diagnostics` also includes other features like breakpoints | `["diagnostics", "line-numbers"]` |
| `auto-completion` | Enable automatic pop up of auto-completion. | `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` |
Expand Down
8 changes: 1 addition & 7 deletions helix-view/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,6 @@ pub enum GutterType {
Diagnostics,
/// Show line numbers
LineNumbers,
/// Show one blank space
Padding,
}

impl std::str::FromStr for GutterType {
Expand Down Expand Up @@ -470,11 +468,7 @@ impl Default for Config {
},
line_number: LineNumber::Absolute,
cursorline: false,
gutters: vec![
GutterType::Diagnostics,
GutterType::LineNumbers,
GutterType::Padding,
],
gutters: vec![GutterType::Diagnostics, GutterType::LineNumbers],
middle_click_paste: true,
auto_pairs: AutoPairConfig::default(),
auto_completion: true,
Expand Down
11 changes: 0 additions & 11 deletions helix-view/src/gutter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,17 +102,6 @@ pub fn line_numbers<'doc>(
})
}

pub fn padding<'doc>(
_editor: &'doc Editor,
_doc: &'doc Document,
_view: &View,
_theme: &Theme,
_is_focused: bool,
_width: usize,
) -> GutterFn<'doc> {
Box::new(|_line: usize, _selected: bool, _out: &mut String| None)
}

#[inline(always)]
const fn abs_diff(a: usize, b: usize) -> usize {
if a > b {
Expand Down
28 changes: 7 additions & 21 deletions helix-view/src/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,19 @@ impl View {
let width = match gutter_type {
GutterType::Diagnostics => 1,
GutterType::LineNumbers => 5,
GutterType::Padding => 1,
};
gutter_offset += width;
gutters.push((
match gutter_type {
GutterType::Diagnostics => gutter::diagnostics_or_breakpoints,
GutterType::LineNumbers => gutter::line_numbers,
GutterType::Padding => gutter::padding,
},
width as usize,
));
}
if !gutter_types.is_empty() {
gutter_offset += 1;
}
Self {
id: ViewId::default(),
doc,
Expand Down Expand Up @@ -346,11 +347,7 @@ mod tests {
fn test_text_pos_at_screen_coords() {
let mut view = View::new(
DocumentId::default(),
vec![
GutterType::Diagnostics,
GutterType::LineNumbers,
GutterType::Padding,
],
vec![GutterType::Diagnostics, GutterType::LineNumbers],
);
view.area = Rect::new(40, 40, 40, 40);
let rope = Rope::from_str("abc\n\tdef");
Expand Down Expand Up @@ -397,10 +394,7 @@ mod tests {

#[test]
fn test_text_pos_at_screen_coords_without_line_numbers_gutter() {
let mut view = View::new(
DocumentId::default(),
vec![GutterType::Diagnostics, GutterType::Padding],
);
let mut view = View::new(DocumentId::default(), vec![GutterType::Diagnostics]);
view.area = Rect::new(40, 40, 40, 40);
let rope = Rope::from_str("abc\n\tdef");
let text = rope.slice(..);
Expand All @@ -426,11 +420,7 @@ mod tests {
fn test_text_pos_at_screen_coords_cjk() {
let mut view = View::new(
DocumentId::default(),
vec![
GutterType::Diagnostics,
GutterType::LineNumbers,
GutterType::Padding,
],
vec![GutterType::Diagnostics, GutterType::LineNumbers],
);
view.area = Rect::new(40, 40, 40, 40);
let rope = Rope::from_str("Hi! こんにちは皆さん");
Expand Down Expand Up @@ -470,11 +460,7 @@ mod tests {
fn test_text_pos_at_screen_coords_graphemes() {
let mut view = View::new(
DocumentId::default(),
vec![
GutterType::Diagnostics,
GutterType::LineNumbers,
GutterType::Padding,
],
vec![GutterType::Diagnostics, GutterType::LineNumbers],
);
view.area = Rect::new(40, 40, 40, 40);
let rope = Rope::from_str("Hèl̀l̀ò world!");
Expand Down

0 comments on commit c155990

Please sign in to comment.