diff --git a/GitUI/Editor/FileViewer.Designer.cs b/GitUI/Editor/FileViewer.Designer.cs index b1c7aabf8a1..cadf009b8bf 100644 --- a/GitUI/Editor/FileViewer.Designer.cs +++ b/GitUI/Editor/FileViewer.Designer.cs @@ -394,7 +394,6 @@ private void InitializeComponent() this.internalFileViewer.Name = "internalFileViewer"; this.internalFileViewer.VScrollPosition = 0; this.internalFileViewer.ShowEOLMarkers = false; - this.internalFileViewer.ShowLineNumbers = true; this.internalFileViewer.ShowSpaces = false; this.internalFileViewer.ShowTabs = false; this.internalFileViewer.Size = new System.Drawing.Size(757, 518); diff --git a/GitUI/Editor/FileViewer.cs b/GitUI/Editor/FileViewer.cs index 9a36c8a6233..db8bd8c7ca6 100644 --- a/GitUI/Editor/FileViewer.cs +++ b/GitUI/Editor/FileViewer.cs @@ -191,10 +191,10 @@ public bool IsReadOnly set => internalFileViewer.IsReadOnly = value; } - [DefaultValue(true)] + [DefaultValue(null)] [Description("If true line numbers are shown in the textarea")] [Category("Appearance")] - public bool ShowLineNumbers + public bool? ShowLineNumbers { get => internalFileViewer.ShowLineNumbers; set => internalFileViewer.ShowLineNumbers = value; diff --git a/GitUI/Editor/FileViewerInternal.cs b/GitUI/Editor/FileViewerInternal.cs index cdd31d15ec2..aa9628d164a 100644 --- a/GitUI/Editor/FileViewerInternal.cs +++ b/GitUI/Editor/FileViewerInternal.cs @@ -3,6 +3,7 @@ using System.Threading.Tasks; using System.Windows.Forms; using GitCommands; +using GitExtUtils.GitUI; using GitUI.Editor.Diff; using ICSharpCode.TextEditor; using ICSharpCode.TextEditor.Document; @@ -104,11 +105,7 @@ public string GetText() return TextEditor.Text; } - public bool ShowLineNumbers - { - get => TextEditor.ShowLineNumbers; - set => TextEditor.ShowLineNumbers = value; - } + public bool? ShowLineNumbers { get; set; } public void SetText(string text, Action openWithDifftool, bool isDiff = false) { @@ -137,12 +134,30 @@ public void SetText(string text, Action openWithDifftool, bool isDiff = false) // important to set after the text was changed // otherwise the may be rendering artifacts as noted in #5568 - TextEditor.ShowLineNumbers = !isDiff; + TextEditor.ShowLineNumbers = ShowLineNumbers ?? !isDiff; + if (ShowLineNumbers.HasValue && !ShowLineNumbers.Value) + { + Padding = new Padding(DpiUtil.Scale(5), Padding.Top, Padding.Right, Padding.Bottom); + } + TextEditor.Refresh(); _currentViewPositionCache.Restore(isDiff); } + private static readonly SolidBrush PaddingBrush = new SolidBrush(Color.White); + protected override void OnPaintBackground(PaintEventArgs e) + { + if (ShowLineNumbers.HasValue && !ShowLineNumbers.Value) + { + e.Graphics.FillRectangle(PaddingBrush, e.ClipRectangle); + } + else + { + base.OnPaintBackground(e); + } + } + public void SetHighlighting(string syntax) { TextEditor.SetHighlighting(syntax); diff --git a/GitUI/Editor/IFileViewer.cs b/GitUI/Editor/IFileViewer.cs index dc80039b78f..13ef8452451 100644 --- a/GitUI/Editor/IFileViewer.cs +++ b/GitUI/Editor/IFileViewer.cs @@ -47,7 +47,7 @@ public interface IFileViewer Action OpenWithDifftool { get; } int VScrollPosition { get; set; } - bool ShowLineNumbers { get; set; } + bool? ShowLineNumbers { get; set; } bool ShowEOLMarkers { get; set; } bool ShowSpaces { get; set; } bool ShowTabs { get; set; }