diff options
author | Thomas Otto <th1000s@posteo.net> | 2021-10-26 22:28:50 +0200 |
---|---|---|
committer | Dan Davison <dandavison7@gmail.com> | 2021-10-26 18:05:30 -0400 |
commit | 59e8908f8274fd925a283e3454a7dda9e928ebb9 (patch) | |
tree | e3072243012d0bd5c21dd055847466b88dac57d9 /src/features/line_numbers.rs | |
parent | fbb654d4370139b2d0fdef9c1b908fae9c54d797 (diff) |
Fix side-by-side mode without line numbers0.9.0
Even though this feature enables line numbers, these can be disabled via
the git config `delta.line-numbers=false`. So always enable line numbers,
even if they do not print numbers.
Construct more structs with ..Self::default()
Diffstat (limited to 'src/features/line_numbers.rs')
-rw-r--r-- | src/features/line_numbers.rs | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/src/features/line_numbers.rs b/src/features/line_numbers.rs index 3afce6b1..0cc4ebfb 100644 --- a/src/features/line_numbers.rs +++ b/src/features/line_numbers.rs @@ -6,7 +6,7 @@ use regex::Regex; use crate::config; use crate::delta::State; use crate::features::hyperlinks; -use crate::features::side_by_side::ansifill; +use crate::features::side_by_side::ansifill::{self, ODD_PAD_CHAR}; use crate::features::side_by_side::{Left, PanelSide, Right}; use crate::features::OptionValueFunction; use crate::format::{self, Align, Placeholder}; @@ -175,9 +175,7 @@ impl<'a> LineNumbersData<'a> { insert_center_space_on_odd_width, ), ), - line_number: MinusPlus::new(0, 0), - hunk_max_line_number_width: 0, - plus_file: "".to_string(), + ..Self::default() } } @@ -193,6 +191,24 @@ impl<'a> LineNumbersData<'a> { self.plus_file = plus_file; } + pub fn empty_for_sbs(use_full_width: ansifill::UseFullPanelWidth) -> LineNumbersData<'a> { + let insert_center_space_on_odd_width = use_full_width.pad_width(); + Self { + format_data: if insert_center_space_on_odd_width { + let format_left = vec![format::FormatStringPlaceholderData::default()]; + let format_right = vec![format::FormatStringPlaceholderData { + prefix: format!("{}", ODD_PAD_CHAR).into(), + prefix_len: 1, + ..Default::default() + }]; + MinusPlus::new(format_left, format_right) + } else { + MinusPlus::default() + }, + ..Self::default() + } + } + pub fn formatted_width(&self) -> SideBySideLineWidth { let format_data_width = |format_data: &format::FormatStringData<'a>| { // Provide each Placeholder with the max_line_number_width to calculate the |