-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Add a conf option to show no line number #769
Conversation
c7c4be0
to
e082528
Compare
Thanks a lot. Nice PR since no one touch this up till now.
Quite a few places are hard-coded with the extra spaces. Most likely you need to change |
e082528
to
59280e2
Compare
@pickfire it's probably not optimal, but it seems that it works. Here is a small video of how it works: https://asciinema.org/a/ujENYIa5G8JUrh6mYZRgilaeK |
I like this feature 👍 |
While this implementation works, I'd rather wait until the gutter code is cleanly abstracted. That way disabling the line numbers simply removes the function from the list of gutters. We also don't want to pass cloned config objects into every view, the I'll see if I can get the gutter changes done today. |
Working on a prototype here: #783 disabling line numbers would simply remove the function from the set of |
59280e2
to
daef2b2
Compare
} | ||
|
||
impl View { | ||
pub fn new(doc: DocumentId) -> Self { | ||
pub fn new(doc: DocumentId, config: crate::editor::Config) -> Self { |
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.
I think the config should be shared, best without using RefCell<Mutex<Config>>
for #798
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.
Tested and works nicely but I think how the config passed in can be done better.
let last_line = self.offset.row + self.area.height as usize - 1; // -1 for statusline | ||
let offset = match self.config.line_number { | ||
LineNumber::Absolute | LineNumber::Relative => { | ||
last_line.to_string().chars().count() + OFFSET |
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.
I just opened a log file with a few million lines and was searching for an issue about cut-off line numbers, nice to see that it’s fixed here!
I think computing the offset is more efficient with
/// Computes the number of decimal digits needed to print a number.
fn digits10(i: usize) -> usize {
((i + 1) as f64).log10().ceil() as usize
}
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.
Huum I'm not sure that using float and log10 would be any fast 🤔
What do you think of this function?
/// Computes the number of decimal digits needed to print a number.
fn digits10(n: usize) -> usize {
std::iter::successors(Some(n), |n| {
let n = n / 10;
(n != 0).then(|| n)
}).count()
}
I'll run a little benchmark just to get an idea but thanks for the suggestion.
I don't think this PR will be merged any time soon however because I don't really have any time to invest in helix currently so you can take it if you want and have the time 👍
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.
Here is my result with a bunch of numbers:
log10/0 time: [6.8428 ns 6.8473 ns 6.8525 ns]
divide/0 time: [1.2312 ns 1.2334 ns 1.2362 ns]
log10/100 time: [8.8163 ns 8.8380 ns 8.8643 ns]
divide/100 time: [1.6460 ns 1.6472 ns 1.6485 ns]
log10/1000 time: [9.0255 ns 9.0385 ns 9.0530 ns]
divide/1000 time: [1.9341 ns 1.9369 ns 1.9403 ns]
log10/4000 time: [9.3187 ns 9.3493 ns 9.3821 ns]
divide/4000 time: [1.8846 ns 1.8853 ns 1.8860 ns]
log10/10000 time: [8.7732 ns 8.7818 ns 8.7922 ns]
divide/10000 time: [2.0882 ns 2.0900 ns 2.0922 ns]
log10/50000 time: [9.1107 ns 9.1342 ns 9.1616 ns]
divide/50000 time: [2.1692 ns 2.1741 ns 2.1798 ns]
log10/100000 time: [9.0641 ns 9.0708 ns 9.0776 ns]
divide/100000 time: [2.4120 ns 2.4160 ns 2.4204 ns]
log10/500000 time: [9.3445 ns 9.3639 ns 9.3847 ns]
divide/500000 time: [2.3472 ns 2.3540 ns 2.3627 ns]
log10/18446744073709551615 time: [7.7829 ns 7.7914 ns 7.8008 ns]
divide/18446744073709551615 time: [10.872 ns 10.879 ns 10.887 ns]
log10
is your function and divide
is my function. The number after the /
is which number was given to our function.
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.
Nice, that’s a lot faster!
I rebased this PR and stitched something together that asks the gutter how much space it needs in https://github.com/Flakebi/helix/tree/no_line_number |
What about passing in a subset? Don't pass the whole config or document. |
I wonder if this should be closed since gutter functions are merged. |
Yes you're right there is no way for any of this code to be merged |
This PR adds the possibility to not print any line number:
On the left is a file opened with this patch vs the default settings on the right:
This is not ideal because if we don't print any line number we could save 5 unused spaces on the left but I don't know how to do it for now 😒
A little help would be appreciated if you have the time 👍