Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

undo change, no magically added space please, just add Spacer by default #3288

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion book/src/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ You may also specify a file to use for configuration with the `-c` or
| `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 `spacer`, note that `diagnostics` also includes other features like breakpoints, 1-width padding will be inserted if gutters is non-empty | `["diagnostics", "line-numbers"]` |
| `gutters` | Gutters to display: Available are `diagnostics` and `line-numbers` and `spacer`, note that `diagnostics` also includes other features like breakpoints. | `["diagnostics", "line-numbers", "spacer"]` |
| `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: 6 additions & 2 deletions helix-view/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ pub struct Config {
pub line_number: LineNumber,
/// Highlight the lines cursors are currently on. Defaults to false.
pub cursorline: bool,
/// Gutters. Default ["diagnostics", "line-numbers"]
/// Gutters. Default ["diagnostics", "line-numbers", "spacer"]
pub gutters: Vec<GutterType>,
/// Middle click paste support. Defaults to true.
pub middle_click_paste: bool,
Expand Down Expand Up @@ -557,7 +557,11 @@ impl Default for Config {
},
line_number: LineNumber::Absolute,
cursorline: false,
gutters: vec![GutterType::Diagnostics, GutterType::LineNumbers],
gutters: vec![
GutterType::Diagnostics,
GutterType::LineNumbers,
GutterType::Spacer,
],
middle_click_paste: true,
auto_pairs: AutoPairConfig::default(),
auto_completion: true,
Expand Down
70 changes: 62 additions & 8 deletions helix-view/src/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ impl View {
pub fn new(doc: DocumentId, gutter_types: Vec<crate::editor::GutterType>) -> Self {
let mut gutters: Vec<(Gutter, usize)> = vec![];
let mut gutter_offset = 0;
let mut last_gutter_is_spacer = false;
use crate::editor::GutterType;
for gutter_type in &gutter_types {
let width = match gutter_type {
Expand All @@ -117,9 +118,11 @@ impl View {
},
width as usize,
));
last_gutter_is_spacer = matches!(gutter_type, GutterType::Spacer);
}
if !gutter_types.is_empty() {
gutter_offset += 1;
if last_gutter_is_spacer && !gutter_types.is_empty() {
// pop from gutters, but leave the offset.
gutters.pop();
}
Self {
id: ViewId::default(),
Expand Down Expand Up @@ -340,16 +343,20 @@ impl View {
mod tests {
use super::*;
use helix_core::Rope;
const OFFSET: u16 = 7; // 1 diagnostic + 5 linenr + 1 gutter
const OFFSET_WITHOUT_LINE_NUMBERS: u16 = 2; // 1 diagnostic + 1 gutter
// const OFFSET: u16 = GUTTERS.iter().map(|(_, width)| *width as u16).sum();
const OFFSET: u16 = 7; // 1 diagnostic + 5 linenr + 1 spacer
const OFFSET_WITHOUT_LINE_NUMBERS: u16 = 1; // 1 diagnostic

use crate::editor::GutterType;

#[test]
fn test_text_pos_at_screen_coords() {
let mut view = View::new(
DocumentId::default(),
vec![GutterType::Diagnostics, GutterType::LineNumbers],
vec![
GutterType::Diagnostics,
GutterType::LineNumbers,
GutterType::Spacer,
],
);
view.area = Rect::new(40, 40, 40, 40);
let rope = Rope::from_str("abc\n\tdef");
Expand Down Expand Up @@ -418,11 +425,54 @@ mod tests {
);
}

#[test]
fn test_text_pos_at_screen_coords_with_spacer_gutters() {
let mut view = View::new(
DocumentId::default(),
vec![
GutterType::Diagnostics,
GutterType::Spacer,
GutterType::LineNumbers,
GutterType::Spacer,
],
);
view.area = Rect::new(40, 40, 40, 40);
let rope = Rope::from_str("abc\n\tdef");
let text = rope.slice(..);
assert_eq!(
view.text_pos_at_screen_coords(&text, 41, 40 + 1 + 1 + 5 + 1, 4),
Some(4)
);
}

#[test]
fn test_text_pos_at_screen_coords_without_last_spacer_gutters() {
let mut view = View::new(
DocumentId::default(),
vec![
GutterType::Diagnostics,
GutterType::Spacer,
GutterType::LineNumbers,
],
);
view.area = Rect::new(40, 40, 40, 40);
let rope = Rope::from_str("abc\n\tdef");
let text = rope.slice(..);
assert_eq!(
view.text_pos_at_screen_coords(&text, 41, 40 + 1 + 1 + 5, 4),
Some(4)
);
}

#[test]
fn test_text_pos_at_screen_coords_cjk() {
let mut view = View::new(
DocumentId::default(),
vec![GutterType::Diagnostics, GutterType::LineNumbers],
vec![
GutterType::Diagnostics,
GutterType::LineNumbers,
GutterType::Spacer,
],
);
view.area = Rect::new(40, 40, 40, 40);
let rope = Rope::from_str("Hi! こんにちは皆さん");
Expand Down Expand Up @@ -462,7 +512,11 @@ mod tests {
fn test_text_pos_at_screen_coords_graphemes() {
let mut view = View::new(
DocumentId::default(),
vec![GutterType::Diagnostics, GutterType::LineNumbers],
vec![
GutterType::Diagnostics,
GutterType::LineNumbers,
GutterType::Spacer,
],
);
view.area = Rect::new(40, 40, 40, 40);
let rope = Rope::from_str("Hèl̀l̀ò world!");
Expand Down