-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Make gutters padding optional #2996
Merged
archseer
merged 1 commit into
helix-editor:master
from
pickfire:optional-gutter-padding
Jul 18, 2022
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,7 +75,11 @@ pub struct View { | |
pub last_modified_docs: [Option<DocumentId>; 2], | ||
/// used to store previous selections of tree-sitter objects | ||
pub object_selections: Vec<Selection>, | ||
pub gutters: Vec<(Gutter, usize)>, | ||
/// Gutter (constructor) and width of gutter, used to calculate | ||
/// `gutter_offset` | ||
gutters: Vec<(Gutter, usize)>, | ||
/// cached total width of gutter | ||
gutter_offset: u16, | ||
} | ||
|
||
impl fmt::Debug for View { | ||
|
@@ -91,12 +95,23 @@ impl fmt::Debug for View { | |
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; | ||
use crate::editor::GutterType; | ||
for gutter_type in &gutter_types { | ||
match gutter_type { | ||
GutterType::Diagnostics => gutters.push((gutter::diagnostics_or_breakpoints, 1)), | ||
GutterType::LineNumbers => gutters.push((gutter::line_numbers, 5)), | ||
} | ||
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, | ||
}, | ||
Comment on lines
+108
to
+112
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure why but I can't seemed to keep these as a variable |
||
width as usize, | ||
)); | ||
} | ||
Self { | ||
id: ViewId::default(), | ||
|
@@ -108,6 +123,7 @@ impl View { | |
last_modified_docs: [None, None], | ||
object_selections: Vec::new(), | ||
gutters, | ||
gutter_offset, | ||
} | ||
} | ||
|
||
|
@@ -119,14 +135,12 @@ impl View { | |
} | ||
|
||
pub fn inner_area(&self) -> Rect { | ||
// TODO: cache this | ||
let offset = self | ||
.gutters | ||
.iter() | ||
.map(|(_, width)| *width as u16) | ||
.sum::<u16>() | ||
+ 1; // +1 for some space between gutters and line | ||
self.area.clip_left(offset).clip_bottom(1) // -1 for statusline | ||
// TODO add abilty to not use cached offset for runtime configurable gutter | ||
self.area.clip_left(self.gutter_offset).clip_bottom(1) // -1 for statusline | ||
} | ||
|
||
pub fn gutters(&self) -> &[(Gutter, usize)] { | ||
&self.gutters | ||
} | ||
|
||
// | ||
|
@@ -327,7 +341,11 @@ mod tests { | |
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::Padding, | ||
], | ||
); | ||
view.area = Rect::new(40, 40, 40, 40); | ||
let rope = Rope::from_str("abc\n\tdef"); | ||
|
@@ -374,7 +392,10 @@ mod tests { | |
|
||
#[test] | ||
fn test_text_pos_at_screen_coords_without_line_numbers_gutter() { | ||
let mut view = View::new(DocumentId::default(), vec![GutterType::Diagnostics]); | ||
let mut view = View::new( | ||
DocumentId::default(), | ||
vec![GutterType::Diagnostics, GutterType::Padding], | ||
); | ||
view.area = Rect::new(40, 40, 40, 40); | ||
let rope = Rope::from_str("abc\n\tdef"); | ||
let text = rope.slice(..); | ||
|
@@ -400,7 +421,11 @@ mod tests { | |
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::Padding, | ||
], | ||
); | ||
view.area = Rect::new(40, 40, 40, 40); | ||
let rope = Rope::from_str("Hi! こんにちは皆さん"); | ||
|
@@ -440,7 +465,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::Padding, | ||
], | ||
); | ||
view.area = Rect::new(40, 40, 40, 40); | ||
let rope = Rope::from_str("Hèl̀l̀ò world!"); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:set gutters diagnostics
or:set gutters ["diagnostics"]
doesn't seemed to work for me, the completion for it is also weird.