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

Expose line numbers width in config #3953

Closed
wants to merge 1 commit into from
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
16 changes: 14 additions & 2 deletions helix-view/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ pub struct Config {
pub indent_guides: IndentGuidesConfig,
/// Whether to color modes with different colors. Defaults to `false`.
pub color_modes: bool,
pub line_numbers_width: u16,
}

#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
Expand Down Expand Up @@ -577,6 +578,7 @@ impl Default for Config {
bufferline: BufferLine::default(),
indent_guides: IndentGuidesConfig::default(),
color_modes: false,
line_numbers_width: 5,
}
}
}
Expand Down Expand Up @@ -973,7 +975,13 @@ impl Editor {
.try_get(self.tree.focus)
.filter(|v| id == v.doc) // Different Document
.cloned()
.unwrap_or_else(|| View::new(id, self.config().gutters.clone()));
.unwrap_or_else(|| {
View::new(
id,
self.config().gutters.clone(),
self.config().line_numbers_width,
)
});
let view_id = self.tree.split(
view,
match action {
Expand Down Expand Up @@ -1111,7 +1119,11 @@ impl Editor {
.map(|(&doc_id, _)| doc_id)
.next()
.unwrap_or_else(|| self.new_document(Document::default()));
let view = View::new(doc_id, self.config().gutters.clone());
let view = View::new(
doc_id,
self.config().gutters.clone(),
self.config().line_numbers_width,
);
let view_id = self.tree.insert(view);
let doc = doc_mut!(self, &doc_id);
doc.ensure_view_init(view_id);
Expand Down
8 changes: 6 additions & 2 deletions helix-view/src/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,18 @@ impl fmt::Debug for View {
}

impl View {
pub fn new(doc: DocumentId, gutter_types: Vec<crate::editor::GutterType>) -> Self {
pub fn new(
doc: DocumentId,
gutter_types: Vec<crate::editor::GutterType>,
line_numbers_width: u16,
) -> Self {
let mut gutters: Vec<(Gutter, usize)> = vec![];
let mut gutter_offset = 0;
use crate::editor::GutterType;
for gutter_type in &gutter_types {
let width = match gutter_type {
GutterType::Diagnostics => 1,
GutterType::LineNumbers => 5,
GutterType::LineNumbers => line_numbers_width,
GutterType::Spacer => 1,
};
gutter_offset += width;
Expand Down